Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6667


Ignore:
Timestamp:
Mar 31, 2010, 12:46:09 PM (15 years ago)
Author:
rgrieder
Message:

Found the darn bug!
The Lua error handling function may have been referenced with the wrong stack index in case LuaState::doString was called from a Lua function (using the tolua interface).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates2/src/libraries/core/LuaState.cc

    r6662 r6667  
    177177
    178178        // Push custom error handler that uses the debugger
    179         int errorHandler = 1;
    180179        lua_getglobal(this->luaState_, "errorHandler");
     180        int errorHandler = lua_gettop(luaState_);
    181181        if (lua_isnil(this->luaState_, -1))
    182182        {
     
    201201        case LUA_ERRMEM:    // Memory allocation error
    202202            COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
    203             lua_pop(luaState_, 1);
     203            lua_pop(luaState_, 1); // Remove error message
    204204            break;
    205205        }
     
    215215                // Remove error string from stack (we already display the error in the
    216216                // 'errorHandler' Lua function in LuaStateInit.lua)
    217                 lua_pop(luaState_, 1);
    218217                break;
    219218            case LUA_ERRERR: // Error in the error handler
    220                 COUT(1) << "Lua error in error handler: " << lua_tostring(luaState_, -1) << std::endl;
     219                COUT(1) << "Lua error in error handler. No message available." << std::endl;
    221220                break;
    222221            case LUA_ERRMEM: // Memory allocation error
    223222                COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
    224                 lua_pop(luaState_, 1);
    225223                break;
    226224            }
     225            if (error != 0)
     226                lua_pop(luaState_, 1); // Remove error message
    227227        }
    228228
    229229        if (error != 0)
    230         {
    231             // Push a nil return value
    232             lua_pushnil(luaState_);
    233         }
     230            lua_pushnil(luaState_); // Push a nil return value
     231
     232        if (errorHandler != 0)
     233            lua_remove(luaState_, errorHandler); // Remove error handler from stack
    234234
    235235        // Set return value to a global variable because we cannot return a table in this function
Note: See TracChangeset for help on using the changeset viewer.