92 Commits

Author SHA1 Message Date
Jean-Baptiste Nahan e16624fd1c check php version 2025-10-06 17:54:19 +02:00
Jean-Baptiste Nahan 44a0c089ca Fix PHP 8.5 build 2025-10-06 17:50:34 +02:00
Xinchen Hui a6c5162a7c Back to dev 2020-03-10 11:09:56 +08:00
Xinchen Hui 0875f92328 Preparing 2.0.7 2020-03-10 11:09:26 +08:00
Xinchen Hui 445e886030 Fixed ulong undefined 2020-03-01 15:33:39 +08:00
Xinchen Hui 5c405f9746 Merge pull request #42 from negram/demangle-object-name
Demangle name of a property when assigning an object into Lua
2019-12-30 13:26:32 +08:00
Xinchen Hui 9b25ea36a5 Merge pull request #44 from tony2001/multiple_fixes
Multiple fixes
2019-12-30 13:25:46 +08:00
Xinchen Hui 5b6ac82491 added more test php version 2019-12-24 12:54:21 +08:00
Mikhail Galanin 5663931ce7 Renamed test to prevent merge conflict 2019-11-02 13:07:12 +00:00
Antony Dovgal a5a8995b2e add some more table magic
this commit seems to fix all remaining issue with iterating tables
2019-07-04 18:48:58 +03:00
Antony Dovgal ffae3062a4 add more tests 2019-05-24 12:42:01 +03:00
Antony Dovgal 13e26a383a make lua_obj optional
so that printing a function would not cause crash
2019-05-24 12:41:55 +03:00
Antony Dovgal ef70d19a33 fix crashes when printing tables 2019-05-24 12:41:42 +03:00
Antony Dovgal d763f167d8 fix incorrect type alloc that causes memory corruption 2019-05-24 12:41:29 +03:00
Mikhail Galanin 24fd1baf19 Fixed issue #40
Using absolute index could be error-prone, updated code to use relative indices as it commonly done with Lua
2019-05-24 12:41:07 +03:00
Mikhail Galanin a780d5623d Make test finally stable 2019-05-21 08:46:23 +01:00
Mikhail Galanin 0d73a2fdaa fixed test 2019-05-19 20:23:55 +01:00
Mikhail Galanin aa1dd4f526 Fixed test 2019-05-19 20:02:32 +01:00
Mikhail Galanin 199a846d7a Demangle name of a property when assigning an object into Lua 2019-05-19 19:55:43 +01:00
Xinchen Hui 84c831e4cb releasing 2.0.6 2018-12-21 11:11:37 +08:00
Xinchen Hui f588c88528 Fixed hash recursive detecting 2018-12-21 11:09:57 +08:00
Xinchen Hui ad31d5f7c6 back to dev 2017-12-31 12:34:09 +08:00
Xinchen Hui 15f58c43fb releasing 2.0.5 2017-12-31 12:33:16 +08:00
Xinchen Hui c4c61f05bf Revert the last merge 2017-10-18 13:05:38 +08:00
Xinchen Hui 9ef044896a Merge pull request #31 from sgolemon/callback.refcount
Explicitly release held references to PHP callbacks
2017-10-18 12:56:28 +08:00
Xinchen Hui feb39efa86 Merge pull request #32 from sgolemon/gitignore
Add a .gitignore to disregard build artifacts
2017-10-18 12:56:02 +08:00
Xinchen Hui 4438a88e85 Merge pull request #33 from sgolemon/object.alloc
Fix allocation of lua object.
2017-10-18 12:55:49 +08:00
Xinchen Hui 0c6a60d21b Merge pull request #34 from sgolemon/php_printf
Prefer php_printf() over printf()
2017-10-18 12:55:26 +08:00
Xinchen Hui db95520d2f Merge pull request #35 from sgolemon/non-string.accessor
Fix non-string member access in read/write prop.
2017-10-18 12:55:10 +08:00
Xinchen Hui 8afc555bce Merge pull request #36 from sgolemon/closure.refactor
Refactor LuaClosure
2017-10-18 12:53:50 +08:00
Sara Golemon 486de80ebf Refactor LuaClosure
Use proper internal object storage rather than private props.
Favor NULL clone_obj handler over empty private __clone method.
Favor free_obj handler over __destruct() method.
2017-10-03 10:09:53 -04:00
Sara Golemon 1813b36307 Fix non-string member access in read/write prop.
These both have a null pointer deref waiting to happen
and are coincidentally more complex than they need to be.

zval_get_string() will incref any IS_STRING zval,
or copy/convert any non-string zval.

zend_string_release() will then decref or free as appropriate.
2017-10-03 08:51:02 -04:00
Sara Golemon a2be2c935b Prefer php_printf() over printf()
On CLI the distinction doesn't matter, but in a web sapi this
will ensure the output goes to the right place.
2017-10-03 08:37:13 -04:00
Sara Golemon 6690ee0c70 Fix allocation of lua object.
Size the malloc using zend's helper.
Use ecalloc over emalloc to make sure uninit'd structs are clear.
No need to check return value as e*alloc() funcs can't fail.
2017-10-03 08:32:51 -04:00
Sara Golemon f64a8d6d27 Add a .gitignore to disregard build artifacts 2017-10-02 19:01:00 -04:00
Sara Golemon d6c7850afa Explicitly release held references to PHP callbacks 2017-10-02 18:52:01 -04:00
Xinchen Hui 257d46c1e4 back to dev 2017-07-12 11:42:28 +08:00
Xinchen Hui e350b425f4 release 2.0.4 2017-07-12 11:42:06 +08:00
Xinchen Hui 527f927ead Fixed bug #73964 (Segmentation fault (11)) 2017-02-12 10:53:36 +08:00
Xinchen Hui 9be57325c6 back to dev 2017-02-10 19:14:10 +08:00
Xinchen Hui 1ff1eb10c9 releaseing 2.0.3 2017-02-10 19:13:44 +08:00
Xinchen Hui cbe65b9ad6 Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua) 2016-05-30 11:44:12 +08:00
Xinchen Hui 04f7106631 back to dev 2016-05-26 17:42:59 +08:00
Xinchen Hui 7406b07f2c Prepare for 2.0.2 2016-05-26 17:42:22 +08:00
Xinchen Hui 17cbba8b77 Fixed issue #22 (Boolean FALSE is always TRUE) 2016-05-20 11:54:37 +08:00
Xinchen Hui 7cdb287c33 back to dev 2016-04-11 10:55:22 +08:00
Xinchen Hui f3d6dca1a0 Prepareing for 2.0.1 2016-04-11 10:54:41 +08:00
Xinchen Hui f177b21ff1 Added tests for bug #71997 2016-04-11 10:51:15 +08:00
Xinchen Hui c7d9844cf1 Fixed default searching in centOS 2016-04-11 10:50:28 +08:00
Xinchen Hui 12c53f28eb Fixed nApplyCount checking 2016-04-11 10:37:11 +08:00
Xinchen Hui 86cb62e0b8 Merge pull request #19 from tony2001/php7_fixes
fix send_zval_to_lua()
2016-04-07 19:14:59 +08:00
Antony Dovgal dc226c345d fix send_zval_to_lua() 2016-03-31 12:56:15 +03:00
Xinchen Hui 2d23b565e5 Merge branch 'master' into php7
Conflicts:
	README.md
2015-10-26 21:11:38 -07:00
Xinchen Hui 6a2bf0e8af Update README 2015-10-26 21:11:12 -07:00
Xinchen Hui 230a8af900 Update README 2015-10-26 21:10:51 -07:00
Xinchen Hui 468203ce7c Merge branch 'master' into php7 2015-10-26 21:05:54 -07:00
Xinchen Hui aaf49be301 trigger triavis 2015-10-26 21:05:41 -07:00
Xinchen Hui 1bd4adf039 No valgrind is valiable 2015-10-26 20:59:34 -07:00
Xinchen Hui 18e2bb493d enable full test 2015-10-26 20:56:56 -07:00
Xinchen Hui 0b28ef4f55 Merge branch 'master' into php7
Conflicts:
	.travis.yml
	travis/compile.sh
2015-10-26 20:56:19 -07:00
Xinchen Hui d3323aa9fe enable travis 2015-10-26 20:54:55 -07:00
Xinchen Hui f6a2f09b19 User hjanuschka doesn't exists? 2015-10-27 11:16:04 +08:00
Xinchen Hui 6c2a37f99c back to dev 2015-10-27 11:14:10 +08:00
Xinchen Hui 65764e0777 release lua for PHP7 2015-10-27 11:13:39 +08:00
Xinchen Hui cf3f69b274 Cleanup 2015-02-26 12:10:34 +08:00
Xinchen Hui 49b95a64f3 All tests passed 2015-02-26 12:05:45 +08:00
Xinchen Hui ca8cf30759 Only for PHP7 2015-02-26 00:16:38 +08:00
Xinchen Hui 8bccbdc5db clean up (not finish yet) 2015-02-26 00:11:42 +08:00
Xinchen Hui 50d32564d2 Master is only for PHP5.X now 2015-02-25 22:23:05 +08:00
Xinchen Hui a55478e449 Merge pull request #17 from tony2001/suffix_fix
several config fixes
2015-02-25 20:52:52 +08:00
Antony Dovgal adb5146954 fix include dir 2015-02-25 15:46:46 +03:00
Antony Dovgal b95ae16c6f also fix "no" suffix 2015-02-25 15:44:29 +03:00
Antony Dovgal c3b50a5645 fix libluaYES suffix 2015-02-25 15:26:31 +03:00
Xinchen Hui bcc3bb67f8 Merge pull request #16 from hjanuschka/hj
Memleaks
2015-02-04 21:56:56 +08:00
Helmut Januschka 5e5fefcdbf * this fixes memleak in php_lua_call_callback
* no more outstanding memory leaks
2015-02-04 12:56:41 +00:00
Xinchen Hui dea4f594e4 Merge pull request #14 from hjanuschka/hj
add me to authors 👍
2015-02-02 23:21:06 +08:00
Helmut Januschka 6205c5c4ff add me to authors 👍 2015-02-02 15:06:46 +00:00
Xinchen Hui a2e9c435c4 Merge pull request #13 from hjanuschka/hj
fix for latest php7 head
2015-02-02 22:09:42 +08:00
Helmut Januschka 061f22aac0 fix for latest php7 head 2015-02-02 13:27:33 +00:00
Xinchen Hui 0c265c5e7d Merge pull request #7 from remicollet/issue-php533
Fix build against PHP 5.3.3
2013-11-29 10:15:57 -08:00
Remi Collet d893cd58c2 zval_copy_property_ctor have been added in 5.3.4 (so not in 5.3.3) 2013-11-06 14:11:45 +01:00
Xinchen Hui 96d77a1c7a Merge pull request #6 from remicollet/issue-110
Various fix for 1.1.0
2013-10-24 00:36:17 -07:00
Remi Collet 99e95d1bf5 fix [-Wpointer-sign] 2013-10-24 08:27:36 +02:00
Remi Collet 10b0cf59cd skip test if json not enabled (or build as shared and so not loaded during make test) 2013-10-24 08:22:57 +02:00
Remi Collet 561f632f62 fix test for 5.1, error string have changed 2013-10-24 08:22:01 +02:00
Remi Collet 22d5b508e7 LUA_ERRGCMM is 5.2 only 2013-10-24 08:19:02 +02:00
Remi Collet 4c8fff9af5 LUA_OK is 5.2 2013-10-24 08:17:43 +02:00
Remi Collet bef3b82b47 quick fix to allow build against shared system library 2013-10-24 08:16:46 +02:00
Remi Collet 5489007dc8 missing test 2013-10-24 08:12:32 +02:00
Remi Collet c4f51f3b43 fix role for doc 2013-10-24 08:12:05 +02:00
Remi Collet b56130d45b drop package2.xml, no more supported 2013-10-24 08:11:15 +02:00
Xinchen Hui 098a5ef470 back to dev(1.1.1-dev) 2013-10-23 12:21:30 +08:00
25 changed files with 1052 additions and 737 deletions
+38
View File
@@ -0,0 +1,38 @@
*.o
*.lo
*.la
.*.swp
.deps
.libs/
include/
tests/*.diff
tests/*.exp
tests/*.log
tests/*.php
tests/*.out
tests/*.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
acinclude.m4
aclocal.m4
autom4te.cache/
build/
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.ac
configure.in
install-sh
libtool
ltmain.sh
missing
mkinstalldirs
modules/
run-tests.php
+27
View File
@@ -0,0 +1,27 @@
language: php
addons:
apt:
packages:
- liblua5.2-dev
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
notifications:
email: false
irc: "irc.efnet.org#php.yaf"
env:
- REPORT_EXIT_STATUS=1 NO_INTERACTION=1
#Compile
before_script:
- ./travis/compile.sh
# Run PHPs run-tests.php
script: TEST_PHP_ARGS="--show-diff" make test
+1
View File
@@ -2,3 +2,4 @@ lua
Johannes Schlueter Johannes Schlueter
Marcelo Araujo Marcelo Araujo
Xinchen Hui Xinchen Hui
Helmut Januschka
+5 -1
View File
@@ -1,2 +1,6 @@
"Lua is a powerful, fast, light-weight, embeddable scripting language." # PHP Lua
[![Build Status](https://secure.travis-ci.org/laruence/php-lua.png)](https://travis-ci.org/laruence/php-lua)
This extension embeds the lua interpreter and offers an OO-API to lua variables and functions. This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.
"Lua is a powerful, fast, light-weight, embeddable scripting language."
Regular → Executable
+32 -10
View File
@@ -1,34 +1,56 @@
dnl $Id: config.m4 321796 2012-01-05 17:23:48Z laruence $
PHP_ARG_WITH(lua, for lua support, PHP_ARG_WITH(lua, for lua support,
[ --with-lua=[DIR] Include php lua support]) [ --with-lua=[DIR] Include php lua support])
PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.)
PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.)
if test "$PHP_LUA" != "no"; then if test "$PHP_LUA" != "no"; then
if test -r $PHP_LUA/include/lua.h; then if test -r $PHP_LUA/include/lua.h; then
LUA_DIR=$PHP_LUA LUA_INCLUDE_DIR=$PHP_LUA/include
else else
AC_MSG_CHECKING(for lua in default path) AC_MSG_CHECKING(for lua in default path)
for i in /usr/local /usr; do for i in /usr/local /usr; do
if test -r $i/include/lua/lua.h; then if test -r $i/include/lua/lua.h; then
LUA_DIR=$i LUA_INCLUDE_DIR=$i/include/lua
AC_MSG_RESULT(found in $i) AC_MSG_RESULT(found in $i)
break break
fi fi
if test -r $i/include/lua.h; then
LUA_INCLUDE_DIR=$i/include
AC_MSG_RESULT(found in $i)
break
fi
if test "$PHP_LUA_VERSION" != "yes"; then
if test -r $i/include/lua$PHP_LUA_VERSION/lua.h; then
LUA_INCLUDE_DIR=$i/include/lua$PHP_LUA_VERSION
AC_MSG_RESULT(found in a version-specific subdirectory of $i)
break
fi
fi
done done
fi fi
if test -z "$LUA_DIR"; then if test -z "$LUA_INCLUDE_DIR"; then
AC_MSG_RESULT(not found) AC_MSG_RESULT(not found)
AC_MSG_ERROR(Please reinstall the lua distribution - lua.h should be in <lua-dir>/include/) AC_MSG_ERROR(Please reinstall the lua distribution - lua.h should be in <lua-dir>/include/)
fi fi
LUA_LIB_NAME=liblua.a if test "$PHP_LUA_VERSION" != "yes" -a "$PHP_LUA_VERSION" != "no"; then
LUA_LIB_SUFFIX=lua$PHP_LUA_VERSION
else
LUA_LIB_SUFFIX=lua
fi
if test -r $PHP_LUA/$PHP_LIBDIR/${LUA_LIB_NAME}; then LUA_LIB_NAME=lib$LUA_LIB_SUFFIX
if test -r $PHP_LUA/$PHP_LIBDIR/${LUA_LIB_NAME}.${SHLIB_SUFFIX_NAME} -o -r $PHP_LUA/$PHP_LIBDIR/${LUA_LIB_NAME}.a; then
LUA_LIB_DIR=$PHP_LUA/$PHP_LIBDIR LUA_LIB_DIR=$PHP_LUA/$PHP_LIBDIR
else else
AC_MSG_CHECKING(for lua library in default path) AC_MSG_CHECKING(for lua library in default path)
for i in /usr/lib /usr/lib64; do for i in /usr/$PHP_LIBDIR /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu; do
if test -r $i/${LUA_LIB_NAME}; then if test -r $i/${LUA_LIB_NAME}.${SHLIB_SUFFIX_NAME} -o -r $i/${LUA_LIB_NAME}.a; then
LUA_LIB_DIR=$i LUA_LIB_DIR=$i
AC_MSG_RESULT(found in $i) AC_MSG_RESULT(found in $i)
break break
@@ -41,8 +63,8 @@ if test "$PHP_LUA" != "no"; then
AC_MSG_ERROR(Please reinstall the lua distribution - lua library should be in <lua-dir>/lib/) AC_MSG_ERROR(Please reinstall the lua distribution - lua library should be in <lua-dir>/lib/)
fi fi
PHP_ADD_INCLUDE($LUA_DIR/include) PHP_ADD_INCLUDE($LUA_INCLUDE_DIR)
PHP_ADD_LIBRARY_WITH_PATH(lua, $LUA_LIB_DIR, LUA_SHARED_LIBADD) PHP_ADD_LIBRARY_WITH_PATH($LUA_LIB_SUFFIX, $LUA_LIB_DIR, LUA_SHARED_LIBADD)
PHP_SUBST(LUA_SHARED_LIBADD) PHP_SUBST(LUA_SHARED_LIBADD)
PHP_NEW_EXTENSION(lua, lua.c lua_closure.c, $ext_shared) PHP_NEW_EXTENSION(lua, lua.c lua_closure.c, $ext_shared)
fi fi
Regular → Executable
+285 -332
View File
File diff suppressed because it is too large Load Diff
+50 -94
View File
@@ -13,8 +13,8 @@
| Author : Johannes Schlueter <johannes@php.net> | | Author : Johannes Schlueter <johannes@php.net> |
| Xinchen Hui <laruence@php.net> | | Xinchen Hui <laruence@php.net> |
| Marcelo Araujo <msaraujo@php.net> | | Marcelo Araujo <msaraujo@php.net> |
| Helmut Januschka <helmut@januschka.com> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
$Id: lua_closure.c 319740 2011-11-24 08:06:48Z laruence $
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -25,6 +25,7 @@
#include "Zend/zend_exceptions.h" #include "Zend/zend_exceptions.h"
#include "lua.h" #include "lua.h"
#include "lua_closure.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
@@ -33,6 +34,7 @@
static zend_class_entry *lua_closure_ce; static zend_class_entry *lua_closure_ce;
extern zend_class_entry *lua_ce; extern zend_class_entry *lua_ce;
extern zend_class_entry *lua_exception_ce; extern zend_class_entry *lua_exception_ce;
static zend_object_handlers lua_closure_handlers;
/** {{{ ARG_INFO /** {{{ ARG_INFO
* *
@@ -43,12 +45,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_invoke, 0, 0, 1)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
/* }}} */ /* }}} */
/** {{{ zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj TSRMLS_DC) /** {{{ zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj)
*/ */
zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj TSRMLS_DC) { zval* php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj) {
lua_closure_object *objval;
object_init_ex(instance, lua_closure_ce); object_init_ex(instance, lua_closure_ce);
zend_update_property_long(lua_closure_ce, instance, ZEND_STRL("_closure"), ref_id TSRMLS_CC); objval = php_lua_closure_object_from_zend_object(Z_OBJ_P(instance));
zend_update_property(lua_closure_ce, instance, ZEND_STRL("_lua_object"), lua_obj TSRMLS_CC); objval->closure = ref_id;
if (lua_obj) {
ZVAL_ZVAL(&(objval->lua), lua_obj, 1, 0);
}
return instance; return instance;
} }
@@ -60,74 +67,44 @@ PHP_METHOD(lua_closure, __construct) {
} }
/* }}} */ /* }}} */
/** {{{ proto LuaClosure::__destruct()
*/
PHP_METHOD(lua_closure, __destruct) {
zval *lua_obj, *closure;
lua_obj = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_lua_object"), 1 TSRMLS_CC);
if (ZVAL_IS_NULL(lua_obj)
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce TSRMLS_CC)) {
RETURN_FALSE;
}
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1 TSRMLS_CC);
if (!Z_LVAL_P(closure)) {
RETURN_FALSE;
}
luaL_unref(Z_LUAVAL_P(lua_obj), LUA_REGISTRYINDEX, Z_LVAL_P(closure));
}
/* }}} */
/** {{{ proto LuaClosure::invoke(mxied $args) /** {{{ proto LuaClosure::invoke(mxied $args)
*/ */
PHP_METHOD(lua_closure, invoke) { PHP_METHOD(lua_closure, invoke) {
lua_closure_object *objval = php_lua_closure_object_from_zend_object(Z_OBJ_P(getThis()));
int bp, sp; int bp, sp;
zval ***arguments = NULL; zval *arguments = NULL;
zval *lua_obj = NULL;
lua_State *L = NULL; lua_State *L = NULL;
zval *closure = NULL; zval rv;
if (ZEND_NUM_ARGS()) { if (ZEND_NUM_ARGS()) {
arguments = emalloc(sizeof(zval**) * ZEND_NUM_ARGS()); arguments = emalloc(sizeof(zval) * ZEND_NUM_ARGS());
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) { if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {
efree(arguments); efree(arguments);
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "cannot get arguments for calling closure"); zend_throw_exception_ex(NULL, 0, "cannot get arguments for calling closure");
return; return;
} }
} }
lua_obj = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_lua_object"), 1 TSRMLS_CC); if (Z_TYPE(objval->lua) != IS_OBJECT
|| !instanceof_function(Z_OBJCE(objval->lua), lua_ce)) {
if (ZVAL_IS_NULL(lua_obj) zend_throw_exception_ex(NULL, 0, "corrupted Lua object");
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce TSRMLS_CC)) {
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "corrupted Lua object");
return; return;
} }
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1 TSRMLS_CC); L = (Z_LUAVAL(objval->lua))->L;
if (!Z_LVAL_P(closure)) {
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid lua closure");
return;
}
L = Z_LUAVAL_P(lua_obj);
bp = lua_gettop(L); bp = lua_gettop(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, Z_LVAL_P(closure)); lua_rawgeti(L, LUA_REGISTRYINDEX, objval->closure);
if (LUA_TFUNCTION != lua_type(L, lua_gettop(L))) { if (LUA_TFUNCTION != lua_type(L, lua_gettop(L))) {
lua_pop(L, -1); lua_pop(L, -1);
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "call to lua closure failed"); zend_throw_exception_ex(NULL, 0, "call to lua closure failed");
return; return;
} }
if (ZEND_NUM_ARGS()) { if (ZEND_NUM_ARGS()) {
int i = 0; int i = 0;
for(;i<ZEND_NUM_ARGS();i++) { for(;i<ZEND_NUM_ARGS();i++) {
php_lua_send_zval_to_lua(L, *(arguments[i]) TSRMLS_CC); php_lua_send_zval_to_lua(L, &arguments[i]);
} }
} }
@@ -136,7 +113,7 @@ PHP_METHOD(lua_closure, invoke) {
efree(arguments); efree(arguments);
} }
lua_pop(L, lua_gettop(L) - bp); lua_pop(L, lua_gettop(L) - bp);
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, zend_throw_exception_ex(NULL, 0,
"call to lua function %s failed", lua_tostring(L, -1)); "call to lua function %s failed", lua_tostring(L, -1));
return; return;
} }
@@ -146,14 +123,14 @@ PHP_METHOD(lua_closure, invoke) {
if (!sp) { if (!sp) {
RETURN_NULL(); RETURN_NULL();
} else if (sp == 1) { } else if (sp == 1) {
zval *tmp = php_lua_get_zval_from_lua(L, -1, lua_obj TSRMLS_CC); php_lua_get_zval_from_lua(L, -1, &(objval->lua), return_value);
RETURN_ZVAL(tmp, 0, 0);
} else { } else {
zval rv;
int i = 0; int i = 0;
array_init(return_value); array_init(return_value);
for (i = -sp; i < 0; i++) { for (i = -sp; i < 0; i++) {
zval *tmp = php_lua_get_zval_from_lua(L, i, lua_obj TSRMLS_CC); php_lua_get_zval_from_lua(L, i, &(objval->lua), &rv);
add_next_index_zval(return_value, tmp); add_next_index_zval(return_value, &rv);
} }
} }
@@ -165,73 +142,52 @@ PHP_METHOD(lua_closure, invoke) {
} }
/* }}} */ /* }}} */
/** {{{ proto LuaClosure::__clone()
*/
PHP_METHOD(lua_closure, __clone) {
}
/* }}} */
/* {{{ lua_class_methods[] /* {{{ lua_class_methods[]
*
*/ */
zend_function_entry lua_closure_methods[] = { zend_function_entry lua_closure_methods[] = {
PHP_ME(lua_closure, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(lua_closure, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
PHP_ME(lua_closure, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
PHP_ME(lua_closure, __clone, NULL, ZEND_ACC_PRIVATE)
PHP_ME(lua_closure, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC) PHP_ME(lua_closure, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC)
PHP_MALIAS(lua_closure, __invoke, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC) PHP_MALIAS(lua_closure, __invoke, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL} PHP_FE_END
}; };
/* }}} */ /* }}} */
static void php_lua_closure_dtor_object(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */ static void php_lua_closure_free_obj(zend_object *zobj) /* {{{ */
{ {
zend_object *obj = (zend_object*)object; lua_closure_object *objval = php_lua_closure_object_from_zend_object(zobj);
zend_object_std_dtor(obj TSRMLS_CC); if ((Z_TYPE(objval->lua) == IS_OBJECT) &&
instanceof_function(Z_OBJCE(objval->lua), lua_ce)) {
efree(obj); luaL_unref((Z_LUAVAL(objval->lua))->L, LUA_REGISTRYINDEX, objval->closure);
}
zval_dtor(&(objval->lua));
zend_object_std_dtor(zobj);
} /* }}} */ } /* }}} */
static zend_object_value php_lua_closure_create_object(zend_class_entry *ce TSRMLS_DC) /* {{{ */ zend_object *php_lua_closure_create_object(zend_class_entry *ce) /* {{{ */
{ {
zend_object_value obj = {0}; lua_closure_object *objval = ecalloc(1, sizeof(lua_closure_object) + zend_object_properties_size(ce));
zend_object *lua_closure_obj = NULL; zend_object *zobj = &(objval->std);
lua_closure_obj = emalloc(sizeof(zend_object)); zend_object_std_init(zobj, ce);
zobj->handlers = &lua_closure_handlers;
zend_object_std_init(lua_closure_obj, ce TSRMLS_CC); return zobj;
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
zend_hash_copy(lua_closure_obj->properties, &ce->default_properties,
#if (PHP_MINOR_VERSION < 3)
(copy_ctor_func_t) zval_add_ref,
#else
zval_copy_property_ctor(ce),
#endif
(void *)0, sizeof(zval *));
#elif (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 3)
object_properties_init(lua_closure_obj, ce);
#endif
obj.handle = zend_objects_store_put(lua_closure_obj, php_lua_closure_dtor_object, NULL, NULL TSRMLS_CC);
obj.handlers = zend_get_std_object_handlers();
return obj;
} /* }}} */ } /* }}} */
void php_lua_closure_register(TSRMLS_D) /* {{{ */ void php_lua_closure_register() /* {{{ */
{ {
zend_class_entry ce; zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "LuaClosure", lua_closure_methods); INIT_CLASS_ENTRY(ce, "LuaClosure", lua_closure_methods);
lua_closure_ce = zend_register_internal_class(&ce TSRMLS_CC); lua_closure_ce = zend_register_internal_class(&ce);
lua_closure_ce->create_object = php_lua_closure_create_object; lua_closure_ce->create_object = php_lua_closure_create_object;
lua_closure_ce->ce_flags |= ZEND_ACC_FINAL; lua_closure_ce->ce_flags |= ZEND_ACC_FINAL;
zend_declare_property_long(lua_closure_ce, ZEND_STRL("_closure"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); memcpy(&lua_closure_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
zend_declare_property_null(lua_closure_ce, ZEND_STRL("_lua_object"), ZEND_ACC_PRIVATE TSRMLS_CC); lua_closure_handlers.offset = XtOffsetOf(lua_closure_object, std);
lua_closure_handlers.clone_obj = NULL;
lua_closure_handlers.free_obj = php_lua_closure_free_obj;
} /* }}} */ } /* }}} */
zend_class_entry *php_lua_get_closure_ce() /* {{{ */ zend_class_entry *php_lua_get_closure_ce() /* {{{ */
+17 -3
View File
@@ -13,13 +13,27 @@
| Author : Johannes Schlueter <johannes@php.net> | | Author : Johannes Schlueter <johannes@php.net> |
| Xinchen Hui <laruence@php.net> | | Xinchen Hui <laruence@php.net> |
| Marcelo Araujo <msaraujo@php.net> | | Marcelo Araujo <msaraujo@php.net> |
| Helmut Januschka <helmut@januschka.com> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
$Id: lua_closure.h 319733 2011-11-24 07:13:56Z laruence $
*/ */
void php_lua_closure_register(TSRMLS_D); #ifndef LUA_CLOSURE_H
#define LUA_CLOSURE_H
typedef struct _lua_closure_object {
long closure;
zval lua;
zend_object std;
} lua_closure_object;
static inline lua_closure_object* php_lua_closure_object_from_zend_object(zend_object *zobj) {
return ((lua_closure_object*)(zobj + 1)) - 1;
}
void php_lua_closure_register();
zend_class_entry *php_lua_get_closure_ce(); zend_class_entry *php_lua_get_closure_ce();
zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj TSRMLS_DC); zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj);
#endif
/* /*
* Local variables: * Local variables:
+311 -56
View File
@@ -1,68 +1,323 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.7" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<package version="1.0" packagerversion="1.9.4">
<name>lua</name> <name>lua</name>
<channel>pecl.php.net</channel>
<summary>Embedded lua interpreter</summary> <summary>Embedded lua interpreter</summary>
<description>&quot;Lua is a powerful, fast, light-weight, embeddable scripting language.&quot; <description>"Lua is a powerful, fast, light-weight, embeddable scripting language."
This extension embeds the lua interpreter and offers an OO-API to lua variables and functions. This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.</description>
</description> <lead>
<maintainers>
<maintainer>
<user>johannes</user>
<name>Johannes Schlüter</name> <name>Johannes Schlüter</name>
<user>johannes</user>
<email>johannes@php.net</email> <email>johannes@php.net</email>
<role>lead</role> <active>yes</active>
</maintainer> </lead>
<maintainer> <lead>
<user>laruence</user>
<name>Xinchen Hui</name> <name>Xinchen Hui</name>
<user>laruence</user>
<email>laruence@php.net</email> <email>laruence@php.net</email>
<role>lead</role> <active>yes</active>
</maintainer> </lead>
<maintainer> <developer>
<user>msaraujo</user>
<name>Marcelo Araujo</name> <name>Marcelo Araujo</name>
<user>msaraujo</user>
<email>msaraujo@php.net</email> <email>msaraujo@php.net</email>
<role>developer</role> <active>yes</active>
</maintainer> </developer>
</maintainers> <date>2020-03-10</date>
<release> <time>11:10:00</time>
<version>0.9.5</version> <version>
<date>2013-10-23</date> <release>2.0.7</release>
<license>PHP</license> <api>2.0.7</api>
<state>beta</state> </version>
<notes>- Fixed #65097 (nApplyCount release missing) (emptyhua at gmail dot com) <stability>
- Trigger E_STRICT when pass an array with index &apos;0&apos; to lua instead of ignoring it <release>stable</release>
- added support for callable functions and closures as values returned injected into lua engine (harald at octris dot org) <api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
- Fixed windows build for 7.4
</notes> </notes>
<deps> <contents>
<dep type="php" rel="ge" version="5.1.0"/> <dir name="/">
</deps> <file name="config.m4" role="src" />
<filelist> <file name="php_lua.h" role="src" />
<file name="lua.c" role="src" />
<file name="lua_closure.h" role="src" />
<file name="lua_closure.c" role="src" />
<file name="config.w32" role="src" />
<file name="CREDITS" role="doc" />
<file name="EXPERIMENTAL" role="doc" />
<file name="LICENSE" role="doc" />
<dir name="tests"> <dir name="tests">
<file role="test" name="001.phpt"/> <file name="001.phpt" role="test" />
<file role="test" name="002.phpt"/> <file name="002.phpt" role="test" />
<file role="test" name="003.phpt"/> <file name="003.phpt" role="test" />
<file role="test" name="004.phpt"/> <file name="004.phpt" role="test" />
<file role="test" name="005.phpt"/> <file name="005.phpt" role="test" />
<file role="test" name="006.phpt"/> <file name="006.phpt" role="test" />
<file role="test" name="007.phpt"/> <file name="007.phpt" role="test" />
<file role="test" name="008.phpt"/> <file name="008.phpt" role="test" />
<file role="test" name="009.phpt"/> <file name="009.phpt" role="test" />
<file role="test" name="010.phpt"/> <file name="010.phpt" role="test" />
<file role="test" name="011.phpt"/> <file name="011.phpt" role="test" />
<file role="test" name="012.phpt"/> <file name="012.phpt" role="test" />
<file role="test" name="013.phpt"/> <file name="013.phpt" role="test" />
</dir> <!-- /tests --> <file name="issue012.phpt" role="test" />
<file role="src" name="config.m4"/> <file name="bug65097.phpt" role="test" />
<file role="src" name="config.w32"/> <file name="bug71997.phpt" role="test" />
<file role="src" name="CREDITS"/> <file name="bug73964.phpt" role="test" />
<file role="src" name="EXPERIMENTAL"/> </dir>
<file role="src" name="LICENSE"/> </dir>
<file role="src" name="lua.c"/> </contents>
<file role="src" name="lua_closure.c"/> <dependencies>
<file role="src" name="lua_closure.h"/> <required>
<file role="src" name="php_lua.h"/> <php>
</filelist> <min>7.0.0</min>
</php>
<pearinstaller>
<min>1.4.0</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>lua</providesextension>
<extsrcrelease />
<changelog>
<release>
<date>2020-03-10</date>
<version>
<release>2.0.7</release>
<api>2.0.7</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed windows build for 7.4
</notes>
</release> </release>
<date>2018-12-21</date>
<version>
<release>2.0.6</release>
<api>2.0.6</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed Hash Recursive Detecting in PHP-7.3
</notes>
<release>
<date>2017-12-31</date>
<version>
<release>2.0.5</release>
<api>2.0.5</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Refactor LuaClosure. (SaraG)
- Fix non-string member access in read/write prop. (SaraG)
- Fix allocation of lua object. (SaraG)
</notes>
</release>
<release>
<date>2017-07-12</date>
<version>
<release>2.0.4</release>
<api>2.0.4</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #73964 (Segmentation fault)
</notes>
</release>
<release>
<date>2017-02-10</date>
<version>
<release>2.0.3</release>
<api>2.0.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua)
</notes>
</release>
<release>
<date>2016-05-26</date>
<version>
<release>2.0.2</release>
<api>2.0.2</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed issue #22 (Boolean FALSE is always TRUE)
</notes>
</release>
<release>
<date>2016-04-11</date>
<version>
<release>2.0.1</release>
<api>2.0.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #71997 (One-Dimensional arrays cause segmentation faults)
</notes>
</release>
<release>
<date>2015-10-27</date>
<version>
<release>2.0.0</release>
<api>2.0.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Release lua for PHP7
</notes>
</release>
<release>
<date>2012-10-23</date>
<version>
<release>1.1.0</release>
<api>1.1.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed #65097 (nApplyCount release missing) (emptyhua at gmail dot com)
- Trigger E_STRICT when pass an array with index '0' to lua instead of ignoring it
- added support for callable functions and closures as values returned injected into lua engine (harald at octris dot org)
</notes>
</release>
<release>
<date>2012-06-24</date>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Release stable version
</notes>
</release>
<release>
<date>2012-03-19</date>
<version>
<release>0.9.4</release>
<api>0.9.4</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Compatible with lua 5.2
</notes>
</release>
<release>
<date>2012-01-12</date>
<version>
<release>0.9.3</release>
<api>0.9.3</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fix build on windows
- Fix build when building lua with static
</notes>
</release>
<release>
<date>2012-01-06</date>
<version>
<release>0.9.2</release>
<api>0.9.2</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #60641 PECL install lua with lua5.1 packages
</notes>
</release>
<release>
<date>2011-11-24</date>
<version>
<release>0.9.1</release>
<api>0.9.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Compatible with PHP5.3+
- Fix ZTS build
- Fix mem leak when get value from lua
</notes>
</release>
<release>
<date>2011-08-03</date>
<version>
<release>0.9.0</release>
<api>0.9.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Merge Plua into Lua
- Api changes
- Add supporting for LUA_TFUNCTION
</notes>
</release>
</changelog>
</package> </package>
<!--
vim:et:ts=1:sw=1
-->
-200
View File
@@ -1,200 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.7" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>lua</name>
<channel>pecl.php.net</channel>
<summary>Embedded lua interpreter</summary>
<description>"Lua is a powerful, fast, light-weight, embeddable scripting language."
This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.</description>
<lead>
<name>Johannes Schlüter</name>
<user>johannes</user>
<email>johannes@php.net</email>
<active>yes</active>
</lead>
<lead>
<name>Xinchen Hui</name>
<user>laruence</user>
<email>laruence@php.net</email>
<active>yes</active>
</lead>
<developer>
<name>Marcelo Araujo</name>
<user>msaraujo</user>
<email>msaraujo@php.net</email>
<active>yes</active>
</developer>
<date>2013-10-23</date>
<time>12:04:27</time>
<version>
<release>1.1.0</release>
<api>1.1.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
- Fixed #65097 (nApplyCount release missing) (emptyhua at gmail dot com)
- Trigger E_STRICT when pass an array with index '0' to lua instead of ignoring it
- added support for callable functions and closures as values returned injected into lua engine (harald at octris dot org)
</notes>
<contents>
<dir name="/">
<file name="config.m4" role="src" />
<file name="php_lua.h" role="src" />
<file name="lua.c" role="src" />
<file name="lua_closure.h" role="src" />
<file name="lua_closure.c" role="src" />
<file name="config.w32" role="src" />
<file name="CREDITS" role="src" />
<file name="EXPERIMENTAL" role="src" />
<file name="LICENSE" role="src" />
<dir name="tests">
<file name="001.phpt" role="test" />
<file name="002.phpt" role="test" />
<file name="003.phpt" role="test" />
<file name="004.phpt" role="test" />
<file name="005.phpt" role="test" />
<file name="006.phpt" role="test" />
<file name="007.phpt" role="test" />
<file name="008.phpt" role="test" />
<file name="009.phpt" role="test" />
<file name="010.phpt" role="test" />
<file name="011.phpt" role="test" />
<file name="012.phpt" role="test" />
<file name="013.phpt" role="test" />
</dir>
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.1.0</min>
</php>
<pearinstaller>
<min>1.4.0</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>lua</providesextension>
<extsrcrelease />
<changelog>
<release>
<date>2012-10-23</date>
<version>
<release>1.1.0</release>
<api>1.1.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed #65097 (nApplyCount release missing) (emptyhua at gmail dot com)
- Trigger E_STRICT when pass an array with index '0' to lua instead of ignoring it
- added support for callable functions and closures as values returned injected into lua engine (harald at octris dot org)
</notes>
</release>
<release>
<date>2012-06-24</date>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Release stable version
</notes>
</release>
<release>
<date>2012-03-19</date>
<version>
<release>0.9.4</release>
<api>0.9.4</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Compatible with lua 5.2
</notes>
</release>
<release>
<date>2012-01-12</date>
<version>
<release>0.9.3</release>
<api>0.9.3</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fix build on windows
- Fix build when building lua with static
</notes>
</release>
<release>
<date>2012-01-06</date>
<version>
<release>0.9.2</release>
<api>0.9.2</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #60641 PECL install lua with lua5.1 packages
</notes>
</release>
<release>
<date>2011-11-24</date>
<version>
<release>0.9.1</release>
<api>0.9.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Compatible with PHP5.3+
- Fix ZTS build
- Fix mem leak when get value from lua
</notes>
</release>
<release>
<date>2011-08-03</date>
<version>
<release>0.9.0</release>
<api>0.9.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Merge Plua into Lua
- Api changes
- Add supporting for LUA_TFUNCTION
</notes>
</release>
</changelog>
</package>
<!--
vim:et:ts=1:sw=1
-->
+18 -13
View File
@@ -13,8 +13,8 @@
| Author : Johannes Schlueter <johannes@php.net> | | Author : Johannes Schlueter <johannes@php.net> |
| Xinchen Hui <laruence@php.net> | | Xinchen Hui <laruence@php.net> |
| Marcelo Araujo <msaraujo@php.net> | | Marcelo Araujo <msaraujo@php.net> |
| Helmut Januschka <helmut@januschka.com> |
+----------------------------------------------------------------------+ +----------------------------------------------------------------------+
$Id: php_lua.h 324349 2012-03-19 03:17:15Z laruence $
*/ */
#ifndef PHP_LUA_H #ifndef PHP_LUA_H
@@ -24,6 +24,11 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
/* LUA_OK is defined sinc 5.2 */
#ifndef LUA_OK
#define LUA_OK 0
#endif
extern zend_module_entry lua_module_entry; extern zend_module_entry lua_module_entry;
#define phpext_lua_ptr &lua_module_entry #define phpext_lua_ptr &lua_module_entry
@@ -43,24 +48,24 @@ extern zend_module_entry lua_module_entry;
#define LUA_G(v) (lua_globals.v) #define LUA_G(v) (lua_globals.v)
#endif #endif
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)) || (PHP_MAJOR_VERSION < 5) #define PHP_LUA_VERSION "2.0.8-dev"
#define Z_ADDREF_P ZVAL_ADDREF
#define Z_REFCOUNT_P ZVAL_REFCOUNT
#define Z_DELREF_P ZVAL_DELREF
#endif
#define PHP_LUA_VERSION "1.1.0"
#define Z_LUAVAL_P(obj) ((php_lua_object*)(zend_object_store_get_object(obj TSRMLS_CC)))->L
struct _php_lua_object { struct _php_lua_object {
zend_object obj;
lua_State *L; lua_State *L;
zend_object obj;
}; };
typedef struct _php_lua_object php_lua_object; typedef struct _php_lua_object php_lua_object;
zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_DC); static inline php_lua_object *php_lua_obj_from_obj(zend_object *obj) {
int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC); return (php_lua_object*)((char*)(obj)-XtOffsetOf(php_lua_object, obj));
}
#define Z_LUAVAL(obj) php_lua_obj_from_obj(Z_OBJ((obj)))
#define Z_LUAVAL_P(obj) php_lua_obj_from_obj(Z_OBJ_P((obj)))
zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv);
int php_lua_send_zval_to_lua(lua_State *L, zval *val);
PHP_MINIT_FUNCTION(lua); PHP_MINIT_FUNCTION(lua);
PHP_MSHUTDOWN_FUNCTION(lua); PHP_MSHUTDOWN_FUNCTION(lua);
@@ -69,8 +74,8 @@ PHP_MINFO_FUNCTION(lua);
PHP_METHOD(lua, __construct); PHP_METHOD(lua, __construct);
PHP_METHOD(lua, eval); PHP_METHOD(lua, eval);
PHP_METHOD(lua, require); PHP_METHOD(lua, require);
#endif /* PHP_LUA_H */
#endif /* PHP_LUA_H */
/* /*
* Local variables: * Local variables:
Regular → Executable
+3 -1
View File
@@ -15,7 +15,9 @@ try {
assert($e->getCode() == LUA_ERRSYNTAX); assert($e->getCode() == LUA_ERRSYNTAX);
echo "\n", $e->getMessage(); echo "\n", $e->getMessage();
} }
?>
--EXPECTF-- --EXPECTF--
12 12
-0.53657291800043 -0.53657291800043
[string "line"]:1: syntax error near 'code' [string "line"]:1: %s near 'code'
+30
View File
@@ -0,0 +1,30 @@
--TEST--
Check for Table Pass vic-a-verse
--SKIPIF--
<?php if (!extension_loaded("lua")) print "skip"; ?>
--FILE--
<?php
$l = new lua();
$l->eval(<<<CODE
function test(a)
lua_fcn(a)
end
CODE
);
$l->registerCallback("lua_fcn", function($a) {
ksort($a);
var_dump($a);
});
$l->test(array("key1"=>"v1",
"key2"=>"v2"));
--EXPECT--
array(2) {
["key1"]=>
string(2) "v1"
["key2"]=>
string(2) "v2"
}
+1 -1
View File
@@ -32,7 +32,7 @@ Testing fine
Hello PHP Hello PHP
Testing broken Testing broken
%s:%d: syntax error near 'fdrg' %s:%d: %s near 'fdrg'
Testing return Testing return
Array Array
( (
+45
View File
@@ -0,0 +1,45 @@
--TEST--
PHP Object to lua
--SKIPIF--
<?php if (!extension_loaded("lua")) print "skip"; ?>
--FILE--
<?php
class T {
private $v;
private $s;
public function __construct($v)
{
$this->v = $v;
$this->s = "string = $v";
}
static function create($arg)
{
return new self($arg);
}
}
$l = new lua();
$l->registerCallback('create_object', [T::class, 'create']);
$l->eval(<<<CODE
local t = create_object(2)
local keys = {}
for k, _ in pairs(t) do
table.insert(keys, k)
end
table.sort(keys)
for _,k in ipairs(keys) do
print(k, " -> ", t[k], ",")
end
CODE
);
?>
--EXPECTF--
s -> string = 2,v -> 2,
+4 -1
View File
@@ -1,7 +1,10 @@
--TEST-- --TEST--
Bug #65097 (nApplyCount release missing) Bug #65097 (nApplyCount release missing)
--SKIPIF-- --SKIPIF--
<?php if (!extension_loaded("lua")) print "skip"; ?> <?php
if (!extension_loaded("lua")) print "skip lua extension missing";
if (!extension_loaded("json")) print "skip json extension missing";
?>
--INI-- --INI--
error_reporting=E_ALL&~E_STRICT error_reporting=E_ALL&~E_STRICT
--FILE-- --FILE--
+22
View File
@@ -0,0 +1,22 @@
--TEST--
Bug #71997 (One-Dimensional arrays cause segmentation faults)
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$mylua = new \lua();
$mylua->eval(<<<CODE
function nicefunction(args)
print(args[1])
return args[1]
end
CODE
);
echo $mylua->call("nicefunction", array(array('hello', 'world')));
?>
done
--EXPECT--
worldworlddone
+45
View File
@@ -0,0 +1,45 @@
--TEST--
Bug #73964 (Segmentation fault (11))
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
class LuaTest
{
function __construct()
{
$this->lua = new Lua();
$this->lua->registerCallback("log", array($this, "API_LuaLog"));
}
function API_LuaLog( $entry)
{
echo("from lua: $entry");
}
public function RunTest()
{
$this->lua->eval(<<<CODE
function TestFunc(str)
log(str)
end
CODE
);
$GamePackage = $this->lua->RootTable;
$this->lua->call("TestFunc", array("okey"));
}
}
$a = new LuaTest();
$a->runtest();
?>
--EXPECT--
from lua: okey
+15
View File
@@ -0,0 +1,15 @@
--TEST--
ISSUE #022 (Boolean FALSE is always TRUE)
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$lua = new Lua();
$lua->assign('TEST', false);
$result = $lua->eval('return TEST');
var_dump($result)
?>
--EXPECT--
bool(false)
+19
View File
@@ -0,0 +1,19 @@
--TEST--
ISSUE #040 (segmentation fault)
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$lua = new Lua();
$lua->eval(<<<CODE
local a = {}
print(a)
CODE
);
?>
--EXPECT--
Array
(
)
BIN
View File
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
--TEST--
print with tables - 1
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$lua = new Lua();
$lua->eval(<<<CODE
local people = {
{
phone = "123456"
},
}
print(people)
CODE
);
?>
--EXPECT--
Array
(
[1] => Array
(
[phone] => 123456
)
)
+22
View File
@@ -0,0 +1,22 @@
--TEST--
print with tables - 2
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
$lua = new Lua();
$lua->eval(<<<CODE
local a = {
LEFT = 1,
}
print(a)
CODE
);
?>
--EXPECT--
Array
(
[LEFT] => 1
)
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
#exit 1 on error
echo "all ok ";
ls ./modules/bartlby.so
exit $?
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
phpize && ./configure --with-lua-version=5.2 && make