xoreos  0.0.5
util.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_LUA_UTIL_H
26 #define AURORA_LUA_UTIL_H
27 
28 #include <cassert>
29 
30 #include "src/aurora/lua/types.h"
31 #include "src/aurora/lua/stack.h"
32 
33 namespace Aurora {
34 
35 namespace Lua {
36 
37 void *getRawCppObjectFromStack(const Stack& stack, int index);
38 void *getRawCppObjectFromVariable(const Variable& var);
39 
40 template<typename T>
41 T *getCppObjectFromStack(const Stack& stack, int index) {
42  return reinterpret_cast<T *>(getRawCppObjectFromStack(stack, index));
43 }
44 
45 template<typename T>
47  return reinterpret_cast<T *>(getRawCppObjectFromVariable(var));
48 }
49 
50 template<typename T>
52 public:
53  static int function(lua_State *state) {
54  assert(state);
55 
56  Stack stack(*state);
57  assert(stack.getSize() == 1);
58 
59  T* object = getCppObjectFromStack<T>(stack, 1);
60  delete object;
61 
62  return 0;
63  }
64 };
65 
66 } // End of namespace Lua
67 
68 } // End of namespace Aurora
69 
70 #define LUA_DEFAULT_DELETER(Type) ::Aurora::Lua::DefaultDeleter<Type>::function
71 
72 #endif // AURORA_LUA_UTIL_H
void * getRawCppObjectFromVariable(const Variable &var)
Definition: util.cpp:52
T * getCppObjectFromVariable(const Variable &var)
Definition: util.h:46
int getSize() const
Return the number of elements in the stack.
Definition: stack.cpp:48
A Lua stack wrapper.
Definition: stack.h:41
Lua types.
T * getCppObjectFromStack(const Stack &stack, int index)
Definition: util.h:41
void * getRawCppObjectFromStack(const Stack &stack, int index)
Definition: util.cpp:34
A Lua stack wrapper.