mirror of
https://github.com/php-win-ext/php-lua.git
synced 2026-03-24 00:52:12 +01:00
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.*.swp
|
||||
|
||||
21
lua.c
21
lua.c
@@ -321,15 +321,18 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv
|
||||
break;
|
||||
case LUA_TTABLE:
|
||||
array_init(rv);
|
||||
lua_pushnil(L); /* first key */
|
||||
while (lua_next(L, index-1) != 0) {
|
||||
lua_pushvalue(L, index); // table
|
||||
lua_pushnil(L); // first key
|
||||
while (lua_next(L, -2) != 0) {
|
||||
zval key, val;
|
||||
|
||||
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
||||
if (!php_lua_get_zval_from_lua(L, -2, lua_obj, &key)) {
|
||||
lua_pushvalue(L, -2);
|
||||
|
||||
/* uses 'key' (at index -1) and 'value' (at index -2) */
|
||||
if (!php_lua_get_zval_from_lua(L, -1, lua_obj, &key)) {
|
||||
break;
|
||||
}
|
||||
if (!php_lua_get_zval_from_lua(L, -1, lua_obj, &val)) {
|
||||
if (!php_lua_get_zval_from_lua(L, -2, lua_obj, &val)) {
|
||||
zval_ptr_dtor(&key);
|
||||
/* there is a warning already in php_lua_get_zval_from_lua */
|
||||
break;
|
||||
@@ -349,17 +352,13 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv
|
||||
default:
|
||||
break;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
break;
|
||||
case LUA_TFUNCTION:
|
||||
{
|
||||
long ref_id = 0;
|
||||
if (!lua_obj) {
|
||||
php_error_docref(NULL, E_WARNING, "corrupted Lua object");
|
||||
break;
|
||||
}
|
||||
|
||||
lua_pushvalue(L, index);
|
||||
ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
|
||||
@@ -53,7 +53,9 @@ zval* php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj) {
|
||||
object_init_ex(instance, lua_closure_ce);
|
||||
objval = php_lua_closure_object_from_zend_object(Z_OBJ_P(instance));
|
||||
objval->closure = ref_id;
|
||||
ZVAL_ZVAL(&(objval->lua), lua_obj, 1, 0);
|
||||
if (lua_obj) {
|
||||
ZVAL_ZVAL(&(objval->lua), lua_obj, 1, 0);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
@@ -75,7 +77,7 @@ PHP_METHOD(lua_closure, invoke) {
|
||||
zval rv;
|
||||
|
||||
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) {
|
||||
efree(arguments);
|
||||
zend_throw_exception_ex(NULL, 0, "cannot get arguments for calling closure");
|
||||
|
||||
19
tests/issue040.phpt
Normal file
19
tests/issue040.phpt
Normal 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
tests/print.phpt
Normal file
BIN
tests/print.phpt
Normal file
Binary file not shown.
28
tests/print_tables-1.phpt
Normal file
28
tests/print_tables-1.phpt
Normal 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
tests/print_tables-2.phpt
Normal file
22
tests/print_tables-2.phpt
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user