Skip to content

Commit

Permalink
v0.2.3
Browse files Browse the repository at this point in the history
- Fixed stack lake when using call.
- Fixed prescript when using "export" will not call function correctly
if no argument passed.
  • Loading branch information
drakeee committed Jul 18, 2015
1 parent eb63cd3 commit d796a71
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Binary file modified Release/lua_samp.dll
Binary file not shown.
17 changes: 14 additions & 3 deletions lua_samp/CLuaFunctions.cpp
Expand Up @@ -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())
Expand All @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions lua_samp/CLuaManager.cpp
Expand Up @@ -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" \
Expand Down
4 changes: 2 additions & 2 deletions lua_samp/LuaMain.h
Expand Up @@ -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

0 comments on commit d796a71

Please sign in to comment.