Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/lib/script_engine/RestoreStack.h @ 7645

Last change on this file since 7645 was 7645, checked in by bensch, 18 years ago

added script_engine

File size: 788 bytes
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.
7class LuaRestoreStack
8{
9public:
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
33protected:
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.