Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if test "$PHP_LUA" != "no"; then
LUA_LIB_DIR=$PHP_LUA/$PHP_LIBDIR
else
AC_MSG_CHECKING(for lua library in default path)
for i in /usr/$PHP_LIBDIR /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu; do
for i in /usr/$PHP_LIBDIR /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /usr/local/lib; do
if test -r $i/${LUA_LIB_NAME}.${SHLIB_SUFFIX_NAME} -o -r $i/${LUA_LIB_NAME}.a; then
LUA_LIB_DIR=$i
AC_MSG_RESULT(found in $i)
Expand Down
37 changes: 25 additions & 12 deletions lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ zend_object *php_lua_create_object(zend_class_entry *ce)
object_properties_init(&intern->obj, ce);

intern->obj.handlers = &lua_object_handlers;

return &intern->obj;
}
/* }}} */
Expand Down Expand Up @@ -265,11 +265,11 @@ static int php_lua_call_callback(lua_State *L) {
order = lua_tonumber(L, lua_upvalueindex(1));

callbacks = zend_read_static_property(lua_ce, ZEND_STRL("_callbacks"), 1);

if (ZVAL_IS_NULL(callbacks)) {
return 0;
}

func = zend_hash_index_find(Z_ARRVAL_P(callbacks), order);

if (!zend_is_callable(func, 0, NULL)) {
Expand All @@ -289,7 +289,7 @@ static int php_lua_call_callback(lua_State *L) {

for (i = 0; i<arg_num; i++) {
zval_ptr_dtor(&params[i]);

}
efree(params);
zval_ptr_dtor(&retval);
Expand All @@ -308,7 +308,15 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv
ZVAL_BOOL(rv, lua_toboolean(L, index));
break;
case LUA_TNUMBER:
ZVAL_DOUBLE(rv, lua_tonumber(L, index));
#if (LUA_VERSION_NUM < 503) /*{*/
ZVAL_DOUBLE(rv, lua_tonumber(L, index));
#else /*} {*/
if(lua_isinteger(L, index) == 1){
ZVAL_LONG(rv, lua_tointeger(L, index));
} else {
ZVAL_DOUBLE(rv, lua_tonumber(L, index));
}
#endif /*}*/
break;
case LUA_TSTRING:
{
Expand Down Expand Up @@ -337,8 +345,9 @@ zval *php_lua_get_zval_from_lua(lua_State *L, int index, zval *lua_obj, zval *rv

switch (Z_TYPE(key)) {
case IS_DOUBLE:
add_index_zval(rv, Z_DVAL(key), &val);
case IS_LONG:
add_index_zval(rv, Z_DVAL(key), &val);
add_index_zval(rv, Z_LVAL(key), &val);
break;
case IS_STRING:
add_assoc_zval(rv, Z_STRVAL(key), &val);
Expand Down Expand Up @@ -398,10 +407,14 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
lua_pushnil(L);
break;
case IS_DOUBLE:
lua_pushnumber(L, Z_DVAL_P(val));
if((long int) (Z_DVAL_P(val)) == Z_DVAL_P(val)) {
lua_pushinteger(L, Z_DVAL_P(val));
} else {
lua_pushnumber(L, Z_DVAL_P(val));
}
break;
case IS_LONG:
lua_pushnumber(L, Z_LVAL_P(val));
lua_pushinteger(L, Z_LVAL_P(val));
break;
case IS_STRING:
lua_pushlstring(L, Z_STRVAL_P(val), Z_STRLEN_P(val));
Expand All @@ -418,7 +431,7 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
array_init(callbacks);
}

lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
lua_pushinteger(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
lua_pushcclosure(L, php_lua_call_callback, 1);

zval_add_ref(val);
Expand Down Expand Up @@ -636,7 +649,7 @@ PHP_METHOD(lua, include) {
char *file;
size_t bp, len;
int ret;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &len) == FAILURE) {
return;
}
Expand Down Expand Up @@ -735,7 +748,7 @@ PHP_METHOD(lua, registerCallback) {
}

if (zend_is_callable(func, 0, NULL)) {
lua_pushnumber(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
lua_pushinteger(L, zend_hash_num_elements(Z_ARRVAL_P(callbacks)));
lua_pushcclosure(L, php_lua_call_callback, 1);
lua_setglobal(L, name);
} else {
Expand All @@ -761,7 +774,7 @@ PHP_METHOD(lua, getVersion) {
*/
PHP_METHOD(lua, __construct) {
lua_State * L = (Z_LUAVAL_P(getThis()))->L;

luaL_openlibs(L);
lua_register(L, "print", php_lua_print);
if (ZEND_NUM_ARGS()) {
Expand Down