From dcbcac42b762ee5f07197a75435684822bf00ef1 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Mon, 11 Nov 2013 11:33:27 +0400 Subject: A few bugfixes --- Lib/lua/luarun.swg | 48 +++++++++++++++++++++++++++++++++--------------- Source/Modules/lua.cxx | 42 +++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 632dbd512..9f669cae6 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -509,22 +509,22 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar { // first_arg - position of the object in stack. Everything that is above are arguments // and is passed to every evocation of the func - int last_argument = lua_gettop(L);// position of last argument + int last_arg = lua_gettop(L);// position of last argument lua_getmetatable(L,first_arg); - int original_metatable = last_argument + 1; + int original_metatable = last_arg + 1; int bases_count; SWIG_LUA_INIT_BASE_SEARCH(bases_count); - int result = SWIG_OK; + int result = SWIG_ERROR; ret = 0; if(bases_count>0) { int i; int j; - int subcall_start = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin + int subcall_first_arg = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin bool valid = true; - for(j=first_arg;j<=last_argument;j++) + for(j=first_arg;j<=last_arg;j++) lua_pushvalue(L,j); - int subcall_end = lua_gettop(L); + int subcall_last_arg = lua_gettop(L); swig_type_info *base_swig_type = 0; // Trick: temporaly replacing original metatable @@ -533,11 +533,12 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid); if(!valid) continue; + assert(lua_isuserdata(L, subcall_first_arg)); assert(lua_istable(L,-1)); - assert(lua_isuserdata(L, subcall_start)); - lua_setmetatable(L,subcall_start); // Set new metatable - result = func(L, base_swig_type,subcall_start, ret); // Forward call - assert(lua_gettop(L) == subcall_end + ret); // + lua_setmetatable(L,subcall_first_arg); // Set new metatable + assert(lua_gettop(L) == subcall_last_arg); + result = func(L, base_swig_type,subcall_first_arg, ret); // Forward call + assert(lua_gettop(L) == subcall_last_arg + ret); // TODO: REMOVE if(result != SWIG_ERROR) { break; } @@ -545,12 +546,16 @@ int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info* swig_type, int first_ar // Return original metatable back lua_pushvalue(L,original_metatable); lua_setmetatable(L,first_arg); - // Clear - remove everything between last_argument and subcall_end including - const int to_remove = subcall_end - last_argument - 1; + // Clear - remove everything between last_arg and subcall_last_arg including + const int to_remove = subcall_last_arg - last_arg; for(j=0;j