Press "Enter" to skip to content

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/

<?php
   $lua = new Plua($lua_script_file = NULL);

   $lua->eval("lua_statements");     //eval lua codes
   $lua->include("lua_script_file"); //import a lua script

   $lua->assign("name", $value); //assign a php variable to Lua
   $lua->register("name", $function); //register a PHP function to Lua with "name"

   $lua->call($string_lua_function_name, array() /*args*/);
   $lua->call($resouce_lua_anonymous_function, array() /*args);
   $lua->call(array("table", "method"), array(...., "push_self" => [true | false]) /*args*/);

   $lua->{$lua_function}(array()/*args*/);
?>
   

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

7 Comments

  1. I enjoy reading an article that will make men and women think.

    Also, many thanks for permitting me to comment!

  2. lucifer
    lucifer 2015-03-06

    现在的游戏开发从大家口中了解到的情况是,游戏的后端都是用 java 或者 python , 没有用php 这个…….Laruence你怎么看…….

  3. samsung s2 t-mobile
    samsung s2 t-mobile 2014-11-20

    Great beat ! I would like to apprentice while you amend your website,
    how could i subscribe for a blog site? The account
    helped me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept

  4. shiny
    shiny 2011-06-19

    很有意思。这样学lua有动力了。。。

  5. xLight
    xLight 2011-06-19

    这个比较有意思,调用方式也是很有嵌入的感觉,
    plua有自己独立的vm?

Leave a Reply

Your email address will not be published. Required fields are marked *