3

PLua - Lua for PHP

 3 years ago
source link: https://www.laruence.com/2011/06/19/2047.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PLua - Lua for PHP

上周的时候, 搞mysql proxy, 发现要用lua写服务器脚本, 加之以前配置lighttpd的时候, 配置也可以用lua来写, 就想彻底学习和研究下lua.
本着学习Lua的态度, 写了一个PHP扩展Plua, 把Lua解析器嵌入了PHP.
Lua的堆栈式传参, 很值得借鉴, 这点上, 感觉比PHP用一个结构体表示弱类型, 要来的更严格, 更可靠一些.
目前可以想到的应用场景, 是可以实现一种编写(Lua), 多处调用(C, PHP, Java等).
不废话了, 项目主页: Plua
代码在Google code上:http://code.google.com/p/plua/

  1. <?php
  2.    $lua = new Plua($lua_script_file = NULL);
  3.    $lua->eval("lua_statements"); //eval lua codes
  4.    $lua->include("lua_script_file"); //import a lua script
  5.    $lua->assign("name", $value); //assign a php variable to Lua
  6.    $lua->register("name", $function); //register a PHP function to Lua with "name"
  7.    $lua->call($string_lua_function_name, array() /*args*/);
  8.    $lua->call($resouce_lua_anonymous_function, array() /*args);
  9. $lua->call(array("table", "method"), array(...., "push_self" => [true | false]) /*args*/);
  10.    $lua->{$lua_function}(array()/*args*/);
  11. ?>

后记: Plua项目现在已经取代了原来的Lua成为了PECL的Lua扩展, Plua也改名为了Lua, 所以请使用最新的Lua


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK