(No version information available, might only be in Git)
Lua::registerCallback — Registra una función PHP en Lua
Registra una función PHP en Lua con el nombre de función que se indique en "$name"
namefunctionUna función de llamada de retorno válida PHP
Devuelve $this, null en caso que los argumentos sean erróneos o false para
cualquier otro tipo de error.
Ejemplo #1 Ejemplo de Lua::registerCallback()
<?php
$lua = new Lua();
$lua->registerCallback("echo", "var_dump");
$lua->eval(<<<CODE
echo({1, 2, 3});
CODE
);
?>El ejemplo anterior mostrará:
array(3) {
[1]=>
float(1)
[2]=>
float(2)
[3]=>
float(3)
}
// 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)
");