summaryrefslogtreecommitdiffstats
path: root/source/LuaState.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-06 08:01:00 +0200
committermadmaxoft <github@xoft.cz>2013-08-06 08:01:00 +0200
commit2151bb8f5bad91975010ab1022177fdb94cc2a3e (patch)
tree897b195dad7deae2726b55491f68522d428548ac /source/LuaState.h
parentMerge branch 'master' into BlockTracing (diff)
downloadcuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar.gz
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar.bz2
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar.lz
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar.xz
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.tar.zst
cuberite-2151bb8f5bad91975010ab1022177fdb94cc2a3e.zip
Diffstat (limited to '')
-rw-r--r--source/LuaState.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/source/LuaState.h b/source/LuaState.h
index 10ff53911..fca532d89 100644
--- a/source/LuaState.h
+++ b/source/LuaState.h
@@ -3,6 +3,12 @@
// Declares the cLuaState class representing the wrapper over lua_State *, provides associated helper functions
+/*
+The contained lua_State can be either owned or attached.
+Owned lua_State is created by calling Create() and the cLuaState automatically closes the state
+Or, lua_State can be attached by calling Attach(), the cLuaState doesn't close such a state
+Attaching a state will automatically close an owned state.
+*/
@@ -29,16 +35,28 @@ public:
*/
cLuaState(const AString & a_SubsystemName);
+ /** Creates a new instance. The a_AttachState is attached.
+ Subsystem name is set to "<attached>".
+ */
+ explicit cLuaState(lua_State * a_AttachState);
+
~cLuaState();
+ /// Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions
operator lua_State * (void) { return m_LuaState; }
- /// Creates the m_LuaState, if not closed already
+ /// Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor
void Create(void);
/// Closes the m_LuaState, if not closed already
void Close(void);
+ /// Attaches the specified state. Operations will be carried out on this state, but it will not be closed in the destructor
+ void Attach(lua_State * a_State);
+
+ /// Detaches a previously attached state.
+ void Detach(void);
+
/// Returns true if the m_LuaState is valid
bool IsValid(void) const { return (m_LuaState != NULL); }
@@ -79,6 +97,9 @@ public:
protected:
lua_State * m_LuaState;
+ /// If true, the state is owned by this object and will be auto-Closed. False => attached state
+ bool m_IsOwned;
+
/** The subsystem name is used for reporting errors to the console, it is either "plugin %s" or "LuaScript"
whatever is given to the constructor
*/