diff --git a/Release/lua_samp.dll b/Release/lua_samp.dll index 3b176e8..05a1641 100644 Binary files a/Release/lua_samp.dll and b/Release/lua_samp.dll differ diff --git a/lua_samp/CLuaFunctions.cpp b/lua_samp/CLuaFunctions.cpp index e3915f6..04bb9c6 100644 --- a/lua_samp/CLuaFunctions.cpp +++ b/lua_samp/CLuaFunctions.cpp @@ -132,35 +132,43 @@ LUA_FUNCTION call(lua_State *L) } } + //sampgdk::logprintf("PCall: %s - %d", functionName.c_str(), argn - 2); + //pass how many arguments we passed and calculate how many return value will we have and call the function int R = lua_pcall(lua_VM, (argn - 2), LUA_MULTRET, 0); //count return int nresults = (lua_gettop(lua_VM) - top); + //stackdump(lua_VM); + //stackdump(L); + if (nresults > 0) { - int stack_end = 3 + nresults; - ArgReader argR(lua_VM, 3); //return values start at index 3 + int stack_end = 1 + nresults; + ArgReader argR(lua_VM); //return values start at index 3 - for (int stack_index = 3; stack_index < stack_end; stack_index++) + for (int stack_index = 1; stack_index < stack_end; stack_index++) { if (argR.IsBool()) { bool tempBool; argR.ReadBool(tempBool); + //sampgdk::logprintf("B: %d", tempBool); lua_pushboolean(L, tempBool); } else if (argR.IsNumber()) { lua_Number tempNumber; argR.ReadLuaNumber(tempNumber); + //sampgdk::logprintf("N: %d", tempNumber); lua_pushnumber(L, tempNumber); } else if (argR.IsString()) { std::string tempString; argR.ReadString(tempString); + //sampgdk::logprintf("S: %s", tempString.c_str()); lua_pushstring(L, tempString.c_str()); } else if (argR.IsNil()) @@ -173,6 +181,9 @@ LUA_FUNCTION call(lua_State *L) } } + //clear the stack, because it can stack to hundreds and thousands of elements + lua_settop(lua_VM, 0); + //stackdump(lua_VM); //stackdump(L); } diff --git a/lua_samp/CLuaManager.cpp b/lua_samp/CLuaManager.cpp index 532ff0a..a69a667 100644 --- a/lua_samp/CLuaManager.cpp +++ b/lua_samp/CLuaManager.cpp @@ -89,8 +89,14 @@ void CLuaManager::RegisterPreScript(lua_State *L) "local callMT = {}\n" \ "function callMT : __index(k)\n" \ " k = tostring(k)\n" \ - " self[k] = function(resTable, ...)\n" \ - " return call(self.res, k, ...)\n" \ + " self[k] = function(a, ...)\n" \ + " if a == nil and #{...} == 0 then\n" \ + " return call(self.res, k)\n" \ + " elseif a == self then\n" \ + " return call(self.res, k, ...)\n" \ + " else\n" \ + " return call(self.res, k, a, ...)\n" \ + " end\n" \ " end\n" \ " return self[k]\n" \ "end\n" \ diff --git a/lua_samp/LuaMain.h b/lua_samp/LuaMain.h index d4bbdd0..fdd8694 100644 --- a/lua_samp/LuaMain.h +++ b/lua_samp/LuaMain.h @@ -9,7 +9,7 @@ #define PLUGIN_MAJOR "0" #define PLUGIN_MINOR "2" -#define PLUGIN_REVISION "2" -#define PLUGIN_VERSION "v0.2.2" +#define PLUGIN_REVISION "3" +#define PLUGIN_VERSION "v0.2.3" #endif \ No newline at end of file