|
VR-Engage
2.2
|
The DtLuaStackCleaner class implements the RAII (Resource Acquisition Is Initialization) pattern for managing the Lua stack. It saves the current stack top on construction and restores it on destruction, ensuring the stack is properly cleaned up after operations that might modify it.
This is particularly useful for operations that push values onto the stack but need to ensure the stack returns to its original state, even in the presence of exceptions.
#include <luaStackCleaner.h>
Public Member Functions | |
| DtLuaStackCleaner (lua_State &vm) | |
| ~DtLuaStackCleaner () | |
Protected Attributes | |
| lua_State & | myState |
| int | myTop |
| makVre::DtLuaStackCleaner::DtLuaStackCleaner | ( | lua_State & | vm | ) |
Constructor.
Records the current top of the Lua stack to restore it later.
| vm | Reference to the Lua state |
| makVre::DtLuaStackCleaner::~DtLuaStackCleaner | ( | ) |
Destructor.
Restores the Lua stack to the position it was at when the cleaner was constructed
|
protected |
Reference to the Lua state being managed.
|
protected |
The original top position of the stack.