Line | |
---|
1 | #ifndef __RESTORE_STACK_H__ |
---|
2 | #define __RESTORE_STACK_H__ |
---|
3 | |
---|
4 | #include "luaincl.h" |
---|
5 | |
---|
6 | //! Class to restore the stack to the way we found it. |
---|
7 | class LuaRestoreStack |
---|
8 | { |
---|
9 | public: |
---|
10 | /** |
---|
11 | * @brief Stores the stack and the index to the top element |
---|
12 | * |
---|
13 | * @param virtualMachine the virtual machine to save |
---|
14 | */ |
---|
15 | LuaRestoreStack (LuaVirtualMachine& virtualMachine) : savedState (NULL) |
---|
16 | { |
---|
17 | savedState = (lua_State *) virtualMachine; |
---|
18 | if (virtualMachine.isOk ()) |
---|
19 | { |
---|
20 | savedTopIndex = lua_gettop (savedState); |
---|
21 | } |
---|
22 | } |
---|
23 | /** |
---|
24 | * @brief Restores the virtual machine |
---|
25 | * |
---|
26 | * |
---|
27 | */ |
---|
28 | virtual ~LuaRestoreStack (void) |
---|
29 | { |
---|
30 | lua_settop (savedState, savedTopIndex); |
---|
31 | } |
---|
32 | |
---|
33 | protected: |
---|
34 | lua_State* savedState; |
---|
35 | int savedTopIndex; |
---|
36 | }; |
---|
37 | |
---|
38 | |
---|
39 | #endif // __RESTORE_STACK_H__ |
---|
Note: See
TracBrowser
for help on using the repository browser.