mirror of
https://github.com/php-win-ext/php-lua.git
synced 2026-03-26 18:12:17 +01:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff1eb10c9 | ||
|
|
cbe65b9ad6 | ||
|
|
04f7106631 | ||
|
|
7406b07f2c | ||
|
|
17cbba8b77 | ||
|
|
7cdb287c33 | ||
|
|
f3d6dca1a0 | ||
|
|
f177b21ff1 | ||
|
|
c7d9844cf1 | ||
|
|
12c53f28eb | ||
|
|
86cb62e0b8 | ||
|
|
dc226c345d | ||
|
|
2d23b565e5 | ||
|
|
6a2bf0e8af | ||
|
|
230a8af900 | ||
|
|
468203ce7c | ||
|
|
aaf49be301 | ||
|
|
1bd4adf039 | ||
|
|
18e2bb493d | ||
|
|
0b28ef4f55 | ||
|
|
d3323aa9fe | ||
|
|
f6a2f09b19 | ||
|
|
6c2a37f99c | ||
|
|
65764e0777 | ||
|
|
cf3f69b274 | ||
|
|
49b95a64f3 | ||
|
|
ca8cf30759 | ||
|
|
8bccbdc5db | ||
|
|
50d32564d2 | ||
|
|
a55478e449 | ||
|
|
adb5146954 | ||
|
|
b95ae16c6f | ||
|
|
c3b50a5645 | ||
|
|
bcc3bb67f8 | ||
|
|
5e5fefcdbf | ||
|
|
dea4f594e4 | ||
|
|
6205c5c4ff | ||
|
|
a2e9c435c4 | ||
|
|
061f22aac0 | ||
|
|
0c265c5e7d | ||
|
|
d893cd58c2 | ||
|
|
96d77a1c7a | ||
|
|
99e95d1bf5 | ||
|
|
10b0cf59cd | ||
|
|
561f632f62 | ||
|
|
22d5b508e7 | ||
|
|
4c8fff9af5 | ||
|
|
bef3b82b47 | ||
|
|
5489007dc8 | ||
|
|
c4f51f3b43 | ||
|
|
b56130d45b | ||
|
|
098a5ef470 |
23
.travis.yml
Normal file
23
.travis.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- liblua5.2-dev
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 7.0
|
||||||
|
|
||||||
|
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
CREDITS
1
CREDITS
@@ -2,3 +2,4 @@ lua
|
|||||||
Johannes Schlueter
|
Johannes Schlueter
|
||||||
Marcelo Araujo
|
Marcelo Araujo
|
||||||
Xinchen Hui
|
Xinchen Hui
|
||||||
|
Helmut Januschka
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
"Lua is a powerful, fast, light-weight, embeddable scripting language."
|
# PHP Lua
|
||||||
|
[](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."
|
||||||
41
config.m4
Normal file → Executable file
41
config.m4
Normal file → Executable file
@@ -1,34 +1,57 @@
|
|||||||
dnl $Id: config.m4 321796 2012-01-05 17:23:48Z laruence $
|
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 +64,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
|
||||||
|
|||||||
525
lua.c
Normal file → Executable file
525
lua.c
Normal file → Executable file
@@ -13,9 +13,9 @@
|
|||||||
| 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.c 324348 2012-03-19 03:12:15Z laruence $
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -90,7 +90,6 @@ ZEND_GET_MODULE(lua)
|
|||||||
/** {{{ static void php_lua_stack_dump(lua_State* L)
|
/** {{{ static void php_lua_stack_dump(lua_State* L)
|
||||||
* just for debug
|
* just for debug
|
||||||
*/
|
*/
|
||||||
#ifdef PHP_LUA_DEBUG
|
|
||||||
static void php_lua_stack_dump(lua_State* L) {
|
static void php_lua_stack_dump(lua_State* L) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
int n = lua_gettop(L);
|
int n = lua_gettop(L);
|
||||||
@@ -121,14 +120,12 @@ static void php_lua_stack_dump(lua_State* L) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ static int php_lua_atpanic(lua_State *L)
|
/** {{{ static int php_lua_atpanic(lua_State *L)
|
||||||
*/
|
*/
|
||||||
static int php_lua_atpanic(lua_State *L) {
|
static int php_lua_atpanic(lua_State *L) {
|
||||||
TSRMLS_FETCH();
|
php_error_docref(NULL, E_ERROR, "lua panic (%s)", lua_tostring(L, 1));
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "lua panic (%s)", lua_tostring(L, 1));
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
zend_bailout();
|
zend_bailout();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -138,13 +135,14 @@ static int php_lua_atpanic(lua_State *L) {
|
|||||||
/** {{{ static int php_lua_print(lua_State *L)
|
/** {{{ static int php_lua_print(lua_State *L)
|
||||||
*/
|
*/
|
||||||
static int php_lua_print(lua_State *L) {
|
static int php_lua_print(lua_State *L) {
|
||||||
|
zval rv;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int nargs = lua_gettop(L);
|
||||||
|
|
||||||
TSRMLS_FETCH();
|
for (i = 1; i <= nargs; ++i) {
|
||||||
for (i = -lua_gettop(L) ; i<0; i++) {
|
php_lua_get_zval_from_lua(L, i, NULL, &rv);
|
||||||
zval *tmp = php_lua_get_zval_from_lua(L, i, NULL TSRMLS_CC);
|
zend_print_zval_r(&rv, 1);
|
||||||
zend_print_zval_r(tmp, 1 TSRMLS_CC);
|
zval_ptr_dtor(&rv);
|
||||||
zval_ptr_dtor(&tmp);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -172,146 +170,102 @@ static void * php_lua_alloc_function(void *ud, void *ptr, size_t osize, size_t n
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ static void php_lua_dtor_object(void *object, zend_object_handle handle TSRMLS_DC)
|
static void php_lua_dtor_object(zend_object *object) /* {{{ */ {
|
||||||
* the dtor function for lua object
|
php_lua_object *lua_obj = php_lua_obj_from_obj(object);
|
||||||
*/
|
|
||||||
static void php_lua_dtor_object(void *object, zend_object_handle handle TSRMLS_DC) {
|
|
||||||
php_lua_object *lua_obj = (php_lua_object *)object;
|
|
||||||
|
|
||||||
zend_object_std_dtor(&(lua_obj->obj) TSRMLS_CC);
|
zend_object_std_dtor(&(lua_obj->obj));
|
||||||
|
|
||||||
if (lua_obj->L) {
|
if (lua_obj->L) {
|
||||||
lua_close(lua_obj->L);
|
lua_close(lua_obj->L);
|
||||||
}
|
}
|
||||||
|
|
||||||
efree(lua_obj);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ static zend_object_value php_lua_create_object(zend_class_entry *ce TSRMLS_DC)
|
/** {{{ static zend_object_value php_lua_create_object(zend_class_entry *ce)
|
||||||
*
|
|
||||||
* the create object handler for lua
|
|
||||||
*/
|
*/
|
||||||
static zend_object_value php_lua_create_object(zend_class_entry *ce TSRMLS_DC) {
|
zend_object *php_lua_create_object(zend_class_entry *ce)
|
||||||
zend_object_value obj = {0};
|
{
|
||||||
php_lua_object *lua_obj = NULL;
|
php_lua_object* intern;
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
|
|
||||||
L = lua_newstate(php_lua_alloc_function, NULL);
|
L = luaL_newstate();
|
||||||
|
|
||||||
lua_atpanic(L, php_lua_atpanic);
|
lua_atpanic(L, php_lua_atpanic);
|
||||||
|
|
||||||
lua_obj = emalloc(sizeof(php_lua_object));
|
intern = emalloc(sizeof(php_lua_object) + sizeof(zval) * (ce->default_properties_count - 1));
|
||||||
|
|
||||||
if (!lua_obj) {
|
if (!intern) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "alloc memory for lua object failed");
|
php_error_docref(NULL, E_ERROR, "alloc memory for lua object failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_obj->L = L;
|
intern->L = L;
|
||||||
zend_object_std_init(&(lua_obj->obj), ce TSRMLS_CC);
|
|
||||||
|
|
||||||
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
|
zend_object_std_init(&intern->obj, ce);
|
||||||
zend_hash_copy(lua_obj->obj.properties, &ce->default_properties,
|
object_properties_init(&intern->obj, ce);
|
||||||
#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_obj->obj), ce);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
obj.handle = zend_objects_store_put(lua_obj, php_lua_dtor_object, NULL, NULL TSRMLS_CC);
|
intern->obj.handlers = &lua_object_handlers;
|
||||||
obj.handlers = &lua_object_handlers;
|
|
||||||
|
|
||||||
return obj;
|
return &intern->obj;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ static zval * php_lua_read_property(zval *object, zval *member, int type TSRMLS_DC)
|
/** {{{ static zval * php_lua_read_property(zval *object, zval *member, int type)
|
||||||
*/
|
*/
|
||||||
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) || (PHP_MAJOR_VERSION < 5)
|
zval *php_lua_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv){
|
||||||
static zval * php_lua_read_property(zval *object, zval *member, int type TSRMLS_DC) {
|
lua_State *L = NULL;
|
||||||
#else
|
|
||||||
static zval * php_lua_read_property(zval *object, zval *member, int type, const struct _zend_literal *key TSRMLS_DC) {
|
|
||||||
#endif
|
|
||||||
zval *retval = NULL;
|
|
||||||
lua_State *L = NULL;
|
|
||||||
zval *tmp_member = NULL;
|
zval *tmp_member = NULL;
|
||||||
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 3))
|
|
||||||
(void)key;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (type != BP_VAR_R) {
|
if (type != BP_VAR_R) {
|
||||||
MAKE_STD_ZVAL(retval);
|
ZVAL_NULL(rv);
|
||||||
ZVAL_NULL(retval);
|
return rv;
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Z_TYPE_P(member) != IS_STRING) {
|
if (Z_TYPE_P(member) != IS_STRING) {
|
||||||
ALLOC_ZVAL(tmp_member);
|
|
||||||
*tmp_member = *member;
|
*tmp_member = *member;
|
||||||
INIT_PZVAL(tmp_member);
|
|
||||||
zval_copy_ctor(tmp_member);
|
zval_copy_ctor(tmp_member);
|
||||||
convert_to_string(tmp_member);
|
convert_to_string(tmp_member);
|
||||||
member = tmp_member;
|
member = tmp_member;
|
||||||
}
|
}
|
||||||
|
|
||||||
L = Z_LUAVAL_P(object);
|
L = (Z_LUAVAL_P(object))->L;
|
||||||
#if (LUA_VERSION_NUM < 502)
|
#if (LUA_VERSION_NUM < 502)
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, Z_STRVAL_P(member));
|
lua_getfield(L, LUA_GLOBALSINDEX, Z_STRVAL_P(member));
|
||||||
#else
|
#else
|
||||||
lua_getglobal(L, Z_STRVAL_P(member));
|
lua_getglobal(L, Z_STRVAL_P(member));
|
||||||
#endif
|
#endif
|
||||||
retval = php_lua_get_zval_from_lua(L, -1, object TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, -1, object, rv);
|
||||||
Z_DELREF_P(retval);
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
return rv;
|
||||||
if (tmp_member) {
|
|
||||||
zval_ptr_dtor(&tmp_member);
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ static void php_lua_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
|
/** {{{ static void php_lua_write_property(zval *object, zval *member, zval *value)
|
||||||
*/
|
*/
|
||||||
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) || (PHP_MAJOR_VERSION < 5)
|
static void php_lua_write_property(zval *object, zval *member, zval *value, void ** key) {
|
||||||
static void php_lua_write_property(zval *object, zval *member, zval *value TSRMLS_DC) {
|
|
||||||
#else
|
|
||||||
static void php_lua_write_property(zval *object, zval *member, zval *value, const struct _zend_literal *key TSRMLS_DC) {
|
|
||||||
#endif
|
|
||||||
lua_State *L = NULL;
|
lua_State *L = NULL;
|
||||||
zval *tmp_member = NULL;
|
zval *tmp_member = NULL;
|
||||||
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 3))
|
|
||||||
(void)key;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (Z_TYPE_P(member) != IS_STRING) {
|
if (Z_TYPE_P(member) != IS_STRING) {
|
||||||
ALLOC_ZVAL(tmp_member);
|
|
||||||
*tmp_member = *member;
|
*tmp_member = *member;
|
||||||
INIT_PZVAL(tmp_member);
|
|
||||||
zval_copy_ctor(tmp_member);
|
zval_copy_ctor(tmp_member);
|
||||||
convert_to_string(tmp_member);
|
convert_to_string(tmp_member);
|
||||||
member = tmp_member;
|
member = tmp_member;
|
||||||
}
|
}
|
||||||
|
|
||||||
L = Z_LUAVAL_P(object);
|
L = (Z_LUAVAL_P(object))->L;
|
||||||
|
|
||||||
#if (LUA_VERSION_NUM < 502)
|
#if (LUA_VERSION_NUM < 502)
|
||||||
php_lua_send_zval_to_lua(L, member TSRMLS_CC);
|
php_lua_send_zval_to_lua(L, member);
|
||||||
php_lua_send_zval_to_lua(L, value TSRMLS_CC);
|
php_lua_send_zval_to_lua(L, value);
|
||||||
|
|
||||||
lua_settable(L, LUA_GLOBALSINDEX);
|
lua_settable(L, LUA_GLOBALSINDEX);
|
||||||
#else
|
#else
|
||||||
php_lua_send_zval_to_lua(L, value TSRMLS_CC);
|
php_lua_send_zval_to_lua(L, value);
|
||||||
lua_setglobal(L, Z_STRVAL_P(member));
|
lua_setglobal(L, Z_STRVAL_P(member));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tmp_member) {
|
if (tmp_member) {
|
||||||
zval_ptr_dtor(&tmp_member);
|
zval_ptr_dtor(tmp_member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@@ -320,72 +274,57 @@ static void php_lua_write_property(zval *object, zval *member, zval *value, cons
|
|||||||
*/
|
*/
|
||||||
static int php_lua_call_callback(lua_State *L) {
|
static int php_lua_call_callback(lua_State *L) {
|
||||||
int order = 0;
|
int order = 0;
|
||||||
zval *return_value = NULL;
|
zval retval;
|
||||||
zval **func = NULL;
|
zval *func = NULL;
|
||||||
zval *callbacks = NULL;
|
zval *callbacks = NULL;
|
||||||
TSRMLS_FETCH();
|
|
||||||
|
|
||||||
order = lua_tonumber(L, lua_upvalueindex(1));
|
order = lua_tonumber(L, lua_upvalueindex(1));
|
||||||
|
|
||||||
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1 TSRMLS_CC);
|
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1);
|
||||||
|
|
||||||
if (ZVAL_IS_NULL(callbacks)) {
|
if (ZVAL_IS_NULL(callbacks)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MAKE_STD_ZVAL(return_value);
|
func = zend_hash_index_find(Z_ARRVAL_P(callbacks), order);
|
||||||
|
|
||||||
if (zend_hash_index_find(Z_ARRVAL_P(callbacks), order, (void **)&func) == FAILURE) {
|
if (!zend_is_callable(func, 0, NULL)) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!zend_is_callable(*func, 0, NULL TSRMLS_CC)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
zval **params = NULL;
|
zval *params;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int arg_num = lua_gettop(L);
|
int arg_num = lua_gettop(L);
|
||||||
|
|
||||||
params = ecalloc(arg_num, sizeof(zval));
|
params = safe_emalloc(sizeof(zval), arg_num, 0);
|
||||||
|
for (i = 0; i < arg_num; i++) {
|
||||||
for (; i<arg_num; i++) {
|
php_lua_get_zval_from_lua(L, -(arg_num - i), NULL, ¶ms[i]);
|
||||||
params[i] = php_lua_get_zval_from_lua(L, -(arg_num-i), NULL TSRMLS_CC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
call_user_function(EG(function_table), NULL, *func, return_value, arg_num, params TSRMLS_CC);
|
call_user_function(EG(function_table), NULL, func, &retval, arg_num, params);
|
||||||
|
php_lua_send_zval_to_lua(L, &retval);
|
||||||
|
|
||||||
php_lua_send_zval_to_lua(L, return_value TSRMLS_CC);
|
for (i = 0; i<arg_num; i++) {
|
||||||
|
|
||||||
for (i=0; i<arg_num; i++) {
|
|
||||||
zval_ptr_dtor(¶ms[i]);
|
zval_ptr_dtor(¶ms[i]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
efree(params);
|
efree(params);
|
||||||
zval_ptr_dtor(&return_value);
|
zval_ptr_dtor(&retval);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_DC)
|
zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv) /* {{{ */ {
|
||||||
*/
|
|
||||||
zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_DC) {
|
|
||||||
zval *retval;
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(retval);
|
|
||||||
ZVAL_NULL(retval);
|
|
||||||
|
|
||||||
switch (lua_type(L, index)) {
|
switch (lua_type(L, index)) {
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
ZVAL_NULL(retval);
|
ZVAL_NULL(rv);
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
ZVAL_BOOL(retval, lua_toboolean(L, index));
|
ZVAL_BOOL(rv, lua_toboolean(L, index));
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
ZVAL_DOUBLE(retval, lua_tonumber(L, index));
|
ZVAL_DOUBLE(rv, lua_tonumber(L, index));
|
||||||
break;
|
break;
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
{
|
{
|
||||||
@@ -393,32 +332,33 @@ zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_D
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
val = (char *)lua_tolstring(L, index, &len);
|
val = (char *)lua_tolstring(L, index, &len);
|
||||||
ZVAL_STRINGL(retval, val, len, 1);
|
ZVAL_STRINGL(rv, val, len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LUA_TTABLE:
|
case LUA_TTABLE:
|
||||||
array_init(retval);
|
array_init(rv);
|
||||||
lua_pushnil(L); /* first key */
|
lua_pushnil(L); /* first key */
|
||||||
while (lua_next(L, index-1) != 0) {
|
while (lua_next(L, index-1) != 0) {
|
||||||
zval *key = NULL;
|
zval key, val;
|
||||||
zval *val = NULL;
|
|
||||||
|
|
||||||
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
||||||
key = php_lua_get_zval_from_lua(L, -2, lua_obj TSRMLS_CC);
|
if (!php_lua_get_zval_from_lua(L, -2, lua_obj, &key)) {
|
||||||
val = php_lua_get_zval_from_lua(L, -1, lua_obj TSRMLS_CC);
|
break;
|
||||||
|
}
|
||||||
if (!key || !val) {
|
if (!php_lua_get_zval_from_lua(L, -1, lua_obj, &val)) {
|
||||||
|
zval_ptr_dtor(&key);
|
||||||
/* there is a warning already in php_lua_get_zval_from_lua */
|
/* there is a warning already in php_lua_get_zval_from_lua */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(Z_TYPE_P(key)) {
|
switch (Z_TYPE(key)) {
|
||||||
case IS_DOUBLE:
|
case IS_DOUBLE:
|
||||||
case IS_LONG:
|
case IS_LONG:
|
||||||
add_index_zval(retval, Z_DVAL_P(key), val);
|
add_index_zval(rv, Z_DVAL(key), &val);
|
||||||
break;
|
break;
|
||||||
case IS_STRING:
|
case IS_STRING:
|
||||||
add_assoc_zval(retval, Z_STRVAL_P(key), val);
|
add_assoc_zval(rv, Z_STRVAL(key), &val);
|
||||||
|
zval_ptr_dtor(&key);
|
||||||
break;
|
break;
|
||||||
case IS_ARRAY:
|
case IS_ARRAY:
|
||||||
case IS_OBJECT:
|
case IS_OBJECT:
|
||||||
@@ -426,22 +366,23 @@ zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_D
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
zval_ptr_dtor(&key);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LUA_TFUNCTION:
|
case LUA_TFUNCTION:
|
||||||
{
|
{
|
||||||
long ref_id = 0;
|
long ref_id = 0;
|
||||||
if (!lua_obj) {
|
if (!lua_obj) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "corrupted Lua object");
|
php_error_docref(NULL, E_WARNING, "corrupted Lua object");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushvalue(L, index);
|
lua_pushvalue(L, index);
|
||||||
ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
|
ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
if (!php_lua_closure_instance(retval, ref_id, lua_obj TSRMLS_CC)) {
|
if (!php_lua_closure_instance(rv, ref_id, lua_obj)) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to initialize closure object");
|
php_error_docref(NULL, E_WARNING, "failed to initialize closure object");
|
||||||
|
ZVAL_NULL(rv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -449,22 +390,26 @@ zval * php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj TSRMLS_D
|
|||||||
case LUA_TTHREAD:
|
case LUA_TTHREAD:
|
||||||
case LUA_TLIGHTUSERDATA:
|
case LUA_TLIGHTUSERDATA:
|
||||||
default:
|
default:
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unsupported type '%s' for php",
|
php_error_docref(NULL, E_WARNING, "unsupported type '%s' for php",
|
||||||
lua_typename(L, lua_type(L, index)));
|
lua_typename(L, lua_type(L, index)));
|
||||||
|
ZVAL_NULL(rv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return rv;
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC)
|
int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
|
||||||
*/
|
|
||||||
int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC) {
|
|
||||||
|
|
||||||
|
try_again:
|
||||||
switch (Z_TYPE_P(val)) {
|
switch (Z_TYPE_P(val)) {
|
||||||
case IS_BOOL:
|
case IS_TRUE:
|
||||||
lua_pushboolean(L, Z_BVAL_P(val));
|
lua_pushboolean(L, 1);
|
||||||
break;
|
break;
|
||||||
|
case IS_FALSE:
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
break;
|
||||||
|
case IS_UNDEF:
|
||||||
case IS_NULL:
|
case IS_NULL:
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
break;
|
break;
|
||||||
@@ -480,10 +425,10 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC) {
|
|||||||
case IS_OBJECT:
|
case IS_OBJECT:
|
||||||
case IS_ARRAY:
|
case IS_ARRAY:
|
||||||
{
|
{
|
||||||
if (zend_is_callable(val, 0, NULL TSRMLS_CC)) {
|
if (zend_is_callable(val, 0, NULL)) {
|
||||||
zval* callbacks = NULL;
|
zval *callbacks;
|
||||||
|
|
||||||
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1 TSRMLS_CC);
|
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1);
|
||||||
|
|
||||||
if (ZVAL_IS_NULL(callbacks)) {
|
if (ZVAL_IS_NULL(callbacks)) {
|
||||||
array_init(callbacks);
|
array_init(callbacks);
|
||||||
@@ -492,57 +437,53 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC) {
|
|||||||
lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
|
lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
|
||||||
lua_pushcclosure(L, php_lua_call_callback, 1);
|
lua_pushcclosure(L, php_lua_call_callback, 1);
|
||||||
|
|
||||||
zval_add_ref(&val);
|
zval_add_ref(val);
|
||||||
add_next_index_zval(callbacks, val);
|
add_next_index_zval(callbacks, val);
|
||||||
} else {
|
} else {
|
||||||
HashTable *ht = NULL;
|
zval *v;
|
||||||
zval **ppzval = NULL;
|
ulong longkey;
|
||||||
|
zend_string *key;
|
||||||
|
zval zkey;
|
||||||
|
|
||||||
ht = HASH_OF(val);
|
HashTable *ht = HASH_OF(val);
|
||||||
|
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
|
||||||
if (++ht->nApplyCount > 1) {
|
ZEND_HASH_INC_APPLY_COUNT(ht);
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "recursion found");
|
if (ZEND_HASH_GET_APPLY_COUNT(ht) > 1) {
|
||||||
--ht->nApplyCount;
|
php_error_docref(NULL, E_ERROR, "recursion found");
|
||||||
break;
|
ZEND_HASH_DEC_APPLY_COUNT(ht);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for(zend_hash_internal_pointer_reset(ht);
|
|
||||||
zend_hash_get_current_data(ht, (void **)&ppzval) == SUCCESS;
|
|
||||||
zend_hash_move_forward(ht)) {
|
|
||||||
char *key = NULL;
|
|
||||||
int len = 0;
|
|
||||||
long idx = 0;
|
|
||||||
zval *zkey= NULL;
|
|
||||||
|
|
||||||
switch(zend_hash_get_current_key_ex(ht, &key, &len, &idx, 0, NULL)) {
|
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, longkey, key, v) {
|
||||||
case HASH_KEY_IS_STRING :
|
if (key) {
|
||||||
MAKE_STD_ZVAL(zkey);
|
ZVAL_STR(&zkey, key);
|
||||||
ZVAL_STRINGL(zkey, key, len - 1, 1);
|
} else {
|
||||||
break;
|
ZVAL_LONG(&zkey, longkey);
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
if (idx == 0) {
|
|
||||||
php_error_docref(NULL TSRMLS_CC, E_STRICT,
|
|
||||||
"attempt to pass an array index begin with 0 to lua");
|
|
||||||
}
|
|
||||||
MAKE_STD_ZVAL(zkey);
|
|
||||||
ZVAL_LONG(zkey, idx);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
php_lua_send_zval_to_lua(L, &zkey);
|
||||||
php_lua_send_zval_to_lua(L, zkey TSRMLS_CC);
|
php_lua_send_zval_to_lua(L, v);
|
||||||
php_lua_send_zval_to_lua(L, *ppzval TSRMLS_CC);
|
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
zval_ptr_dtor(&zkey);
|
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
|
||||||
|
ZEND_HASH_DEC_APPLY_COUNT(ht);
|
||||||
}
|
}
|
||||||
--ht->nApplyCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case IS_REFERENCE:
|
||||||
|
ZVAL_DEREF(val);
|
||||||
|
goto try_again;
|
||||||
|
break;
|
||||||
|
case IS_INDIRECT:
|
||||||
|
val = Z_INDIRECT_P(val);
|
||||||
|
goto try_again;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "unsupported type `%s' for lua"
|
php_error_docref(NULL, E_ERROR, "unsupported type `%s' for lua", zend_zval_type_name(val));
|
||||||
, zend_zval_type_name(val));
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -551,52 +492,49 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val TSRMLS_DC) {
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/*** {{{ static int php_lua_arg_apply_func(void *data, void *L TSRMLS_DC)
|
/*** {{{ static int php_lua_arg_apply_func(void *data, void *L)
|
||||||
*/
|
*/
|
||||||
static int php_lua_arg_apply_func(void *data, void *L TSRMLS_DC) {
|
static int php_lua_arg_apply_func(void *data, void *L) {
|
||||||
php_lua_send_zval_to_lua((lua_State*)L, *(zval**)data TSRMLS_CC);
|
php_lua_send_zval_to_lua((lua_State*)L, (zval*)data);
|
||||||
return ZEND_HASH_APPLY_KEEP;
|
return ZEND_HASH_APPLY_KEEP;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
/** {{{ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, int use_self TSRMLS_DC)
|
static zval *php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, int use_self, zval *retval) /* {{{ */ {
|
||||||
*/
|
int bp = 0;
|
||||||
static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, int use_self TSRMLS_DC) {
|
int sp = 0;
|
||||||
int bp = 0;
|
|
||||||
int sp = 0;
|
|
||||||
int arg_num = 0;
|
int arg_num = 0;
|
||||||
zval *ret = NULL;
|
zval rv;
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
|
|
||||||
L = Z_LUAVAL_P(lua_obj);
|
L = (Z_LUAVAL_P(lua_obj))->L;
|
||||||
|
|
||||||
if (IS_ARRAY == Z_TYPE_P(func)) {
|
if (IS_ARRAY == Z_TYPE_P(func)) {
|
||||||
zval **t = NULL;
|
zval *t, *f;
|
||||||
zval **f = NULL;
|
if ((t = zend_hash_index_find(Z_ARRVAL_P(func), 0)) == NULL || Z_TYPE_P(t) != IS_STRING
|
||||||
if (zend_hash_index_find(Z_ARRVAL_P(func), 0, (void **)&t) == FAILURE || Z_TYPE_PP(t) != IS_STRING
|
|| (f = zend_hash_index_find(Z_ARRVAL_P(func), 1)) == NULL || Z_TYPE_P(f) != IS_STRING) {
|
||||||
|| zend_hash_index_find(Z_ARRVAL_P(func), 1, (void **)&f) == FAILURE || Z_TYPE_PP(f) != IS_STRING) {
|
|
||||||
/* as johannes suggesting use exceptioni to distinguish the error from a lua function return false
|
/* as johannes suggesting use exceptioni to distinguish the error from a lua function return false
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
php_error_docref(NULL, E_WARNING,
|
||||||
"invalid lua function, argument must be an array which contain two elements: array('table', 'method')");
|
"invalid lua function, argument must be an array which contain two elements: array('table', 'method')");
|
||||||
*/
|
*/
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC,
|
zend_throw_exception_ex(lua_exception_ce, 0,
|
||||||
"invalid lua function, argument must be an array which contain two elements: array('table', 'method')");
|
"invalid lua function, argument must be an array which contain two elements: array('table', 'method')");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#if (LUA_VERSION_NUM < 502)
|
#if (LUA_VERSION_NUM < 502)
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, Z_STRVAL_PP(t));
|
lua_getfield(L, LUA_GLOBALSINDEX, Z_STRVAL_P(t));
|
||||||
#else
|
#else
|
||||||
lua_getglobal(L, Z_STRVAL_PP(t));
|
lua_getglobal(L, Z_STRVAL_P(t));
|
||||||
#endif
|
#endif
|
||||||
if (LUA_TTABLE != lua_type(L, lua_gettop(L))) {
|
if (LUA_TTABLE != lua_type(L, lua_gettop(L))) {
|
||||||
lua_pop(L, -1);
|
lua_pop(L, -1);
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid lua table '%s'", Z_STRVAL_PP(t));
|
zend_throw_exception_ex(lua_exception_ce, 0, "invalid lua table '%s'", Z_STRVAL_P(t));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bp = lua_gettop(L);
|
bp = lua_gettop(L);
|
||||||
lua_getfield(L, -1, Z_STRVAL_PP(f));
|
lua_getfield(L, -1, Z_STRVAL_P(f));
|
||||||
if (LUA_TFUNCTION != lua_type(L, lua_gettop(L))) {
|
if (LUA_TFUNCTION != lua_type(L, lua_gettop(L))) {
|
||||||
lua_pop(L, -2);
|
lua_pop(L, -2);
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid lua table function '%s'.%s", Z_STRVAL_PP(t), Z_STRVAL_PP(f));
|
zend_throw_exception_ex(lua_exception_ce, 0, "invalid lua table function '%s'.%s", Z_STRVAL_P(t), Z_STRVAL_P(f));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (IS_STRING == Z_TYPE_P(func)) {
|
} else if (IS_STRING == Z_TYPE_P(func)) {
|
||||||
@@ -608,21 +546,21 @@ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, i
|
|||||||
#endif
|
#endif
|
||||||
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, "invalid lua function '%s'", Z_STRVAL_P(func));
|
zend_throw_exception_ex(lua_exception_ce, 0, "invalid lua function '%s'", Z_STRVAL_P(func));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (IS_OBJECT == Z_TYPE_P(func)
|
} else if (IS_OBJECT == Z_TYPE_P(func)
|
||||||
&& instanceof_function(Z_OBJCE_P(func), php_lua_get_closure_ce() TSRMLS_CC)) {
|
&& instanceof_function(Z_OBJCE_P(func), php_lua_get_closure_ce())) {
|
||||||
zval *closure = zend_read_property(php_lua_get_closure_ce(), func, ZEND_STRL("_closure"), 1 TSRMLS_CC);
|
zval *closure = zend_read_property(php_lua_get_closure_ce(), func, ZEND_STRL("_closure"), 1, &rv);
|
||||||
if (!Z_LVAL_P(closure)) {
|
if (!Z_LVAL_P(closure)) {
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid lua closure");
|
zend_throw_exception_ex(lua_exception_ce, 0, "invalid lua closure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bp = lua_gettop(L);
|
bp = lua_gettop(L);
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, Z_LVAL_P(closure));
|
lua_rawgeti(L, LUA_REGISTRYINDEX, Z_LVAL_P(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(lua_exception_ce, 0, "call to lua closure failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -635,11 +573,11 @@ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, i
|
|||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
arg_num += zend_hash_num_elements(Z_ARRVAL_P(args));
|
arg_num += zend_hash_num_elements(Z_ARRVAL_P(args));
|
||||||
zend_hash_apply_with_argument(Z_ARRVAL_P(args), php_lua_arg_apply_func, (void *)L TSRMLS_CC);
|
zend_hash_apply_with_argument(Z_ARRVAL_P(args), (apply_func_arg_t)php_lua_arg_apply_func, (void *)L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lua_pcall(L, arg_num, LUA_MULTRET, 0) != LUA_OK) {
|
if (lua_pcall(L, arg_num, LUA_MULTRET, 0) != LUA_OK) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
php_error_docref(NULL, E_WARNING,
|
||||||
"call to lua function %s failed", lua_tostring(L, -1));
|
"call to lua function %s failed", lua_tostring(L, -1));
|
||||||
lua_pop(L, lua_gettop(L) - bp);
|
lua_pop(L, lua_gettop(L) - bp);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -648,17 +586,16 @@ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, i
|
|||||||
sp = lua_gettop(L) - bp;
|
sp = lua_gettop(L) - bp;
|
||||||
|
|
||||||
if (!sp) {
|
if (!sp) {
|
||||||
MAKE_STD_ZVAL(ret);
|
ZVAL_NULL(retval);
|
||||||
ZVAL_NULL(ret);
|
|
||||||
} else if (sp == 1) {
|
} else if (sp == 1) {
|
||||||
ret = php_lua_get_zval_from_lua(L, -1, lua_obj TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, -1, lua_obj, retval);
|
||||||
} else {
|
} else {
|
||||||
|
zval rv;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
MAKE_STD_ZVAL(ret);
|
array_init(retval);
|
||||||
array_init(ret);
|
|
||||||
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, lua_obj, &rv);
|
||||||
add_next_index_zval(ret, tmp);
|
add_next_index_zval(retval, &rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,43 +605,43 @@ static zval * php_lua_call_lua_function(zval *lua_obj, zval *func, zval *args, i
|
|||||||
lua_pop(L, -1);
|
lua_pop(L, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return retval;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
/** {{{ proto Lua::eval(string $lua_chunk)
|
/** {{{ proto Lua::eval(string $lua_chunk)
|
||||||
* eval a lua chunk
|
* eval a lua chunk
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, eval) {
|
PHP_METHOD(lua, eval) {
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
char *statements = NULL;
|
char *statements;
|
||||||
long bp, len = 0;
|
long bp, len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
L = Z_LUAVAL_P(getThis());
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &statements, &len) == FAILURE) {
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statements, &len) == FAILURE) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
L = (Z_LUAVAL_P(getThis()))->L;
|
||||||
|
|
||||||
bp = lua_gettop(L);
|
bp = lua_gettop(L);
|
||||||
if ((ret = luaL_loadbuffer(L, statements, len, "line")) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
|
if ((ret = luaL_loadbuffer(L, statements, len, "line")) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
|
||||||
zend_throw_exception_ex(lua_exception_ce, ret TSRMLS_CC, "%s", lua_tostring(L, -1));
|
zend_throw_exception_ex(lua_exception_ce, ret, "%s", lua_tostring(L, -1));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
} else {
|
} else {
|
||||||
zval *tmp = NULL;
|
int ret_count;
|
||||||
int ret_count = 0;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
ret_count = lua_gettop(L) - bp;
|
ret_count = lua_gettop(L) - bp;
|
||||||
if (ret_count > 1) {
|
if (ret_count > 1) {
|
||||||
|
zval rv;
|
||||||
|
int i = 0;
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
for (i = -ret_count; i<0; i++) {
|
for (i = -ret_count; i<0; i++) {
|
||||||
tmp = php_lua_get_zval_from_lua(L, i, getThis() TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, i, getThis(), &rv);
|
||||||
add_next_index_zval(return_value, tmp);
|
add_next_index_zval(return_value, &rv);
|
||||||
}
|
}
|
||||||
} else if (ret_count) {
|
} else if (ret_count) {
|
||||||
zval *tmp = php_lua_get_zval_from_lua(L, -1, getThis() TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, -1, getThis(), return_value);
|
||||||
RETURN_ZVAL(tmp, 1, 1);
|
|
||||||
}
|
}
|
||||||
lua_pop(L, ret_count);
|
lua_pop(L, ret_count);
|
||||||
}
|
}
|
||||||
@@ -715,50 +652,41 @@ PHP_METHOD(lua, eval) {
|
|||||||
* run a lua script file
|
* run a lua script file
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, include) {
|
PHP_METHOD(lua, include) {
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
char *file = NULL;
|
char *file;
|
||||||
long bp, len = 0;
|
size_t bp, len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &len) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &len) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (php_check_open_basedir(file TSRMLS_CC)
|
if (php_check_open_basedir(file)) {
|
||||||
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) || (PHP_MAJOR_VERSION < 5)
|
|
||||||
|| (PG(safe_mode)
|
|
||||||
&& !php_checkuid(file, "rb+", CHECKUID_CHECK_MODE_PARAM))
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
L = Z_LUAVAL_P(getThis());
|
L = (Z_LUAVAL_P(getThis()))->L;
|
||||||
|
|
||||||
bp = lua_gettop(L);
|
bp = lua_gettop(L);
|
||||||
if ((ret = luaL_loadfile(L, file)) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
|
if ((ret = luaL_loadfile(L, file)) != LUA_OK || (ret = lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK)) {
|
||||||
zend_throw_exception_ex(lua_exception_ce, ret TSRMLS_CC, "%s", lua_tostring(L, -1));
|
zend_throw_exception_ex(lua_exception_ce, ret, "%s", lua_tostring(L, -1));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
} else {
|
} else {
|
||||||
zval *tmp = NULL;
|
int ret_count;
|
||||||
int ret_count = 0;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
ret_count = lua_gettop(L) - bp;
|
ret_count = lua_gettop(L) - bp;
|
||||||
if (ret_count > 1) {
|
if (ret_count > 1) {
|
||||||
|
zval rv;
|
||||||
|
int i = 0;
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
|
|
||||||
for (i = -ret_count; i<0; i++) {
|
for (i = -ret_count; i<0; i++) {
|
||||||
tmp = php_lua_get_zval_from_lua(L, i, getThis() TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, i, getThis(), &rv);
|
||||||
add_next_index_zval(return_value, tmp);
|
add_next_index_zval(return_value, &rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (ret_count) {
|
} else if (ret_count) {
|
||||||
zval *tmp = php_lua_get_zval_from_lua(L, -1, getThis() TSRMLS_CC);
|
php_lua_get_zval_from_lua(L, -1, getThis(), return_value);
|
||||||
RETURN_ZVAL(tmp, 1, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop(L, ret_count);
|
lua_pop(L, ret_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -768,41 +696,37 @@ PHP_METHOD(lua, include) {
|
|||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, call) {
|
PHP_METHOD(lua, call) {
|
||||||
long u_self = 0;
|
long u_self = 0;
|
||||||
|
zval *func;
|
||||||
zval *args = NULL;
|
zval *args = NULL;
|
||||||
zval *func = NULL;
|
|
||||||
zval *ret = NULL;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|al", &func, &args, &u_self) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|al", &func, &args, &u_self) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = php_lua_call_lua_function(getThis(), func, args, u_self TSRMLS_CC))) {
|
if (!(php_lua_call_lua_function(getThis(), func, args, u_self, return_value))) {
|
||||||
RETURN_ZVAL(ret, 1, 1);
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ proto Lua::assign(string $name, mix $value)
|
/** {{{ proto Lua::assign(string $name, mix $value)
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, assign) {
|
PHP_METHOD(lua, assign) {
|
||||||
char *name = NULL;
|
zval *name;
|
||||||
zval *value = NULL;
|
zval *value;
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &name, &value) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
L = Z_LUAVAL_P(getThis());
|
L = (Z_LUAVAL_P(getThis()))->L;
|
||||||
|
|
||||||
php_lua_send_zval_to_lua(L, value TSRMLS_CC);
|
php_lua_send_zval_to_lua(L, value);
|
||||||
#if (LUA_VERSION_NUM < 502)
|
#if (LUA_VERSION_NUM < 502)
|
||||||
lua_setfield(L, LUA_GLOBALSINDEX, name);
|
lua_setfield(L, LUA_GLOBALSINDEX, Z_STRVAL_P(name));
|
||||||
#else
|
#else
|
||||||
lua_setglobal(L, name);
|
lua_setglobal(L, Z_STRVAL_P(name));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RETURN_ZVAL(getThis(), 1, 0);
|
RETURN_ZVAL(getThis(), 1, 0);
|
||||||
@@ -812,33 +736,34 @@ PHP_METHOD(lua, assign) {
|
|||||||
/** {{{ proto Lua::registerCallback(string $name, mix $value)
|
/** {{{ proto Lua::registerCallback(string $name, mix $value)
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, registerCallback) {
|
PHP_METHOD(lua, registerCallback) {
|
||||||
char *name = NULL;
|
char *name;
|
||||||
long len = 0;
|
size_t len;
|
||||||
zval *func = NULL;
|
zval *func;
|
||||||
lua_State *L = NULL;
|
lua_State *L;
|
||||||
zval* callbacks = NULL;
|
zval* callbacks;
|
||||||
L = Z_LUAVAL_P(getThis());
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sz", &name, &len, &func) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS(),"sz", &name, &len, &func) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1 TSRMLS_CC);
|
L = (Z_LUAVAL_P(getThis()))->L;
|
||||||
|
|
||||||
|
callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1);
|
||||||
|
|
||||||
if (ZVAL_IS_NULL(callbacks)) {
|
if (ZVAL_IS_NULL(callbacks)) {
|
||||||
array_init(callbacks);
|
array_init(callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zend_is_callable(func, 0, NULL TSRMLS_CC)) {
|
if (zend_is_callable(func, 0, NULL)) {
|
||||||
lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
|
lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
|
||||||
lua_pushcclosure(L, php_lua_call_callback, 1);
|
lua_pushcclosure(L, php_lua_call_callback, 1);
|
||||||
lua_setglobal(L, name);
|
lua_setglobal(L, name);
|
||||||
} else {
|
} else {
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid php callback");
|
zend_throw_exception_ex(lua_exception_ce, 0, "invalid php callback");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
zval_add_ref(&func);
|
zval_add_ref(func);
|
||||||
add_next_index_zval(callbacks, func);
|
add_next_index_zval(callbacks, func);
|
||||||
|
|
||||||
RETURN_ZVAL(getThis(), 1, 0);
|
RETURN_ZVAL(getThis(), 1, 0);
|
||||||
@@ -848,14 +773,15 @@ PHP_METHOD(lua, registerCallback) {
|
|||||||
/** {{{ proto Lua::getVersion()
|
/** {{{ proto Lua::getVersion()
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, getVersion) {
|
PHP_METHOD(lua, getVersion) {
|
||||||
RETURN_STRING(LUA_RELEASE, 1);
|
RETURN_STRING(LUA_RELEASE);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/** {{{ proto Lua::__construct()
|
/** {{{ proto Lua::__construct()
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua, __construct) {
|
PHP_METHOD(lua, __construct) {
|
||||||
lua_State *L = Z_LUAVAL_P(getThis());
|
lua_State * L = (Z_LUAVAL_P(getThis()))->L;
|
||||||
|
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
lua_register(L, "print", php_lua_print);
|
lua_register(L, "print", php_lua_print);
|
||||||
if (ZEND_NUM_ARGS()) {
|
if (ZEND_NUM_ARGS()) {
|
||||||
@@ -892,33 +818,34 @@ PHP_MINIT_FUNCTION(lua) {
|
|||||||
REGISTER_LONG_CONSTANT("LUA_ERRRUN", LUA_ERRRUN, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRRUN", LUA_ERRRUN, CONST_PERSISTENT | CONST_CS);
|
||||||
REGISTER_LONG_CONSTANT("LUA_ERRSYNTAX", LUA_ERRSYNTAX, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRSYNTAX", LUA_ERRSYNTAX, CONST_PERSISTENT | CONST_CS);
|
||||||
REGISTER_LONG_CONSTANT("LUA_ERRMEM", LUA_ERRMEM, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRMEM", LUA_ERRMEM, CONST_PERSISTENT | CONST_CS);
|
||||||
|
#ifdef LUA_ERRGCMM
|
||||||
REGISTER_LONG_CONSTANT("LUA_ERRGCMM", LUA_ERRGCMM, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRGCMM", LUA_ERRGCMM, CONST_PERSISTENT | CONST_CS);
|
||||||
|
#endif
|
||||||
REGISTER_LONG_CONSTANT("LUA_ERRERR", LUA_ERRERR, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRERR", LUA_ERRERR, CONST_PERSISTENT | CONST_CS);
|
||||||
REGISTER_LONG_CONSTANT("LUA_ERRFILE", LUA_ERRFILE, CONST_PERSISTENT | CONST_CS);
|
REGISTER_LONG_CONSTANT("LUA_ERRFILE", LUA_ERRFILE, CONST_PERSISTENT | CONST_CS);
|
||||||
|
|
||||||
|
|
||||||
lua_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
lua_ce = zend_register_internal_class(&ce);
|
||||||
|
|
||||||
lua_ce->create_object = php_lua_create_object;
|
lua_ce->create_object = php_lua_create_object;
|
||||||
memcpy(&lua_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
memcpy(&lua_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||||
|
lua_object_handlers.offset = XtOffsetOf(php_lua_object, obj);
|
||||||
|
lua_object_handlers.dtor_obj = php_lua_dtor_object;
|
||||||
|
lua_object_handlers.free_obj = NULL;
|
||||||
|
lua_object_handlers.clone_obj = NULL;
|
||||||
lua_object_handlers.write_property = php_lua_write_property;
|
lua_object_handlers.write_property = php_lua_write_property;
|
||||||
lua_object_handlers.read_property = php_lua_read_property;
|
lua_object_handlers.read_property = php_lua_read_property;
|
||||||
|
|
||||||
lua_ce->ce_flags |= ZEND_ACC_FINAL;
|
lua_ce->ce_flags |= ZEND_ACC_FINAL;
|
||||||
|
|
||||||
zend_declare_property_null(lua_ce, ZEND_STRL("_callbacks"), ZEND_ACC_STATIC|ZEND_ACC_PRIVATE TSRMLS_CC);
|
zend_declare_property_null(lua_ce, ZEND_STRL("_callbacks"), ZEND_ACC_STATIC|ZEND_ACC_PRIVATE);
|
||||||
zend_declare_class_constant_string(lua_ce, ZEND_STRL("LUA_VERSION"), LUA_RELEASE TSRMLS_CC);
|
zend_declare_class_constant_string(lua_ce, ZEND_STRL("LUA_VERSION"), LUA_RELEASE);
|
||||||
|
|
||||||
php_lua_closure_register(TSRMLS_C);
|
php_lua_closure_register();
|
||||||
|
|
||||||
INIT_CLASS_ENTRY(ce, "LuaException", NULL);
|
INIT_CLASS_ENTRY(ce, "LuaException", NULL);
|
||||||
lua_exception_ce = zend_register_internal_class_ex(&ce,
|
|
||||||
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
|
lua_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default());
|
||||||
zend_exception_get_default(),
|
|
||||||
#else
|
|
||||||
zend_exception_get_default(TSRMLS_C),
|
|
||||||
#endif
|
|
||||||
NULL TSRMLS_CC);
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
| license@php.net so we can mail you a copy immediately. |
|
| license@php.net so we can mail you a copy immediately. |
|
||||||
+----------------------------------------------------------------------+
|
+----------------------------------------------------------------------+
|
||||||
| 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
|
||||||
@@ -43,12 +43,12 @@ 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) {
|
||||||
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);
|
zend_update_property_long(lua_closure_ce, instance, ZEND_STRL("_closure"), ref_id);
|
||||||
zend_update_property(lua_closure_ce, instance, ZEND_STRL("_lua_object"), lua_obj TSRMLS_CC);
|
zend_update_property(lua_closure_ce, instance, ZEND_STRL("_lua_object"), lua_obj);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@@ -63,21 +63,21 @@ PHP_METHOD(lua_closure, __construct) {
|
|||||||
/** {{{ proto LuaClosure::__destruct()
|
/** {{{ proto LuaClosure::__destruct()
|
||||||
*/
|
*/
|
||||||
PHP_METHOD(lua_closure, __destruct) {
|
PHP_METHOD(lua_closure, __destruct) {
|
||||||
zval *lua_obj, *closure;
|
zval *lua_obj, *closure, rv;
|
||||||
|
|
||||||
lua_obj = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_lua_object"), 1 TSRMLS_CC);
|
lua_obj = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_lua_object"), 1, &rv);
|
||||||
if (ZVAL_IS_NULL(lua_obj)
|
if (ZVAL_IS_NULL(lua_obj)
|
||||||
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|
||||||
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce TSRMLS_CC)) {
|
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce)) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1 TSRMLS_CC);
|
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1, &rv);
|
||||||
if (!Z_LVAL_P(closure)) {
|
if (!Z_LVAL_P(closure)) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
luaL_unref(Z_LUAVAL_P(lua_obj), LUA_REGISTRYINDEX, Z_LVAL_P(closure));
|
luaL_unref((Z_LUAVAL_P(lua_obj))->L, LUA_REGISTRYINDEX, Z_LVAL_P(closure));
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@@ -85,49 +85,50 @@ PHP_METHOD(lua_closure, __destruct) {
|
|||||||
*/
|
*/
|
||||||
PHP_METHOD(lua_closure, invoke) {
|
PHP_METHOD(lua_closure, invoke) {
|
||||||
int bp, sp;
|
int bp, sp;
|
||||||
zval ***arguments = NULL;
|
zval *arguments = NULL;
|
||||||
zval *lua_obj = NULL;
|
zval *lua_obj = NULL;
|
||||||
lua_State *L = NULL;
|
lua_State *L = NULL;
|
||||||
zval *closure = 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);
|
lua_obj = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_lua_object"), 1, &rv);
|
||||||
|
|
||||||
if (ZVAL_IS_NULL(lua_obj)
|
if (ZVAL_IS_NULL(lua_obj)
|
||||||
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|
|| Z_TYPE_P(lua_obj) != IS_OBJECT
|
||||||
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce TSRMLS_CC)) {
|
|| !instanceof_function(Z_OBJCE_P(lua_obj), lua_ce)) {
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "corrupted Lua object");
|
zend_throw_exception_ex(NULL, 0, "corrupted Lua object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1 TSRMLS_CC);
|
closure = zend_read_property(lua_closure_ce, getThis(), ZEND_STRL("_closure"), 1, &rv);
|
||||||
if (!Z_LVAL_P(closure)) {
|
if (!Z_LVAL_P(closure)) {
|
||||||
zend_throw_exception_ex(lua_exception_ce, 0 TSRMLS_CC, "invalid lua closure");
|
zend_throw_exception_ex(NULL, 0, "invalid lua closure");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
L = Z_LUAVAL_P(lua_obj);
|
L = (Z_LUAVAL_P(lua_obj))->L;
|
||||||
|
|
||||||
bp = lua_gettop(L);
|
bp = lua_gettop(L);
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, Z_LVAL_P(closure));
|
lua_rawgeti(L, LUA_REGISTRYINDEX, Z_LVAL_P(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 +137,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 +147,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, lua_obj, 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, lua_obj, &rv);
|
||||||
add_next_index_zval(return_value, tmp);
|
add_next_index_zval(return_value, &rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,52 +185,45 @@ zend_function_entry lua_closure_methods[] = {
|
|||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static void php_lua_closure_dtor_object(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */
|
static void php_lua_closure_dtor_object(void *object, zend_object_handlers handle) /* {{{ */
|
||||||
{
|
{
|
||||||
zend_object *obj = (zend_object*)object;
|
zend_object *obj = (zend_object*)object;
|
||||||
|
|
||||||
zend_object_std_dtor(obj TSRMLS_CC);
|
zend_object_std_dtor(obj);
|
||||||
|
|
||||||
efree(obj);
|
efree(obj);
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
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};
|
zend_object *intern;
|
||||||
zend_object *lua_closure_obj = NULL;
|
|
||||||
|
|
||||||
lua_closure_obj = emalloc(sizeof(zend_object));
|
intern = emalloc(sizeof(zend_object)+ sizeof(zval) * (ce->default_properties_count - 1));
|
||||||
|
|
||||||
zend_object_std_init(lua_closure_obj, ce TSRMLS_CC);
|
if (!intern) {
|
||||||
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
|
php_error_docref(NULL, E_ERROR, "alloc memory for lua object failed");
|
||||||
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);
|
zend_object_std_init(intern, ce);
|
||||||
obj.handlers = zend_get_std_object_handlers();
|
object_properties_init(intern, ce);
|
||||||
|
|
||||||
|
intern->handlers = zend_get_std_object_handlers();
|
||||||
|
|
||||||
|
return intern;
|
||||||
|
|
||||||
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);
|
zend_declare_property_long(lua_closure_ce, ZEND_STRL("_closure"), 0, ZEND_ACC_PRIVATE);
|
||||||
zend_declare_property_null(lua_closure_ce, ZEND_STRL("_lua_object"), ZEND_ACC_PRIVATE TSRMLS_CC);
|
zend_declare_property_null(lua_closure_ce, ZEND_STRL("_lua_object"), ZEND_ACC_PRIVATE);
|
||||||
|
|
||||||
|
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|||||||
@@ -11,15 +11,18 @@
|
|||||||
| license@php.net so we can mail you a copy immediately. |
|
| license@php.net so we can mail you a copy immediately. |
|
||||||
+----------------------------------------------------------------------+
|
+----------------------------------------------------------------------+
|
||||||
| 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
|
||||||
|
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:
|
||||||
|
|||||||
321
package.xml
321
package.xml
@@ -1,68 +1,261 @@
|
|||||||
<?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>"Lua is a powerful, fast, light-weight, embeddable scripting language."
|
<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>
|
<name>Johannes Schlüter</name>
|
||||||
<maintainer>
|
<user>johannes</user>
|
||||||
<user>johannes</user>
|
<email>johannes@php.net</email>
|
||||||
<name>Johannes Schlüter</name>
|
<active>yes</active>
|
||||||
<email>johannes@php.net</email>
|
</lead>
|
||||||
<role>lead</role>
|
<lead>
|
||||||
</maintainer>
|
<name>Xinchen Hui</name>
|
||||||
<maintainer>
|
<user>laruence</user>
|
||||||
<user>laruence</user>
|
<email>laruence@php.net</email>
|
||||||
<name>Xinchen Hui</name>
|
<active>yes</active>
|
||||||
<email>laruence@php.net</email>
|
</lead>
|
||||||
<role>lead</role>
|
<developer>
|
||||||
</maintainer>
|
<name>Marcelo Araujo</name>
|
||||||
<maintainer>
|
<user>msaraujo</user>
|
||||||
<user>msaraujo</user>
|
<email>msaraujo@php.net</email>
|
||||||
<name>Marcelo Araujo</name>
|
<active>yes</active>
|
||||||
<email>msaraujo@php.net</email>
|
</developer>
|
||||||
<role>developer</role>
|
<date>2017-02-10</date>
|
||||||
</maintainer>
|
<time>19:15:00</time>
|
||||||
</maintainers>
|
<version>
|
||||||
<release>
|
<release>2.0.3</release>
|
||||||
<version>0.9.5</version>
|
<api>2.0.3</api>
|
||||||
<date>2013-10-23</date>
|
</version>
|
||||||
<license>PHP</license>
|
<stability>
|
||||||
<state>beta</state>
|
<release>stable</release>
|
||||||
<notes>- Fixed #65097 (nApplyCount release missing) (emptyhua at gmail dot com)
|
<api>stable</api>
|
||||||
- Trigger E_STRICT when pass an array with index '0' to lua instead of ignoring it
|
</stability>
|
||||||
- added support for callable functions and closures as values returned injected into lua engine (harald at octris dot org)
|
<license uri="http://www.php.net/license">PHP</license>
|
||||||
</notes>
|
<notes>
|
||||||
<deps>
|
- Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua)
|
||||||
<dep type="php" rel="ge" version="5.1.0"/>
|
</notes>
|
||||||
</deps>
|
<contents>
|
||||||
<filelist>
|
<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="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"/>
|
</dir>
|
||||||
<file role="src" name="EXPERIMENTAL"/>
|
</dir>
|
||||||
<file role="src" name="LICENSE"/>
|
</contents>
|
||||||
<file role="src" name="lua.c"/>
|
<dependencies>
|
||||||
<file role="src" name="lua_closure.c"/>
|
<required>
|
||||||
<file role="src" name="lua_closure.h"/>
|
<php>
|
||||||
<file role="src" name="php_lua.h"/>
|
<min>7.0.0</min>
|
||||||
</filelist>
|
</php>
|
||||||
</release>
|
<pearinstaller>
|
||||||
|
<min>1.4.0</min>
|
||||||
|
</pearinstaller>
|
||||||
|
</required>
|
||||||
|
</dependencies>
|
||||||
|
<providesextension>lua</providesextension>
|
||||||
|
<extsrcrelease />
|
||||||
|
<changelog>
|
||||||
|
<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
package2.xml
200
package2.xml
@@ -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
|
|
||||||
-->
|
|
||||||
32
php_lua.h
32
php_lua.h
@@ -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,23 @@ 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.3"
|
||||||
#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_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 +73,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:
|
||||||
|
|||||||
4
tests/001.phpt
Normal file → Executable file
4
tests/001.phpt
Normal file → Executable 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
tests/0014.phpt
Normal file
30
tests/0014.phpt
Normal 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"
|
||||||
|
}
|
||||||
@@ -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
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -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
tests/bug71997.phpt
Normal file
22
tests/bug71997.phpt
Normal 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
|
||||||
15
tests/issue012.phpt
Normal file
15
tests/issue012.phpt
Normal 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)
|
||||||
7
travis/build_check.sh
Executable file
7
travis/build_check.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
|
#exit 1 on error
|
||||||
|
echo "all ok ";
|
||||||
|
ls ./modules/bartlby.so
|
||||||
|
exit $?
|
||||||
2
travis/compile.sh
Executable file
2
travis/compile.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
phpize && ./configure --with-lua-version=5.2 && make
|
||||||
Reference in New Issue
Block a user