From e22007c50f285e87c89ad459050990e44e5a19ed Mon Sep 17 00:00:00 2001 From: flysion Date: Wed, 24 Nov 2021 09:54:15 +0800 Subject: [PATCH] Integer support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在新版本的lua中已经可以区分integer和double了,这就可以解决扩展统一把lua的number类型转换成php的double的问题 ``` $lua->eval("a=2"); // old gettype($lua->a); // double // new gettype($lua->a); // integer ``` --- lua.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua.c b/lua.c index b05f4ef..3593982 100755 --- a/lua.c +++ b/lua.c @@ -300,6 +300,12 @@ static int php_lua_call_callback(lua_State *L) { /* }}} */ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv) /* {{{ */ { +#if (LUA_VERSION_NUM >= 503) + if (lua_isinteger(L, index)) { + ZVAL_LONG(rv, lua_tointeger(L, index)); + return rv; + } +#endif switch (lua_type(L, index)) { case LUA_TNIL: ZVAL_NULL(rv); @@ -340,9 +346,11 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv switch (Z_TYPE(key)) { case IS_DOUBLE: - case IS_LONG: add_index_zval(rv, Z_DVAL(key), &val); break; + case IS_LONG: + add_index_zval(rv, Z_LVAL(key), &val); + break; case IS_STRING: add_assoc_zval(rv, Z_STRVAL(key), &val); zval_ptr_dtor(&key);