Changeset 19
- Timestamp:
- 01/10/2007 09:29:46 PM (5 years ago)
- Files:
-
- 11 edited
-
Plugins/luaScripting/Script.cpp (modified) (5 diffs)
-
Plugins/luaScripting/ScriptConnector.cpp (modified) (2 diffs)
-
Plugins/luaScripting/ScriptConnector.h (modified) (1 diff)
-
nrEngine/include/Event.h (modified) (2 diffs)
-
nrEngine/include/EventActor.h (modified) (2 diffs)
-
nrEngine/include/EventChannel.h (modified) (1 diff)
-
nrEngine/include/Result.h (modified) (1 diff)
-
nrEngine/include/nrEngine.h (modified) (1 diff)
-
nrEngine/nrEngine.h (modified) (1 diff)
-
nrEngine/src/EventActor.cpp (modified) (2 diffs)
-
nrEngine/src/EventChannel.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Plugins/luaScripting/Script.cpp
r18 r19 16 16 lua_State* LuaScript::State = NULL; 17 17 18 #if 018 #if 1 19 19 // Dump all the contents of your lua_state (Lua Stack) 20 20 // Find out the location of ur table and try to print out the details by … … 24 24 int i; 25 25 int top = lua_gettop(L); 26 printf("Stack has %d elements\n", top); 26 27 for (i = 1; i <= top; i++) { /* repeat for each level */ 27 28 int t = lua_type(L, i); … … 42 43 default: /* other values */ 43 44 printf("type: %s", lua_typename(L, t)); 44 break; 45 45 break; 46 46 } 47 47 printf("\n"); /* put a separator */ … … 131 131 { 132 132 pushErrorMessage(std::string("luaScript: The stack must be empty when calling a function!")); 133 stackDump(State); 133 134 return SCRIPT_ERROR; 134 135 } … … 166 167 { 167 168 pushErrorMessage(std::string("luaScript: The stack must be empty when calling a function!")); 169 stackDump(State); 168 170 return SCRIPT_ERROR; 169 171 } -
Plugins/luaScripting/ScriptConnector.cpp
r1 r19 22 22 { 23 23 initialize(); 24 initializeLuaEnvironment(); 24 25 } 25 26 27 //---------------------------------------------------------------------------------- 28 void LuaScriptConnector::initializeLuaEnvironment() 29 { 30 // add include function 31 lua_pushcfunction(LuaScript::State, includeFile); 32 lua_setglobal(LuaScript::State, "include"); 33 } 34 35 26 36 //---------------------------------------------------------------------------------- 27 37 void LuaScriptConnector::OnRegisterFunction(const std::string& name, const ScriptFunctor& func) … … 48 58 mRegistered.erase(std::find(mRegistered.begin(), mRegistered.end(), name)); 49 59 } 60 61 62 //---------------------------------------------------------------------------------- 63 int LuaScriptConnector::includeFile(lua_State *L) 64 { 65 int n=lua_gettop(L); 66 while (n) 67 { 68 // check if do not have anil value 69 if (!lua_isnil(L, -n)) 70 { 71 // do we got a string 72 if (lua_isstring(L, -n)) 73 { 74 // read string parameter 75 std::string filename = lua_tostring(L, -n); 76 77 // open filestream and load it 78 FileStream* fStream = new FileStream(); 79 Result ret = fStream->open(filename); 80 if (ret == OK) 81 { 82 // get the whole file content 83 std::string str = fStream->getAsString(); 84 85 // now let lua do the string 86 luaL_dostring(L, str.c_str()); 87 }else{ 88 printf("ScriptConnector: Cannot load luafile %s, no file found\n", filename.c_str()); 89 } 90 delete fStream; 91 }else{ 92 printf("ScriptConnector: Cannot include luafile. Filename(string) must be given. You gave me %s:%p\n",luaL_typename(L,-n),lua_topointer(L,-n)); 93 return 0; 94 } 95 } 96 --n; 97 } 98 99 // clear the stack 100 lua_pop(L, lua_gettop(L)); 101 102 return 0; 103 } 104 50 105 51 106 //---------------------------------------------------------------------------------- -
Plugins/luaScripting/ScriptConnector.h
r1 r19 60 60 std::list<std::string> mRegistered; 61 61 62 //! Include lua file (this function will be registered in lua) 63 static int includeFile(lua_State *L); 64 65 //! Initialize default functions, which are registered in the lua environemnt 66 void initializeLuaEnvironment(); 67 62 68 }; 63 69 -
nrEngine/include/Event.h
r1 r19 93 93 **/ 94 94 template<class T> 95 static T* event_cast(Event* base) throw (Exception)95 static T* event_cast(Event* base) 96 96 { 97 97 T* ptr = NULL; 98 try{ 99 ptr = dynamic_cast<T*>(base); 100 if (ptr == NULL) throw(Result(EVENT_COULD_NOT_CAST)); 101 102 }catch (Result i){ 103 NR_EXCEPT(i, 104 "Casting from Event* to given type is not possible", 105 "Event::event_shared_cast<T>()"); 106 } 98 ptr = dynamic_cast<T*>(base); 107 99 return ptr; 108 100 } … … 118 110 { 119 111 SharedPtr<T> ptr; 120 try 121 { 122 ptr = boost::dynamic_pointer_cast<T, Event>(base); 123 if (ptr == NULL) throw(Result(EVENT_COULD_NOT_CAST)); 124 125 }catch (Result i){ 126 NR_EXCEPT(i, 127 "Casting from Event* to given type is not possible", 128 "Event::event_shared_cast<T>()"); 129 } 112 ptr = boost::dynamic_pointer_cast<T, Event>(base); 130 113 return ptr; 131 114 } -
nrEngine/include/EventActor.h
r15 r19 42 42 public: 43 43 44 //! Create new actor without any name (@see setName() ) 45 EventActor(); 46 44 47 //! Create a new actor within unique name 45 48 EventActor(const std::string& name); … … 55 58 const std::string& getName() const; 56 59 60 /** 61 * Set name for this actor. You have to setup a name before you can 62 * connect the actor to any communication channel. 63 **/ 64 void setName(const std::string& name); 65 57 66 /** 58 67 * This is a function which will be called from the channel -
nrEngine/include/EventChannel.h
r1 r19 91 91 * Get the name of the channel 92 92 **/ 93 const std::string& getName (){ return mName; }93 NR_FORCEINLINE const std::string& getName () const { return mName; } 94 94 95 95 /** -
nrEngine/include/Result.h
r18 r19 326 326 EVENT_FACTORY_NOT_FOUND = EVENT_ERROR | (1 << 7), 327 327 328 //! Given actor is not valid 329 EVENT_NO_VALID_ACTOR = EVENT_ERROR | (1 << 8), 330 328 331 //------------------------------------------------------------------------------ 329 332 //! Generic group for properties errors -
nrEngine/include/nrEngine.h
r18 r19 44 44 #include "Event.h" 45 45 #include "EventActor.h" 46 #include "EventChannel.h" 46 47 47 48 #endif -
nrEngine/nrEngine.h
r18 r19 44 44 #include "include/Event.h" 45 45 #include "include/EventActor.h" 46 #include "include/EventChannel.h" 46 47 47 48 #endif -
nrEngine/src/EventActor.cpp
r15 r19 20 20 21 21 namespace nrEngine{ 22 22 23 //------------------------------------------------------------------------ 24 EventActor::EventActor() 25 { 26 27 } 28 23 29 //------------------------------------------------------------------------ 24 30 EventActor::EventActor(const std::string& name) : mName(name){ … … 36 42 } 37 43 44 //------------------------------------------------------------------------ 45 void EventActor::setName(const std::string& name) 46 { 47 mName = name; 48 } 49 50 38 51 //------------------------------------------------------------------------ 39 52 const std::string& EventActor::getName() const -
nrEngine/src/EventChannel.cpp
r1 r19 34 34 Result EventChannel::add(EventActor* actor, bool notice) 35 35 { 36 // check if actor has got a name 37 if (actor == NULL) return OK; 38 if (actor->getName().length() == 0) 39 { 40 NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, "EventChannel (%s): Want to connect nameless actor", getName().c_str()); 41 return EVENT_NO_VALID_ACTOR; 42 } 43 36 44 // we first check whenever the actor is already connected 37 45 if (isConnected(actor->getName())) return EVENT_ALREADY_CONNECTED; … … 52 60 Result EventChannel::del(EventActor* actor, bool notice) 53 61 { 62 if (actor == NULL) return OK; 63 54 64 // we first check whenever the actor is already connected 55 65 if (!isConnected(actor->getName())) return EVENT_NOT_CONNECTED;
Note: See TracChangeset
for help on using the changeset viewer.
