Book/lua-Phpdoc专题
Lua
目录
- 简介
- 安装/配置
- Lua — Lua类
- Lua::assign — 将一个php变量赋值给Lua
- Lua::call — 调用Lua函数
- Lua::__construct — Lua 构造方法
- Lua::eval — 将字符串当做Lua代码执行
- Lua::getVersion — 获取Lua版本
- Lua::include — 解析Lua脚本文件
- Lua::registerCallback — 向Lua中注册php函数
- LuaClosure — LuaClosure类
- LuaClosure::__invoke — 调用luaclosure
简介
类摘要
Lua
class Lua {
/* 常量 */
const string
Lua::LUA_VERSION = Lua 5.1.4 ;
/* 方法 */
public mixed
assign ( <span
class="type">string $name , <span
class="methodparam">string $value )
public mixed
call ( <span
class="type">callable $lua_func [, <span
class="methodparam">array $args [,
int $use_self<span
class="initializer"> = 0 ]] )
public mixed
__call ( <span
class="methodparam">callable
$lua_func [, <span
class="type">array $args [, <span
class="methodparam">int $use_self<span
class="initializer"> = 0 ]] )
public <span
class="methodname">__construct ( <span
class="methodparam">string
$lua_script_file = NULL )
public mixed
eval ( <span
class="type">string $statements )
public string getVersion ( <span class="methodparam">void )
public mixed
include ( <span
class="methodparam">string $file )
public mixed
registerCallback ( <span
class="methodparam">string $name ,
callable
$function )
}
预定义常量
Lua::LUA_VERSION
Lua::assign
将一个php变量赋值给Lua
说明
public mixed
Lua::assign ( <span
class="methodparam">string $name ,
string
$value )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
赋值成功返回$this否则返回null
范例
示例 #1 Lua::assign示例
<?php
$lua = new Lua();
$lua->assign("php_var", array(1=>1, 2, 3)); //lua table index begin with 1
$lua->eval(<<<CODE
print(php_var);
CODE
);
?>
以上例程会输出:
Array
(
[1] => 1
[2] => 2
[3] => 3
)
Lua::call
Lua::__call
调用Lua函数
说明
public mixed
Lua::call ( <span
class="methodparam">callable
$lua_func [, <span
class="type">array $args [, <span
class="methodparam">int $use_self<span
class="initializer"> = 0 ]] )
public mixed
Lua::__call ( <span
class="methodparam">callable
$lua_func [, <span
class="type">array $args [, <span
class="methodparam">int $use_self<span
class="initializer"> = 0 ]] )
Warning
本函数还未编写文档,仅有参数列表。
参数
lua_func
lua中的函数名。
args
向Lua函数传入的参数。
use_self
是否使用self。
返回值
返回调用函数的结果,参数错误返回null ,其它错误返回false。
范例
示例 #1 Lua::call示例
<?php
$lua = new Lua();
$lua->eval(<<<CODE
function dummy(foo, bar)
print(foo, ",", bar)
end
CODE
);
$lua->call("dummy", array("Lua", "geiliable\n"));
$lua->dummy("Lua", "geiliable"); // __call()
var_dump($lua->call(array("table", "concat"), array(array(1=>1, 2=>2, 3=>3), "-")));
?>
以上例程会输出:
Lua,geiliable
Lua,geiliable
string(5) "1-2-3"
参见
Lua::__construct
Lua 构造方法
说明
public <span
class="methodname">Lua::__construct ( <span
class="methodparam">string
$lua_script_file = NULL )
Warning
本函数还未编写文档,仅有参数列表。
参数
lua_script_file
返回值
Lua::eval
将字符串当做Lua代码执行
说明
public mixed
Lua::eval ( <span
class="methodparam">string
$statements )
Warning
本函数还未编写文档,仅有参数列表。
参数
statements
返回值
返回运行结果,参数错误返回null ,其它错误返回false。
范例
示例 #1 Lua::eval示例
<?php
$lua = new Lua();
$lua->eval(<<<CODE
print(2);
CODE
);
?>
以上例程会输出:
2
Lua::getVersion
获取Lua版本
说明
public string Lua::getVersion ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回 Lua::LUA_VERSION。
Lua::include
解析Lua脚本文件
说明
public mixed
Lua::include ( <span
class="methodparam">string $file )
Warning
本函数还未编写文档,仅有参数列表。
参数
file
返回值
返回脚本文件运行结果,参数错误返回null ,其它错误返回false。
Lua::registerCallback
向Lua中注册php函数
说明
public mixed
Lua::registerCallback ( <span
class="methodparam">string $name ,
callable
$function )
向Lua注册php函数,函数名为"$name"
参数
name
function
一个有效的PHP回调函数
返回值
成功返回$this,参数错误返回null ,其它错误返回false。
范例
示例 #1 Lua::registerCallback示例
<?php
$lua = new Lua();
$lua->registerCallback("echo", "var_dump");
$lua->eval(<<<CODE
echo({1, 2, 3});
CODE
);
?>
以上例程会输出:
array(3) {
[1]=>
float(1)
[2]=>
float(2)
[3]=>
float(3)
}
简介
LuaClosure是对LUA_TFUNCTION的封装类,可以作为调用Lua函数的返回值。
类摘要
LuaClosure
class LuaClosure {
/* 方法 */
public void
__invoke ( <span
class="methodparam">mixed $arg [,
mixed $...
] )
}
LuaClosure::__invoke
调用luaclosure
说明
public void
LuaClosure::__invoke ( <span
class="methodparam">mixed $arg [,
mixed $...
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
arg
...
返回值
范例
示例 #1 LuaClosure::__invoke示例
<?php
$lua = new Lua();
$closure = $lua->eval(<<<CODE
return (function ()
print("hello world")
end)
CODE
);
$lua->call($closure);
/* after PHP 5.3 */
$closure();
?>
以上例程会输出:
hello worldhello world