mirror of
https://github.com/php-win-ext/php-lua.git
synced 2026-03-24 00:52:12 +01:00
Fixed issue #40
Using absolute index could be error-prone, updated code to use relative indices as it commonly done with Lua
This commit is contained in:
committed by
Antony Dovgal
parent
84c831e4cb
commit
24fd1baf19
5
lua.c
5
lua.c
@@ -321,8 +321,11 @@ 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_pushvalue(L, index); /* stack now contains: -1 => table */
|
||||
|
||||
lua_pushnil(L); /* first key */
|
||||
while (lua_next(L, index-1) != 0) {
|
||||
/* stack now contains: -1 => nil; -2 => table */
|
||||
while (lua_next(L, -2) != 0) {
|
||||
zval key, val;
|
||||
|
||||
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
||||
|
||||
19
tests/issue040.phpt
Normal file
19
tests/issue040.phpt
Normal file
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
ISSUE #040 (segment 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
|
||||
(
|
||||
)
|
||||
Reference in New Issue
Block a user