Changeset 910
- Timestamp:
- 03/10/10 23:08:56 (5 months ago)
- Location:
- trunk/client/Game2
- Files:
-
- 5 modified
-
Console.cpp (modified) (8 diffs)
-
Console.h (modified) (3 diffs)
-
GameApp.cpp (modified) (1 diff)
-
HighConsole.cpp (modified) (1 diff)
-
HighConsole.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/Game2/Console.cpp
r903 r910 58 58 }; 59 59 60 Console::Console( ) :61 inputState(ISTATE_COMMAND)60 Console::Console(Script::Core *scripting) : 61 SUPER(scripting), inputState(ISTATE_COMMAND) 62 62 { 63 63 chunk.reserve(1024); 64 outHandle = scripting->AddOutput(boost::make_shared<LogStream>(this)); 64 65 } 65 66 66 67 Console::~Console() 67 68 { 68 Cleanup(); 69 delete scripting; 70 } 71 72 void Console::Init() 73 { 74 scripting = new Core(); 75 InitEnv(scripting); 76 InitGlobals(scripting); 77 } 78 79 /** 80 * Set intial settings on the scripting environment. 81 * @param scripting The environment to initialize (may not be @c NULL). 82 */ 83 void Console::InitEnv(Script::Core *scripting) 84 { 85 scripting->AddOutput(boost::make_shared<LogStream>(this)); 86 } 87 88 /** 89 * Populate the globals in the environment. 90 * @param scripting The environment to initialize (may not be @c NULL). 91 */ 92 void Console::InitGlobals(Script::Core *scripting) 93 { 94 lua_State *state = scripting->GetState(); 95 69 GetScripting()->RemoveOutput(outHandle); 70 } 71 72 void Console::InitEnv() 73 { 74 lua_State *state = GetScripting()->GetState(); 75 76 // Start with the standard global environment. 77 CopyGlobals(); 78 79 lua_pushlightuserdata(state, this); // table this 80 lua_pushcclosure(state, Console::LClear, 1); // table fn 81 lua_pushstring(state, "clear"); // table fn str 82 lua_insert(state, -2); // table str fn 83 lua_rawset(state, -3); // table 84 85 /* 96 86 lua_pushlightuserdata(state, this); 97 87 lua_pushcclosure(state, Console::LClear, 1); … … 99 89 100 90 lua_pushlightuserdata(state, this); 101 lua_pushcclosure(state, Console::LReinit, 1);102 lua_setglobal(state, "reinit");103 104 lua_pushlightuserdata(state, this);105 91 lua_pushcclosure(state, Console::LReset, 1); 106 92 lua_setglobal(state, "reset"); … … 109 95 lua_pushcclosure(state, Console::LSandbox, 1); 110 96 lua_setglobal(state, "sandbox"); 111 } 112 113 /** 114 * Clean up any resources invalidated during script execution. 115 * Note that this is not the same as invoking the garbage collector for the 116 * scripting environment; this is for console-specific resources which 117 * have been invalidated but could not be freed while the script was executing. 118 */ 119 void Console::Cleanup() 120 { 121 if (!oldScriptings.empty()) { 122 for (oldScriptings_t::iterator iter = oldScriptings.begin(); 123 iter != oldScriptings.end(); ++iter) 124 { 125 delete *iter; 126 } 127 oldScriptings.clear(); 128 } 97 */ 129 98 } 130 99 … … 138 107 139 108 try { 140 scripting->Execute(chunk);109 Execute(chunk); 141 110 } 142 111 catch (const IncompleteExn&) { … … 147 116 LogError(exn.GetMessage()); 148 117 } 149 150 Cleanup();151 118 152 119 chunk.clear(); … … 175 142 } 176 143 144 /* 177 145 int Console::LReset(lua_State *state) 178 146 { … … 185 153 self->LogInfo("Console script environment reset complete."); 186 154 return 0; 187 }188 189 int Console::LReinit(lua_State *state)190 {191 // function reinit()192 // Completely reinitialize the environment.193 // This is a last-resort call for fixing an environment that is very194 // messed up. reset() does not need to be called afterwards; this function195 // is a superset of what reset() does.196 Console *self = static_cast<Console*>(lua_touserdata(state, lua_upvalueindex(1)));197 198 // Save the current environment to be cleaned up later (in Clean()).199 // We can't destroy it just yet -- we were called from it!200 self->oldScriptings.push_back(self->scripting);201 202 self->Init();203 204 // Cause an error in order to terminate execution in the current environment205 // immediately.206 lua_pushstring(state, "Console script environment reinitialization complete.");207 return lua_error(state);208 155 } 209 156 … … 221 168 return 0; 222 169 } 170 */ 223 171 224 172 // Console::LogStreamBuf -
trunk/client/Game2/Console.h
r903 r910 25 25 #include <lua.hpp> 26 26 27 #include "../../engine/Script/Core.h" 28 #include "../../engine/Script/Env.h" 27 29 #include "../../engine/Util/OS.h" 28 29 namespace HoverRace {30 namespace Script {31 class Core;32 }33 }34 30 35 31 namespace HoverRace { … … 40 36 * @author Michael Imamura 41 37 */ 42 class Console 38 class Console : public Script::Env 43 39 { 40 typedef Script::Env SUPER; 41 44 42 public: 45 Console( );43 Console(Script::Core *scripting); 46 44 virtual ~Console(); 47 45 48 public:49 void Init();50 46 protected: 51 Script::Core *GetScripting() const { return scripting; } 52 virtual void InitEnv(Script::Core *scripting); 53 virtual void InitGlobals(Script::Core *scripting); 54 55 virtual void Cleanup(); 47 virtual void InitEnv(); 56 48 57 49 public: … … 76 68 private: 77 69 static int LClear(lua_State *state); 70 /* 78 71 static int LReset(lua_State *state); 79 static int LReinit(lua_State *state);80 72 static int LSandbox(lua_State *state); 73 */ 81 74 82 75 private: 83 Script::Core *scripting; 84 typedef std::list<Script::Core*> oldScriptings_t; 85 oldScriptings_t oldScriptings; 76 inputState_t inputState; 77 Script::Core::OutHandle outHandle; 86 78 std::string chunk; 87 inputState_t inputState;88 79 89 80 class LogStreamBuf; -
trunk/client/Game2/GameApp.cpp
r904 r910 1561 1561 highObserver = new HighObserver(); 1562 1562 if (Config::GetInstance()->runtime.enableConsole) { 1563 highConsole = new HighConsole(); 1564 highConsole->Init(); 1563 highConsole = new HighConsole(scripting); 1565 1564 } 1566 1565 -
trunk/client/Game2/HighConsole.cpp
r896 r910 76 76 }; 77 77 78 HighConsole::HighConsole( ) :79 SUPER( ), visible(false), cursorOn(true), cursorTick(0)78 HighConsole::HighConsole(Script::Core *scripting) : 79 SUPER(scripting), visible(false), cursorOn(true), cursorTick(0) 80 80 { 81 81 vp = new MR_2DViewPort(); -
trunk/client/Game2/HighConsole.h
r896 r910 46 46 typedef Console SUPER; 47 47 public: 48 HighConsole( );48 HighConsole(Script::Core *scripting); 49 49 virtual ~HighConsole(); 50 50
