Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6670 for code


Ignore:
Timestamp:
Apr 1, 2010, 1:46:53 PM (15 years ago)
Author:
rgrieder
Message:

Lua errors in 'doFile', 'includeFile' or 'require' should not be caught in theses functions but rather at the beginning of the Lua call.

Location:
code/branches/gamestates2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates2/data/lua/LuaStateInit.lua

    r6665 r6670  
    1616original_dofile = dofile
    1717dofile = function(filename)
    18   luaState:doFile(filename)
     18  if not luaState:doFile(filename) then
     19    error("Error propagation. Do not display")
     20  end
    1921  -- Required because if the file returns a table, it cannot be passed through the C++ function
    2022  return LuaStateReturnValue -- C-injected global variable
     
    2527-- to a function provided to the LuaState constructor (in C++)
    2628include = function(filename)
    27   luaState:includeFile(filename)
     29  if not luaState:includeFile(filename) then
     30    error("Error propagation. Do not display")
     31  end
    2832  -- Required because if the file returns a table, it cannot be passed through the C++ function
    2933  return LuaStateReturnValue -- C-injected global variable
     
    5458    _REQUIREDNAME = moduleName
    5559
    56     luaState:doFile(moduleName .. ".lua")
     60    if not luaState:doFile(moduleName .. ".lua") then
     61      error("Error propagation. Do not display")
     62    end
    5763    -- LuaStateReturnValue is required because if the file returns a table,
    5864    -- it cannot be passed through the C++ function
     
    6672  return asdf
    6773end
     74
     75
     76-- Load useful tool functions (like handleDefaultArgument)
     77require("Tools")
    6878
    6979
     
    8292-- General error handler that gets called whenever an error happens at runtime
    8393errorHandler = function(err)
    84   -- Display the error message
    8594  if type(err) == "string" then
     95    -- Simply return if the error has already been handled
     96    if string.find(err, "Error propagation. Do not display") ~= nil then
     97      return err
     98    end
     99    -- Display the error message
    86100    logMessage(1, "Lua runtime error: "..err)
    87101  end
     
    92106  else
    93107    -- Fallback: print stack trace
    94     logMessage(1, debug.traceback(2))
     108    logMessage(3, debug.traceback(""))
    95109  end
    96110  return err -- Hello Lua debugger user! Please type 'set 2' to get to the
  • code/branches/gamestates2/src/libraries/core/LuaState.cc

    r6667 r6670  
    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); // Remove error message
    204203            break;
    205204        }
     
    213212            {
    214213            case LUA_ERRRUN: // Runtime error
    215                 // Remove error string from stack (we already display the error in the
     214                // Do nothing (we already display the error in the
    216215                // 'errorHandler' Lua function in LuaStateInit.lua)
    217216                break;
     
    223222                break;
    224223            }
    225             if (error != 0)
    226                 lua_pop(luaState_, 1); // Remove error message
    227224        }
    228225
    229226        if (error != 0)
     227        {
     228            lua_pop(luaState_, 1);  // Remove error message
    230229            lua_pushnil(luaState_); // Push a nil return value
     230        }
    231231
    232232        if (errorHandler != 0)
Note: See TracChangeset for help on using the changeset viewer.