1 | /*! |
---|
2 | * @file executor_generic.h |
---|
3 | * Definition of a Generic Executor |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | orxonox - the future of 3D-vertical-scrollers |
---|
8 | |
---|
9 | Copyright (C) 2004 orx |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify |
---|
12 | it under the terms of the GNU General Public License as published by |
---|
13 | the Free Software Foundation; either version 2, or (at your option) |
---|
14 | any later version. |
---|
15 | |
---|
16 | ### File Specific: |
---|
17 | main-programmer: Benjamin Grauer |
---|
18 | co-programmer: ... |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | #ifndef __EXECUTOR_LUA_STATE_H_ |
---|
24 | #define __EXECUTOR_LUA_STATE_H_ |
---|
25 | |
---|
26 | |
---|
27 | #include "executor_generic.h" |
---|
28 | #include "luaincl.h" |
---|
29 | #ifdef FUNCTOR_CALL_TYPE |
---|
30 | #undef FUNCTOR_CALL_TYPE |
---|
31 | #endif |
---|
32 | #define FUNCTOR_CALL_TYPE lua_State* |
---|
33 | |
---|
34 | |
---|
35 | template<typename type> type fromLua(lua_State* state, int index); |
---|
36 | template<> bool fromLua<bool>(lua_State* state, int index); |
---|
37 | template<> int fromLua<int>(lua_State* state, int index); |
---|
38 | template<> unsigned int fromLua<unsigned int>(lua_State* state, int index); |
---|
39 | template<> float fromLua<float>(lua_State* state, int index); |
---|
40 | template<> char fromLua<char>(lua_State* state, int index); |
---|
41 | template<> const std::string& fromLua<const std::string&>(lua_State* state, int index); |
---|
42 | |
---|
43 | template<typename type> void toLua(lua_State* state, type value); |
---|
44 | template<> void toLua<bool>(lua_State* state, bool value); |
---|
45 | template<> void toLua<int>(lua_State* state, int value); |
---|
46 | template<> void toLua<unsigned int>(lua_State* state, unsigned int value); |
---|
47 | template<> void toLua<float>(lua_State* state, float value); |
---|
48 | template<> void toLua<char>(lua_State* state, char value); |
---|
49 | template<> void toLua<const std::string&>(lua_State* state, const std::string& value); |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief to remove writing errors, this function is Used. |
---|
53 | * @param sub The SubString to use |
---|
54 | * @param default The default Values. |
---|
55 | */ |
---|
56 | template<> class ExecutorEvaluater <lua_State*> |
---|
57 | { |
---|
58 | public: |
---|
59 | /** @brief Executes the Evaluater |
---|
60 | * @param CallValue the Value that should be converted |
---|
61 | * @param defaults the default Values. |
---|
62 | */ |
---|
63 | template <typename ToType, int index> |
---|
64 | ToType operator()(lua_State*& CallValue, const MultiType* const defaults) |
---|
65 | { |
---|
66 | return (fromLua<ToType>(CallValue, index)); |
---|
67 | } |
---|
68 | template <typename ToType> |
---|
69 | void storeRet(lua_State*& state, ToType value) |
---|
70 | { |
---|
71 | toLua<ToType>(state, value); |
---|
72 | } |
---|
73 | static lua_State*& defaultValue() { static lua_State* nullState; return nullState; }; |
---|
74 | }; |
---|
75 | |
---|
76 | #endif /* __EXECUTOR_LUA_STATE_H_ */ |
---|