Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7653 was 7653, checked in by bensch, 19 years ago

orxonox/script_engine: namespace OrxScript introduced

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