diff --git a/.travis.yml b/.travis.yml index 02aa33a..5b7ef76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,10 @@ addons: php: - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 notifications: email: false diff --git a/lua.c b/lua.c index 13bc284..de652e9 100755 --- a/lua.c +++ b/lua.c @@ -36,7 +36,13 @@ static zend_object_handlers lua_object_handlers; /** {{{ ARG_INFO * */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_call, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_call, 0, 0, 1) + ZEND_ARG_INFO(0, method) + ZEND_ARG_INFO(0, args) + ZEND_ARG_INFO(0, use_self) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua___call, 0, 0, 2) ZEND_ARG_INFO(0, method) ZEND_ARG_INFO(0, args) ZEND_END_ARG_INFO() @@ -64,9 +70,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_eval, 0, 0, 1) ZEND_ARG_INFO(0, statements) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_free, 0, 0, 1) - ZEND_ARG_INFO(0, closure) +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_getVersion, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_getVersionInt, 0, 0, 0) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua___construct, 0, 0, 0) +ZEND_END_ARG_INFO() + /* }}} */ /* {{{ lua_module_entry @@ -217,46 +229,46 @@ zend_object *php_lua_create_object(zend_class_entry *ce) /** {{{ static zval * php_lua_read_property(zval *object, zval *member, int type) */ -zval *php_lua_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv){ - lua_State *L = (Z_LUAVAL_P(object))->L; - zend_string *str_member; +zval *php_lua_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv){ + lua_State *L = php_lua_obj_from_obj(object)->L; if (type != BP_VAR_R) { ZVAL_NULL(rv); return rv; } - str_member = zval_get_string(member); #if (LUA_VERSION_NUM < 502) - lua_getfield(L, LUA_GLOBALSINDEX, ZSTR_VAL(str_member)); + lua_getfield(L, LUA_GLOBALSINDEX, ZSTR_VAL(member)); #else - lua_getglobal(L, ZSTR_VAL(str_member)); + lua_getglobal(L, ZSTR_VAL(member)); #endif - zend_string_release(str_member); - php_lua_get_zval_from_lua(L, -1, object, rv); + zval lua_zval_object; + ZVAL_OBJ(&lua_zval_object, object); + + php_lua_get_zval_from_lua(L, -1, &lua_zval_object, rv); lua_pop(L, 1); + return rv; } /* }}} */ /** {{{ static void php_lua_write_property(zval *object, zval *member, zval *value) */ -static void php_lua_write_property(zval *object, zval *member, zval *value, void ** key) { - lua_State *L = (Z_LUAVAL_P(object))->L; - zend_string *str_member = zval_get_string(member); +static zval* php_lua_write_property(zend_object *object, zend_string *member, zval *value, void ** key) { + lua_State *L = php_lua_obj_from_obj(object)->L; #if (LUA_VERSION_NUM < 502) - php_lua_send_zval_to_lua(L, member); + lua_pushlstring(L, ZSTR_VAL(val), ZSTR_LEN(val)); php_lua_send_zval_to_lua(L, value); lua_settable(L, LUA_GLOBALSINDEX); #else php_lua_send_zval_to_lua(L, value); - lua_setglobal(L, Z_STRVAL_P(member)); + lua_setglobal(L, ZSTR_VAL(member)); #endif - zend_string_release(str_member); + return value; } /* }}} */ @@ -305,7 +317,7 @@ static int php_lua_call_callback(lua_State *L) { // and pass it to PHP if Lua didn't handle this error. Let's try with the ideal approach somewhere later zend_clear_exception(); - zend_call_method_with_0_params(&exception, Z_OBJCE_P(&exception), NULL, "getmessage", &tmp); + zend_call_method_with_0_params(Z_OBJ_P(&exception), Z_OBJCE_P(&exception), NULL, "getmessage", &tmp); if (Z_TYPE(tmp) != IS_STRING) { zend_error(E_WARNING, "%s::getMessage() must return a string", ZSTR_VAL(Z_OBJCE_P(&exception)->name)); lua_pushfstring(L, "Exception of type %s has been thrown in PHP", ZSTR_VAL(Z_OBJCE_P(&exception)->name)); @@ -481,7 +493,7 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ { add_next_index_zval(callbacks, val); } else { zval *v; - ulong longkey; + zend_ulong longkey; zend_string *key; zval zkey; @@ -815,6 +827,23 @@ PHP_METHOD(lua, call) { } /* }}} */ +/** {{{ proto Lua::__call(mixed $function, array $args) +*/ +PHP_METHOD(lua, __call) { + long u_self = 0; + zval *func; + zval *args = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "za", &func, &args) == FAILURE) { + return; + } + + if (!(php_lua_call_lua_function(getThis(), func, args, 0, return_value))) { + RETURN_FALSE; + } +} +/* }}} */ + /** {{{ proto Lua::assign(string $name, mix $value) */ PHP_METHOD(lua, assign) { @@ -907,16 +936,16 @@ PHP_METHOD(lua, __construct) { * */ zend_function_entry lua_class_methods[] = { - PHP_ME(lua, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(lua, __construct, arginfo_lua___construct,ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(lua, eval, arginfo_lua_eval, ZEND_ACC_PUBLIC) PHP_ME(lua, include, arginfo_lua_include, ZEND_ACC_PUBLIC) PHP_ME(lua, loadstring, arginfo_lua_loadstring, ZEND_ACC_PUBLIC) PHP_ME(lua, call, arginfo_lua_call, ZEND_ACC_PUBLIC) + PHP_ME(lua, __call, arginfo_lua___call, ZEND_ACC_PUBLIC) PHP_ME(lua, assign, arginfo_lua_assign, ZEND_ACC_PUBLIC) - PHP_ME(lua, getVersion, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC) - PHP_ME(lua, getVersionInt, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC|ZEND_ACC_STATIC) + PHP_ME(lua, getVersion, arginfo_lua_getVersion, ZEND_ACC_PUBLIC) + PHP_ME(lua, getVersionInt, arginfo_lua_getVersionInt, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(lua, registerCallback, arginfo_lua_register, ZEND_ACC_PUBLIC) - PHP_MALIAS(lua, __call, call, arginfo_lua_call, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */ diff --git a/lua_closure.c b/lua_closure.c index 50ef039..6b385bf 100644 --- a/lua_closure.c +++ b/lua_closure.c @@ -39,10 +39,13 @@ static zend_object_handlers lua_closure_handlers; /** {{{ ARG_INFO * */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_invoke, 0, 0, 1) - ZEND_ARG_INFO(0, arg) - ZEND_ARG_INFO(0, ...) +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_invoke, 0, 0, 0) + ZEND_ARG_VARIADIC_INFO(0, arg) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_lua_closure___construct, 0, 0, 0) +ZEND_END_ARG_INFO() + /* }}} */ /** {{{ zval * php_lua_closure_instance(zval *instance, long ref_id, zval *lua_obj) @@ -145,7 +148,7 @@ PHP_METHOD(lua_closure, invoke) { /* {{{ lua_class_methods[] */ zend_function_entry lua_closure_methods[] = { - PHP_ME(lua_closure, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) + PHP_ME(lua_closure, __construct, arginfo_lua_closure___construct, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(lua_closure, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC) PHP_MALIAS(lua_closure, __invoke, invoke, arginfo_lua_invoke, ZEND_ACC_PUBLIC) PHP_FE_END diff --git a/package.xml b/package.xml index 1a968e3..884d582 100644 --- a/package.xml +++ b/package.xml @@ -23,11 +23,11 @@ msaraujo@php.net yes - 2018-12-21 + 2020-03-10 - 2.0.6 - 2.0.6 + 2.0.7 + 2.0.7 stable @@ -35,7 +35,7 @@ PHP - - Fixed Hash Recursive Detecting in PHP-7.3 + - Fixed windows build for 7.4 @@ -83,6 +83,21 @@ + 2020-03-10 + + 2.0.7 + 2.0.7 + + + stable + stable + + PHP License + + - Fixed windows build for 7.4 + + + 2018-12-21 2.0.6 @@ -96,8 +111,6 @@ - Fixed Hash Recursive Detecting in PHP-7.3 - - 2017-12-31 diff --git a/php_lua.h b/php_lua.h index 40b7a09..5b1cd2b 100644 --- a/php_lua.h +++ b/php_lua.h @@ -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; diff --git a/tests/003.phpt b/tests/003.phpt index af50e46..cc5e68c 100644 --- a/tests/003.phpt +++ b/tests/003.phpt @@ -42,8 +42,8 @@ var_dump($l->call(array("math", "cos"), array(pi()))); echo "\n"; try { -$l->notexisting(2423); -$l->call(array("math", "sin", "function"), array(432, 342)); + $l->notexisting(2423); + $l->call(array("math", "sin", "function"), array(432, 342)); } catch (LuaException $e) { echo $e->getMessage(); @@ -58,8 +58,15 @@ echo "\n"; var_dump($l->__call("multiret", array())); -$l->__call("print"); +echo "\nusing Lua->__call(print)\n"; +$l->__call("print", []); $l->__call("print", array("foo")); + +echo "\nusing Lua->print()\n"; + +$l->print(); // same as $l->__call("print", []); +$l->print("foo\n"); // same as $l->__call("print", array("foo")); + ?> --EXPECTF-- Hello world! @@ -92,4 +99,8 @@ array(3) { [2]=> string(1) "c" } + +using Lua->__call(print) foo +using Lua->print() +foo \ No newline at end of file diff --git a/tests/013.phpt b/tests/013.phpt index 5da0ed4..4f6a2ac 100644 --- a/tests/013.phpt +++ b/tests/013.phpt @@ -6,9 +6,9 @@ PHP Closures from Lua eval(<<eval(<<<'CODE' function test(cb1) - local cb2 = cb1("called from lua") + local cb2 = cb1("called from lua\n") cb2("returned from php") end CODE @@ -27,4 +27,5 @@ try { } ?> --EXPECTF-- -called from luareturned from php +called from lua +returned from php