Permalink
Browse files

- Fix definitivly clear lua environment precedent problem (precedent …

…commit fix was wrong)
  • Loading branch information...
1 parent 9d1db21 commit 4ef5022e0dca3a2ff1d2fd64019b9b440f87fde5 @MathieuPOUX MathieuPOUX committed Nov 15, 2013
Showing with 12 additions and 10 deletions.
  1. +6 −2 CumulusServer/sources/Script.cpp
  2. +6 −8 CumulusServer/sources/Service.cpp
View
8 CumulusServer/sources/Script.cpp
@@ -35,9 +35,13 @@ using namespace Cumulus;
lua_Debug Script::LuaDebug;
const char* Script::LastError(lua_State *pState) {
+ int top = lua_gettop(pState);
+ if(top==0)
+ return "Unknown error";
const char* error = lua_tostring(pState,-1);
- if(error)
- lua_pop(pState,1);
+ lua_pop(pState,1);
+ if(!error)
+ return "Unknown error";
return error;
}
View
14 CumulusServer/sources/Service.cpp
@@ -380,10 +380,9 @@ void Service::load() {
while (lua_next(_pState, -2) != 0) {
// uses 'key' (at index -2) and 'value' (at index -1)
// remove the raw!
- if(lua_istable(_pState,-1)) {
- lua_pushnil(_pState);
- lua_setfield(_pState,-4,lua_tostring(_pState,-3));
- }
+ lua_pushvalue(_pState,-2); // duplicate key
+ lua_pushnil(_pState);
+ lua_rawset(_pState,-5);
lua_pop(_pState,1);
}
}
@@ -435,10 +434,9 @@ void Service::clear() {
while (lua_next(_pState, -2) != 0) {
// uses 'key' (at index -2) and 'value' (at index -1)
// remove the raw!
- if(lua_istable(_pState,-1)) {
- lua_pushnil(_pState);
- lua_setfield(_pState,-4,lua_tostring(_pState,-3));
- }
+ lua_pushvalue(_pState,-2); // duplicate key
+ lua_pushnil(_pState);
+ lua_rawset(_pState,-5);
lua_pop(_pState,1);
}
}

0 comments on commit 4ef5022

Please sign in to comment.