Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 23, 2010, 11:41:30 AM (15 years ago)
Author:
rgrieder
Message:

Eliminated all unnecessary global Lua variables and replaced them either with a local or a instance variable (P.myVar).

File:
1 edited

Legend:

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

    r6746 r6773  
    1 -- Note: luaState is a pointer to the LuaState instance that created this lua state
     1-- LuaStateInit.lua
     2
     3-- Note: 'luaState' is a pointer to the LuaState instance that created this lua state
    24
    35-- Redirect print to the C++ print function
    46original_print = print
    5 print = function(s)
     7function print(s)
    68  luaState:luaPrint(s)
    79end
    810
    911-- Create function to log text like COUT, but always prints a line!
    10 logMessage = function(level, message)
     12function logMessage(level, message)
    1113  luaState:luaLog(level, message)
    1214end
     
    1517-- Redirect dofile in order to load with the resource manager
    1618original_dofile = dofile
    17 dofile = function(filename)
     19function dofile(filename)
    1820  if not luaState:doFile(filename) then
    1921    error("Error propagation. Do not display")
     
    2628-- Create includeFile function that preparses the file according
    2729-- to a function provided to the LuaState constructor (in C++)
    28 include = function(filename)
     30function include(filename)
    2931  if not luaState:includeFile(filename) then
    3032    error("Error propagation. Do not display")
     
    3739-- The loaded modules are then stored with their names (where name has no .lua extension)
    3840-- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
     41_LOADED = {}
     42_LOADED_RETURN_VALUES = {}
     43_REQUIREDNAME = nil
    3944original_require = require
    40 _REQUIREDNAME = ""
    41 LuaStateReturnValue = true
    42 require = function(moduleName)
     45function require(moduleName)
    4346  if not luaState:fileExists(moduleName .. ".lua") then
    4447    logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ")
    4548    return nil
    46   end
    47 
    48   if not _LOADED then
    49     _LOADED = {}
    50   end
    51   if not _LOADED_RETURN_VALUES then
    52       _LOADED_RETURN_VALUES = {}
    5349  end
    5450
     
    6965    _REQUIREDNAME = _REQUIREDNAME_OLD
    7066  end
    71   local asdf = _LOADED_RETURN_VALUES[moduleName]
    72   return asdf
     67  return _LOADED_RETURN_VALUES[moduleName]
    7368end
    74 
    7569
    7670-- Load useful tool functions (like handleDefaultArgument)
    7771require("Tools")
    78 
    7972
    8073-- Include command line debugger for lua 5.1
     
    8477else
    8578  -- Fallback pause function
    86   pause = function()
     79  function pause()
    8780    logMessage(2, [["Warning: debug() called in Lua, but Debugger is not active.
    8881Do you have the IOConsole disabled and are you using Lua version 5.1?"]])
     
    9184
    9285-- General error handler that gets called whenever an error happens at runtime
    93 errorHandler = function(err)
     86function errorHandler(err)
    9487  if type(err) == "string" then
    9588    -- Simply return if the error has already been handled
     
    112105end
    113106
    114 
    115107-- Convenience function for console commands
    116108orxonox.execute = function(command)
Note: See TracChangeset for help on using the changeset viewer.