Changeset 11549 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/luatb.ipp
- Timestamp:
- Nov 6, 2017, 5:23:08 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/luatb.ipp
r11519 r11549 3 3 #include <iostream> 4 4 #include <type_traits> 5 #include "scriptable_controller_api.h"6 5 #include "luatb_typed_stack.h" 7 6 … … 20 19 { 21 20 // Store the 'this' pointer of the caller in the extraspace 22 // *static_cast<ThisType**>(lua_getextraspace(lua))= _this;21 LuaTB<ThisType, Ret (ThisType::*)(Args...)>::stateToClassMap[lua] = _this; 23 22 24 23 // Make a function visible to lua that will call 'func' with the correct … … 28 27 29 28 private: 29 static std::map<lua_State*, ThisType*> stateToClassMap; 30 30 31 // Represents a function that can made visible to lua with the correct 31 32 // signature. It will call the corresponding C++ function with the … … 34 35 static int toLuaSignature(lua_State *lua) 35 36 { 36 // The number of arguments is the first item on the stack37 int argc = lua_tointeger(lua, lua_gettop(lua));38 lua_pop(lua, 1);37 // The index of the topmost item on the stack equals the size of 38 // the stack, which also equals the number of arguments 39 int argc = lua_gettop(lua); 39 40 40 41 // Check if the number of arguments match 41 42 if(argc != sizeof...(Args)) 42 43 { 43 std::cerr << "ERROR: LuaTB: Lua script called a function with wrong number of arguments " << std::endl;44 std::cerr << "ERROR: LuaTB: Lua script called a function with wrong number of arguments (" << argc << " given, " << sizeof...(Args) << " expected)" << std::endl; 44 45 return LUA_ERRSYNTAX; 45 46 } 46 47 // Retrieve 'this' pointer of caller 48 // ThisType *_this = *static_cast<ThisType**>(lua_getextraspace(lua)); 49 ThisType *_this = orxonox::ScriptableControllerAPI::this_; 47 orxonox::orxout(orxonox::user_warning) << "what" << std::endl; 50 48 51 49 // Call getArgument for every argument seperately to convert each argument 52 50 // to the correct type and call the function afterwards 53 ((* _this).*func)( (LuaTBTypedStack::getArgument<Args>(lua))... );51 ((*LuaTB<ThisType, Ret (ThisType::*)(Args...)>::stateToClassMap[lua]).*func)( (LuaTBTypedStack::getArgument<Args>(lua))... ); 54 52 55 53 return 0; 56 54 } 57 55 }; 56 57 // This needs to be here and not in a source file, because the compiler can't know 58 // the template types if it's in a separate module. 59 template<typename ThisType, typename Ret, typename... Args> 60 std::map<lua_State*, ThisType*> LuaTB<ThisType, Ret (ThisType::*)(Args...)>::stateToClassMap = std::map<lua_State*, ThisType*>();
Note: See TracChangeset
for help on using the changeset viewer.