- Timestamp:
- Jun 14, 2006, 5:22:13 PM (18 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/lunar.h
r8399 r8403 21 21 22 22 23 static void Register(Script* script, const std::string& className, const ScriptMethod* scriptMethod )23 static void Register(Script* script, const std::string& className, const ScriptMethod* scriptMethods) 24 24 { 25 25 if(script != NULL) 26 Register(script->getLuaState(), className, scriptMethod );27 } 28 29 static void Register(lua_State *L, const std::string& className, const ScriptMethod* scriptMethod )26 Register(script->getLuaState(), className, scriptMethods); 27 } 28 29 static void Register(lua_State *L, const std::string& className, const ScriptMethod* scriptMethods) 30 30 { 31 31 Lunar<T>::className = className; 32 Lunar<T>::scriptMethods = scriptMethods; 32 33 lua_newtable(L); 33 34 int methods = lua_gettop(L); … … 62 63 63 64 // fill method table with methods from class T 65 /* as it was originally 64 66 for (RegType *l = T::methods; l->name; l++) 65 67 { … … 68 70 lua_pushcclosure(L, thunk, 1); 69 71 lua_settable(L, methods); 70 } 71 72 }*/ 73 for (unsigned int i = 0; i < Lunar<T>::scriptMethods->size(); i++) 74 { 75 lua_pushstring(L, Lunar<T>::scriptMethods->name(i).c_str()); 76 lua_pushlightuserdata(L, (void*)Lunar<T>::scriptMethods->executor(i)); 77 lua_pushcclosure(L, thunk, 1); 78 lua_settable(L, methods); 79 } 72 80 lua_pop(L, 2); // drop metatable and method table 73 81 } … … 176 184 lua_remove(L, 1); // remove self so member function args start at index 1 177 185 // get member function from upvalue 178 RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));186 Executor *l = static_cast<Executor*>(lua_touserdata(L, lua_upvalueindex(1))); 179 187 int value; 180 (*l ->mfunc)(obj, value, L); // call member function188 (*l)(obj, value, L); // call member function 181 189 return value; 182 190 } … … 268 276 private: 269 277 static std::string className; 278 static const ScriptMethod* scriptMethods; 270 279 }; 271 280 272 281 template <typename T> 273 282 std::string Lunar<T>::className = ""; 283 template <typename T> 284 const ScriptMethod* Lunar<T>::scriptMethods = NULL; 274 285 275 286 #endif /* _LUNAR_H */ -
branches/script_engine/src/lib/script_engine/script_method.h
r8401 r8403 20 20 ScriptMethod* addMethod(const std::string& methodName, const Executor& executor); 21 21 22 unsigned int size() const { return methods.size(); }; 23 22 24 const std::string& name(unsigned int methodNumber) const { return methods[methodNumber].name; }; 23 25 const Executor* executor(unsigned int methodNumber) const { return methods[methodNumber].executor; };
Note: See TracChangeset
for help on using the changeset viewer.