From 2151bb8f5bad91975010ab1022177fdb94cc2a3e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 6 Aug 2013 08:01:00 +0200 Subject: cLuaState can now contain a detached LuaState, too. This will be useful for cases when we get a lua_State * from the outside and are asked to perform operations on it. --- source/LuaState.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source/LuaState.h') 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 "". + */ + 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 */ -- cgit v1.2.3