summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Bindings/LuaState.h98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index f66605332..215980033 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -57,26 +57,26 @@ public:
public:
/** Creates an unbound reference object. */
cRef(void);
-
+
/** Creates a reference in the specified LuaState for object at the specified StackPos */
cRef(cLuaState & a_LuaState, int a_StackPos);
/** Moves the reference from the specified instance into a newly created instance.
The old instance is then "!IsValid()". */
cRef(cRef && a_FromRef);
-
+
~cRef();
-
+
/** Creates a reference to Lua object at the specified stack pos, binds this object to it.
Calls UnRef() first if previously bound to another reference. */
void RefStack(cLuaState & a_LuaState, int a_StackPos);
-
+
/** Removes the bound reference, resets the object to Unbound state. */
void UnRef(void);
-
+
/** Returns true if the reference is valid */
bool IsValid(void) const {return (m_Ref != LUA_REFNIL); }
-
+
/** Allows to use this class wherever an int (i. e. ref) is to be used */
explicit operator int(void) const { return m_Ref; }
@@ -87,8 +87,8 @@ public:
// Remove the copy-constructor:
cRef(const cRef &) = delete;
} ;
-
-
+
+
/** Used for calling functions stored in a reference-stored table */
class cTableRef
{
@@ -100,7 +100,7 @@ public:
m_FnName(a_FnName)
{
}
-
+
cTableRef(const cRef & a_TableRef, const char * a_FnName) :
m_TableRef(static_cast<int>(a_TableRef)),
m_FnName(a_FnName)
@@ -110,13 +110,13 @@ public:
int GetTableRef(void) const { return m_TableRef; }
const char * GetFnName(void) const { return m_FnName; }
} ;
-
-
+
+
/** A dummy class that's used only to delimit function args from return values for cLuaState::Call() */
class cRet
{
} ;
-
+
static const cRet Return; // Use this constant to delimit function args from return values for cLuaState::Call()
@@ -180,31 +180,31 @@ public:
or "LuaScript" for the cLuaScript template
*/
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. This state will be automatically closed in the destructor.
The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
lite-config as well), use RegisterAPILibs() to do that. */
void Create(void);
-
+
/** Registers all the API libraries that MCS provides into m_LuaState. */
void RegisterAPILibs(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);
@@ -260,7 +260,7 @@ public:
void Push(long a_Value);
void Push(const UInt32 a_Value);
void Push(std::chrono::milliseconds a_time);
-
+
// GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged.
// Returns whether value was changed
// Enum values are checked for their allowed values and fail if the value is not assigned.
@@ -335,7 +335,7 @@ public:
// Include the auto-generated Push and GetStackValue() functions:
#include "LuaState_Declaration.inc"
-
+
/** Call the specified Lua function.
Returns true if call succeeded, false if there was an error.
A special param of cRet & signifies the end of param list and the start of return values.
@@ -364,50 +364,50 @@ public:
/** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */
bool CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are of the specified usertype; also logs warning if not. Used for regular functions */
bool CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are tables; also logs warning if not */
bool CheckParamTable(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are numbers; also logs warning if not */
bool CheckParamNumber(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are bools; also logs warning if not */
bool CheckParamBool(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are strings; also logs warning if not */
bool CheckParamString(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are functions; also logs warning if not */
bool CheckParamFunction(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameters on the stack are functions or nils; also logs warning if not */
bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam = -1);
-
+
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
bool CheckParamEnd(int a_Param);
-
+
bool IsParamUserType(int a_Param, AString a_UserType);
bool IsParamNumber(int a_Param);
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
bool ReportErrors(int status);
-
+
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
static bool ReportErrors(lua_State * a_LuaState, int status);
-
+
/** Logs all items in the current stack trace to the server console */
void LogStackTrace(int a_StartingDepth = 0);
-
+
/** Logs all items in the current stack trace to the server console */
static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
-
+
/** Returns the type of the item on the specified position in the stack */
AString GetTypeText(int a_StackPos);
-
+
/** Calls the function specified by its name, with arguments copied off the foreign state.
If successful, keeps the return values on the stack and returns their number.
If unsuccessful, returns a negative number and keeps the stack position unchanged. */
@@ -417,37 +417,37 @@ public:
int a_SrcParamStart,
int a_SrcParamEnd
);
-
+
/** Copies objects on the stack from the specified state.
Only numbers, bools, strings and userdatas are copied.
If successful, returns the number of objects copied.
If failed, returns a negative number and rewinds the stack position. */
int CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_SrcEnd);
-
+
/** Reads the value at the specified stack position as a string and sets it to a_String. */
void ToString(int a_StackPos, AString & a_String);
/** Logs all the elements' types on the API stack, with an optional header for the listing. */
void LogStack(const char * a_Header = nullptr);
-
+
/** Logs all the elements' types on the API stack, with an optional header for the listing. */
static void LogStack(lua_State * a_LuaState, const char * a_Header = nullptr);
-
+
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
*/
AString m_SubsystemName;
-
+
/** Name of the currently pushed function (for the Push / Call chain) */
AString m_CurrentFunctionName;
-
+
/** Number of arguments currently pushed (for the Push / Call chain) */
int m_NumCurrentFunctionArgs;
@@ -499,12 +499,12 @@ protected:
Returns true if successful. Logs a warning on failure (incl. m_SubsystemName)
*/
bool PushFunction(const char * a_FunctionName);
-
+
/** Pushes a function that has been saved into the global registry, identified by a_FnRef.
Returns true if successful. Logs a warning on failure
*/
bool PushFunction(int a_FnRef);
-
+
/** Pushes a function that has been saved as a reference.
Returns true if successful. Logs a warning on failure
*/
@@ -512,12 +512,12 @@ protected:
{
return PushFunction(static_cast<int>(a_FnRef));
}
-
+
/** Pushes a function that is stored in a referenced table by name
Returns true if successful. Logs a warning on failure
*/
bool PushFunction(const cTableRef & a_TableRef);
-
+
/** Pushes a usertype of the specified class type onto the stack */
// void PushUserType(void * a_Object, const char * a_Type);
@@ -527,7 +527,7 @@ protected:
Returns true if successful, logs a warning on failure.
*/
bool CallFunction(int a_NumReturnValues);
-
+
/** Used as the error reporting function for function calls */
static int ReportFnCallErrors(lua_State * a_LuaState);