- Timestamp:
- Apr 23, 2010, 11:46:11 AM (15 years ago)
- Location:
- code/branches/gamestates3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestates3/data/lua/Strict.lua
r6746 r6774 13 13 end 14 14 15 __STRICT = false15 __STRICT = true 16 16 mt.__declared = {} 17 17 18 18 mt.__newindex = function (t, n, v) 19 if __STRICT and not mt.__declared[n] then 20 local d = debug.getinfo(2, "S") 21 local w = d and d.what or "C" 22 if w ~= "main" and w ~= "C" then 23 error("assign to undeclared variable '"..n.."'", 2) 19 if not mt.__declared[n] then 20 if __STRICT then 21 local d = debug.getinfo(2, "S") 22 local w = d and d.what or "C" 23 if w ~= "main" and w ~= "C" then 24 error("Assigning to undeclared global variable '"..n.."'", 2) 25 end 24 26 end 25 27 mt.__declared[n] = true … … 29 31 30 32 mt.__index = function (t, n) 31 if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then 32 error("variable '"..n.."' is not declared", 2) 33 if not mt.__declared[n] then 34 local d = debug.getinfo(2, "S") 35 local w = d and d.what or "C" 36 if w ~= "C" then 37 error("Global variable '"..n.."' was not declared", 2) 38 else 39 mt.__declared[n] = true 40 end 33 41 end 34 42 return rawget(t, n) … … 36 44 37 45 function global(...) 38 for _, v in ipairs{...} do mt.__declared[v] = true end 46 for _, v in ipairs{...} do 47 mt.__declared[v] = true 48 end 39 49 end -
code/branches/gamestates3/src/libraries/core/LuaState.cc
r6763 r6774 53 53 DeclareToluaInterface(Core); 54 54 55 LuaState::LuaState( )55 LuaState::LuaState(bool bStrict) 56 56 : bIsRunning_(false) 57 57 , includeParseFunction_(NULL) … … 82 82 tolua_pushusertype(luaState_, static_cast<void*>(this), "orxonox::LuaState"); 83 83 lua_setglobal(luaState_, "luaState"); 84 85 // Strict.lua ensures that global variables are not declared inside a function scope 86 if (bStrict) 87 { 88 if (!this->doFile("Strict.lua")) 89 ThrowException(InitialisationFailed, "Running Strict.lua failed"); 90 } 91 else 92 { 93 // Add dummy function for declaring global variables 94 this->doString("global = function(...) end"); 95 } 84 96 85 97 // Parse init script -
code/branches/gamestates3/src/libraries/core/LuaState.h
r6763 r6774 68 68 { // tolua_export 69 69 public: 70 LuaState( );70 LuaState(bool bStrict = true); 71 71 ~LuaState(); 72 72 -
code/branches/gamestates3/src/orxonox/items/MultiStateEngine.cc
r6709 r6774 61 61 this->defEngineSndNormal_->setLooping(true); 62 62 this->defEngineSndBoost_->setLooping(true); 63 this->lua_ = new LuaState( );63 this->lua_ = new LuaState(false); 64 64 } 65 65 else
Note: See TracChangeset
for help on using the changeset viewer.