[Orxonox-commit 1953] r6670 - in code/branches/gamestates2: data/lua src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Thu Apr 1 13:46:53 CEST 2010
Author: rgrieder
Date: 2010-04-01 13:46:53 +0200 (Thu, 01 Apr 2010)
New Revision: 6670
Modified:
code/branches/gamestates2/data/lua/LuaStateInit.lua
code/branches/gamestates2/src/libraries/core/LuaState.cc
Log:
Lua errors in 'doFile', 'includeFile' or 'require' should not be caught in theses functions but rather at the beginning of the Lua call.
Modified: code/branches/gamestates2/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/gamestates2/data/lua/LuaStateInit.lua 2010-04-01 08:21:35 UTC (rev 6669)
+++ code/branches/gamestates2/data/lua/LuaStateInit.lua 2010-04-01 11:46:53 UTC (rev 6670)
@@ -15,7 +15,9 @@
-- Redirect dofile in order to load with the resource manager
original_dofile = dofile
dofile = function(filename)
- luaState:doFile(filename)
+ if not luaState:doFile(filename) then
+ error("Error propagation. Do not display")
+ end
-- Required because if the file returns a table, it cannot be passed through the C++ function
return LuaStateReturnValue -- C-injected global variable
end
@@ -24,7 +26,9 @@
-- Create includeFile function that preparses the file according
-- to a function provided to the LuaState constructor (in C++)
include = function(filename)
- luaState:includeFile(filename)
+ if not luaState:includeFile(filename) then
+ error("Error propagation. Do not display")
+ end
-- Required because if the file returns a table, it cannot be passed through the C++ function
return LuaStateReturnValue -- C-injected global variable
end
@@ -53,7 +57,9 @@
local _REQUIREDNAME_OLD = _REQUIREDNAME
_REQUIREDNAME = moduleName
- luaState:doFile(moduleName .. ".lua")
+ if not luaState:doFile(moduleName .. ".lua") then
+ error("Error propagation. Do not display")
+ end
-- LuaStateReturnValue is required because if the file returns a table,
-- it cannot be passed through the C++ function
_LOADED_RETURN_VALUES[moduleName] = LuaStateReturnValue
@@ -67,6 +73,10 @@
end
+-- Load useful tool functions (like handleDefaultArgument)
+require("Tools")
+
+
-- Include command line debugger for lua 5.1
-- Note: It doesn't work if the IOConsole was started. Then we replace pause() with a warning
if _VERSION ~= "Lua 5.0" and not luaState:usingIOConsole() then
@@ -81,8 +91,12 @@
-- General error handler that gets called whenever an error happens at runtime
errorHandler = function(err)
- -- Display the error message
if type(err) == "string" then
+ -- Simply return if the error has already been handled
+ if string.find(err, "Error propagation. Do not display") ~= nil then
+ return err
+ end
+ -- Display the error message
logMessage(1, "Lua runtime error: "..err)
end
@@ -91,7 +105,7 @@
pause()
else
-- Fallback: print stack trace
- logMessage(1, debug.traceback(2))
+ logMessage(3, debug.traceback(""))
end
return err -- Hello Lua debugger user! Please type 'set 2' to get to the
-- actual position in the stack where the error occurred
Modified: code/branches/gamestates2/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestates2/src/libraries/core/LuaState.cc 2010-04-01 08:21:35 UTC (rev 6669)
+++ code/branches/gamestates2/src/libraries/core/LuaState.cc 2010-04-01 11:46:53 UTC (rev 6670)
@@ -200,7 +200,6 @@
break;
case LUA_ERRMEM: // Memory allocation error
COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
- lua_pop(luaState_, 1); // Remove error message
break;
}
@@ -212,7 +211,7 @@
switch (error)
{
case LUA_ERRRUN: // Runtime error
- // Remove error string from stack (we already display the error in the
+ // Do nothing (we already display the error in the
// 'errorHandler' Lua function in LuaStateInit.lua)
break;
case LUA_ERRERR: // Error in the error handler
@@ -222,12 +221,13 @@
COUT(1) << "Lua memory allocation error: Consult your dentist immediately!" << std::endl;
break;
}
- if (error != 0)
- lua_pop(luaState_, 1); // Remove error message
}
if (error != 0)
+ {
+ lua_pop(luaState_, 1); // Remove error message
lua_pushnil(luaState_); // Push a nil return value
+ }
if (errorHandler != 0)
lua_remove(luaState_, errorHandler); // Remove error handler from stack
More information about the Orxonox-commit
mailing list