VR-Engage  2.2
Loading...
Searching...
No Matches
luaStackCleaner.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6#pragma once
7
8//! \file luaStackCleaner.h
9//! \brief Provides a RAII mechanism for automatically cleaning the Lua stack
10
11#include "vreUtil/export.h"
12
13struct lua_State;
14
15namespace makVre
16{
17//! \brief A utility class for automatically cleaning the Lua stack
18//!
19//! The DtLuaStackCleaner class implements the RAII (Resource Acquisition Is Initialization)
20//! pattern for managing the Lua stack. It saves the current stack top on construction
21//! and restores it on destruction, ensuring the stack is properly cleaned up
22//! after operations that might modify it.
23//!
24//! This is particularly useful for operations that push values onto the stack
25//! but need to ensure the stack returns to its original state, even in the
26//! presence of exceptions.
28{
29public:
30 //! \brief Constructor
31 //!
32 //! Records the current top of the Lua stack to restore it later.
33 //!
34 //! \param vm Reference to the Lua state
35 DtLuaStackCleaner(lua_State& vm);
36
37 //! \brief Destructor
38 //!
39 //! Restores the Lua stack to the position it was at when the cleaner was constructed
41
42protected:
43 //! \brief Reference to the Lua state being managed
44 lua_State& myState;
45
46 //! \brief The original top position of the stack
47 int myTop;
48};
49} // namespace makVre
DtLuaStackCleaner(lua_State &vm)
Constructor.
lua_State & myState
Reference to the Lua state being managed.
Definition luaStackCleaner.h:44
int myTop
The original top position of the stack.
Definition luaStackCleaner.h:47
~DtLuaStackCleaner()
Destructor.
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
Include export definitions for this library.
Definition glsVreMessageUtil.h:49