mirror of
https://github.com/php-win-ext/php-lua.git
synced 2026-03-25 17:42:09 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6c5162a7c | ||
|
|
0875f92328 | ||
|
|
445e886030 | ||
|
|
5c405f9746 | ||
|
|
9b25ea36a5 | ||
|
|
5b6ac82491 | ||
|
|
5663931ce7 | ||
|
|
a5a8995b2e | ||
|
|
ffae3062a4 | ||
|
|
13e26a383a | ||
|
|
ef70d19a33 | ||
|
|
d763f167d8 | ||
|
|
24fd1baf19 | ||
|
|
a780d5623d | ||
|
|
0d73a2fdaa | ||
|
|
aa1dd4f526 | ||
|
|
199a846d7a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
.*.swp
|
||||
|
||||
@@ -7,6 +7,10 @@ addons:
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
45
lua.c
45
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);
|
||||
|
||||
@@ -425,7 +424,7 @@ try_again:
|
||||
add_next_index_zval(callbacks, val);
|
||||
} else {
|
||||
zval *v;
|
||||
ulong longkey;
|
||||
zend_ulong longkey;
|
||||
zend_string *key;
|
||||
zval zkey;
|
||||
|
||||
@@ -458,13 +457,31 @@ try_again:
|
||||
lua_newtable(L);
|
||||
|
||||
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, longkey, key, v) {
|
||||
zend_bool key_pushed = 0;
|
||||
|
||||
if (key) {
|
||||
ZVAL_STR(&zkey, key);
|
||||
if (Z_TYPE_P(val) == IS_OBJECT && ZSTR_VAL(key)[0] == 0) {
|
||||
/* This is object property and it's name should be demangled*/
|
||||
const char *prop_name, *class_name;
|
||||
size_t prop_len;
|
||||
|
||||
zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
|
||||
|
||||
lua_pushlstring(L, prop_name, prop_len);
|
||||
key_pushed = 1;
|
||||
} else {
|
||||
ZVAL_STR(&zkey, key);
|
||||
}
|
||||
} else {
|
||||
ZVAL_LONG(&zkey, longkey);
|
||||
}
|
||||
php_lua_send_zval_to_lua(L, &zkey);
|
||||
|
||||
if (!key_pushed) {
|
||||
php_lua_send_zval_to_lua(L, &zkey);
|
||||
}
|
||||
|
||||
php_lua_send_zval_to_lua(L, v);
|
||||
|
||||
lua_settable(L, -3);
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
25
package.xml
25
package.xml
@@ -23,11 +23,11 @@
|
||||
<email>msaraujo@php.net</email>
|
||||
<active>yes</active>
|
||||
</developer>
|
||||
<date>2018-12-21</date>
|
||||
<date>2020-03-10</date>
|
||||
<time>11:10:00</time>
|
||||
<version>
|
||||
<release>2.0.6</release>
|
||||
<api>2.0.6</api>
|
||||
<release>2.0.7</release>
|
||||
<api>2.0.7</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
@@ -35,7 +35,7 @@
|
||||
</stability>
|
||||
<license uri="http://www.php.net/license">PHP</license>
|
||||
<notes>
|
||||
- Fixed Hash Recursive Detecting in PHP-7.3
|
||||
- Fixed windows build for 7.4
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
@@ -83,6 +83,21 @@
|
||||
<extsrcrelease />
|
||||
<changelog>
|
||||
<release>
|
||||
<date>2020-03-10</date>
|
||||
<version>
|
||||
<release>2.0.7</release>
|
||||
<api>2.0.7</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://www.php.net/license">PHP License</license>
|
||||
<notes>
|
||||
- Fixed windows build for 7.4
|
||||
</notes>
|
||||
</release>
|
||||
|
||||
<date>2018-12-21</date>
|
||||
<version>
|
||||
<release>2.0.6</release>
|
||||
@@ -96,8 +111,6 @@
|
||||
<notes>
|
||||
- Fixed Hash Recursive Detecting in PHP-7.3
|
||||
</notes>
|
||||
</release>
|
||||
|
||||
<release>
|
||||
<date>2017-12-31</date>
|
||||
<version>
|
||||
|
||||
@@ -48,7 +48,7 @@ extern zend_module_entry lua_module_entry;
|
||||
#define LUA_G(v) (lua_globals.v)
|
||||
#endif
|
||||
|
||||
#define PHP_LUA_VERSION "2.0.6"
|
||||
#define PHP_LUA_VERSION "2.0.8-dev"
|
||||
|
||||
struct _php_lua_object {
|
||||
lua_State *L;
|
||||
|
||||
45
tests/016.phpt
Normal file
45
tests/016.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
PHP Object to lua
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("lua")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
class T {
|
||||
private $v;
|
||||
private $s;
|
||||
|
||||
public function __construct($v)
|
||||
{
|
||||
$this->v = $v;
|
||||
$this->s = "string = $v";
|
||||
}
|
||||
|
||||
static function create($arg)
|
||||
{
|
||||
return new self($arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$l = new lua();
|
||||
$l->registerCallback('create_object', [T::class, 'create']);
|
||||
|
||||
$l->eval(<<<CODE
|
||||
local t = create_object(2)
|
||||
|
||||
local keys = {}
|
||||
|
||||
for k, _ in pairs(t) do
|
||||
table.insert(keys, k)
|
||||
end
|
||||
|
||||
table.sort(keys)
|
||||
for _,k in ipairs(keys) do
|
||||
print(k, " -> ", t[k], ",")
|
||||
end
|
||||
CODE
|
||||
);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
s -> string = 2,v -> 2,
|
||||
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