diff --git a/lua.c b/lua.c index 0a75b7f..7429b8b 100755 --- a/lua.c +++ b/lua.c @@ -457,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(); diff --git a/tests/016.phpt b/tests/016.phpt new file mode 100644 index 0000000..0f094e5 --- /dev/null +++ b/tests/016.phpt @@ -0,0 +1,45 @@ +--TEST-- +PHP Object to lua +--SKIPIF-- + +--FILE-- +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(<< ", t[k], ",") +end +CODE +); + +?> +--EXPECTF-- +s -> string = 2,v -> 2, \ No newline at end of file