Lua::registerCallback

(No version information available, might only be in Git)

Lua::registerCallbackRegistra uma função PHP no interpretador Lua

Descrição

public Lua::registerCallback(string $name, callable $function): mixed

Registra uma função PHP no interpretador Lua como uma função chamada "$name"

Parâmetros

name

function

Uma função PHP válida

Valor Retornado

Retorna $this, null para argumentos incorretos ou false para outros tipos de falha.

Exemplos

Exemplo #1 Exemplo da função Lua::registerCallback()

<?php
$lua
= new Lua();
$lua->registerCallback("echo", "var_dump");
$lua->eval(<<<CODE
echo({1, 2, 3});
CODE
);
?>

O exemplo acima produzirá:

array(3) {
  [1]=>
  float(1)
  [2]=>
  float(2)
  [3]=>
  float(3)
}
adicione uma nota

Notas Enviadas por Usuários (em inglês) 1 note

up
0
turn_and_turn at sina dot com
5 years ago
// init lua$lua = new Lua();/*** Hello world method*/function helloWorld(){    return "hello world";}// register our hello world method$lua->registerCallback("helloWorld", helloWorld);$lua->eval("    -- call php method    local retVal = helloWorld()    print(retVal)");// register our hello world method but using an other name$lua->registerCallback("worldHello", helloWorld);// run our lua script$lua->eval("    -- call php method    local retVal = worldHello()    print(retVal)");
To Top