2013-08-04 17:11:25 -04:00
|
|
|
|
|
|
|
// LuaState.h
|
|
|
|
|
|
|
|
// Declares the cLuaState class representing the wrapper over lua_State *, provides associated helper functions
|
|
|
|
|
2013-08-06 02:01:00 -04:00
|
|
|
/*
|
|
|
|
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.
|
2013-08-06 02:59:54 -04:00
|
|
|
|
|
|
|
Calling a Lua function is done by pushing the function, either by PushFunction() or PushFunctionFromRegistry(),
|
|
|
|
then pushing the arguments (PushString(), PushNumber(), PushUserData() etc.) and finally
|
|
|
|
executing CallFunction(). cLuaState automatically keeps track of the number of arguments and the name of the
|
|
|
|
function (for logging purposes), which makes the call less error-prone.
|
2013-08-07 08:26:18 -04:00
|
|
|
|
|
|
|
Reference management is provided by the cLuaState::cRef class. This is used when you need to hold a reference to
|
|
|
|
any Lua object across several function calls; usually this is used for callbacks. The class is RAII-like, with
|
|
|
|
automatic resource management.
|
2013-08-06 02:01:00 -04:00
|
|
|
*/
|
2013-08-04 17:11:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-08-07 08:26:18 -04:00
|
|
|
extern "C"
|
|
|
|
{
|
2013-11-26 12:14:46 -05:00
|
|
|
#include "lua/src/lauxlib.h"
|
2013-08-07 08:26:18 -04:00
|
|
|
}
|
2013-08-04 17:11:25 -04:00
|
|
|
|
2014-03-11 10:01:17 -04:00
|
|
|
#include "../Vector3.h"
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-06 02:59:54 -04:00
|
|
|
class cWorld;
|
|
|
|
class cPlayer;
|
|
|
|
class cEntity;
|
2014-03-29 10:43:03 -04:00
|
|
|
class cProjectileEntity;
|
2013-08-08 03:13:13 -04:00
|
|
|
class cMonster;
|
2013-08-06 02:59:54 -04:00
|
|
|
class cItem;
|
|
|
|
class cItems;
|
|
|
|
class cClientHandle;
|
|
|
|
class cPickup;
|
2013-08-08 08:08:21 -04:00
|
|
|
class cChunkDesc;
|
|
|
|
class cCraftingGrid;
|
|
|
|
class cCraftingRecipe;
|
|
|
|
struct TakeDamageInfo;
|
2013-08-08 10:02:07 -04:00
|
|
|
class cWindow;
|
2013-08-19 03:39:18 -04:00
|
|
|
class cPluginLua;
|
2013-08-08 10:02:07 -04:00
|
|
|
struct HTTPRequest;
|
2013-08-08 10:30:02 -04:00
|
|
|
class cWebAdmin;
|
|
|
|
struct HTTPTemplateRequest;
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
class cTNTEntity;
|
|
|
|
class cCreeper;
|
2013-08-11 08:57:07 -04:00
|
|
|
class cHopperEntity;
|
|
|
|
class cBlockEntity;
|
2013-08-06 02:59:54 -04:00
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Encapsulates a Lua state and provides some syntactic sugar for common operations */
|
2013-08-04 17:11:25 -04:00
|
|
|
class cLuaState
|
|
|
|
{
|
|
|
|
public:
|
2013-08-07 08:26:18 -04:00
|
|
|
|
2014-02-09 12:39:22 -05:00
|
|
|
/** Used for storing references to object in the global registry.
|
|
|
|
Can be bound (contains a reference) or unbound (doesn't contain reference).
|
|
|
|
The reference can also be reset by calling RefStack(). */
|
2013-08-07 08:26:18 -04:00
|
|
|
class cRef
|
|
|
|
{
|
|
|
|
public:
|
2014-02-09 12:39:22 -05:00
|
|
|
/** Creates an unbound reference object. */
|
|
|
|
cRef(void);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Creates a reference in the specified LuaState for object at the specified StackPos */
|
2013-08-07 08:26:18 -04:00
|
|
|
cRef(cLuaState & a_LuaState, int a_StackPos);
|
2014-02-09 12:39:22 -05:00
|
|
|
|
2013-08-07 08:26:18 -04:00
|
|
|
~cRef();
|
|
|
|
|
2014-02-09 12:39:22 -05:00
|
|
|
/** 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);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the reference is valid */
|
2013-08-07 08:26:18 -04:00
|
|
|
bool IsValid(void) const {return (m_Ref != LUA_REFNIL); }
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Allows to use this class wherever an int (i. e. ref) is to be used */
|
2013-08-21 15:29:30 -04:00
|
|
|
operator int(void) const { return m_Ref; }
|
2013-08-07 08:26:18 -04:00
|
|
|
|
|
|
|
protected:
|
2014-02-09 12:39:22 -05:00
|
|
|
cLuaState * m_LuaState;
|
2013-08-07 08:26:18 -04:00
|
|
|
int m_Ref;
|
|
|
|
} ;
|
2013-08-08 08:08:21 -04:00
|
|
|
|
|
|
|
|
2014-01-11 16:51:10 -05:00
|
|
|
/** Used for calling functions stored in a reference-stored table */
|
|
|
|
class cTableRef
|
|
|
|
{
|
|
|
|
int m_TableRef;
|
|
|
|
const char * m_FnName;
|
|
|
|
public:
|
|
|
|
cTableRef(int a_TableRef, const char * a_FnName) :
|
|
|
|
m_TableRef(a_TableRef),
|
|
|
|
m_FnName(a_FnName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetTableRef(void) const { return m_TableRef; }
|
|
|
|
const char * GetFnName(void) const { return m_FnName; }
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** A dummy class that's used only to delimit function args from return values for cLuaState::Call() */
|
2013-08-08 08:08:21 -04:00
|
|
|
class cRet
|
|
|
|
{
|
|
|
|
} ;
|
|
|
|
|
|
|
|
static const cRet Return; // Use this constant to delimit function args from return values for cLuaState::Call()
|
2013-08-07 08:26:18 -04:00
|
|
|
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
/** Creates a new instance. The LuaState is not initialized.
|
|
|
|
a_SubsystemName is used for reporting problems in the console, it is "plugin %s" for plugins,
|
|
|
|
or "LuaScript" for the cLuaScript template
|
|
|
|
*/
|
|
|
|
cLuaState(const AString & a_SubsystemName);
|
|
|
|
|
2013-08-06 02:01:00 -04:00
|
|
|
/** Creates a new instance. The a_AttachState is attached.
|
|
|
|
Subsystem name is set to "<attached>".
|
|
|
|
*/
|
|
|
|
explicit cLuaState(lua_State * a_AttachState);
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
~cLuaState();
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
|
2013-08-04 17:11:25 -04:00
|
|
|
operator lua_State * (void) { return m_LuaState; }
|
|
|
|
|
2014-03-12 08:05:28 -04:00
|
|
|
/** 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. */
|
2013-08-04 17:11:25 -04:00
|
|
|
void Create(void);
|
|
|
|
|
2014-03-12 08:05:28 -04:00
|
|
|
/** Registers all the API libraries that MCS provides into m_LuaState. */
|
|
|
|
void RegisterAPILibs(void);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Closes the m_LuaState, if not closed already */
|
2013-08-04 17:11:25 -04:00
|
|
|
void Close(void);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Attaches the specified state. Operations will be carried out on this state, but it will not be closed in the destructor */
|
2013-08-06 02:01:00 -04:00
|
|
|
void Attach(lua_State * a_State);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Detaches a previously attached state. */
|
2013-08-06 02:01:00 -04:00
|
|
|
void Detach(void);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the m_LuaState is valid */
|
2013-08-04 17:11:25 -04:00
|
|
|
bool IsValid(void) const { return (m_LuaState != NULL); }
|
|
|
|
|
2014-02-17 17:12:46 -05:00
|
|
|
/** Adds the specified path to package.<a_PathVariable> */
|
|
|
|
void AddPackagePath(const AString & a_PathVariable, const AString & a_Path);
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
/** Loads the specified file
|
|
|
|
Returns false and logs a warning to the console if not successful (but the LuaState is kept open).
|
|
|
|
m_SubsystemName is displayed in the warning log message.
|
|
|
|
*/
|
|
|
|
bool LoadFile(const AString & a_FileName);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if a_FunctionName is a valid Lua function that can be called */
|
2013-08-08 10:02:07 -04:00
|
|
|
bool HasFunction(const char * a_FunctionName);
|
|
|
|
|
2013-08-08 08:08:21 -04:00
|
|
|
// Push a value onto the stack
|
|
|
|
void Push(const AString & a_String);
|
|
|
|
void Push(const AStringVector & a_Vector);
|
|
|
|
void Push(int a_Value);
|
|
|
|
void Push(double a_Value);
|
|
|
|
void Push(const char * a_Value);
|
|
|
|
void Push(bool a_Value);
|
|
|
|
void Push(cWorld * a_World);
|
|
|
|
void Push(cPlayer * a_Player);
|
|
|
|
void Push(const cPlayer * a_Player);
|
|
|
|
void Push(cEntity * a_Entity);
|
2014-03-29 10:43:03 -04:00
|
|
|
void Push(cProjectileEntity * a_ProjectileEntity);
|
2013-08-08 08:08:21 -04:00
|
|
|
void Push(cMonster * a_Monster);
|
|
|
|
void Push(cItem * a_Item);
|
|
|
|
void Push(cItems * a_Items);
|
2013-12-31 08:53:10 -05:00
|
|
|
void Push(const cItems & a_Items);
|
2013-08-08 08:08:21 -04:00
|
|
|
void Push(cClientHandle * a_ClientHandle);
|
|
|
|
void Push(cPickup * a_Pickup);
|
|
|
|
void Push(cChunkDesc * a_ChunkDesc);
|
|
|
|
void Push(const cCraftingGrid * a_Grid);
|
|
|
|
void Push(const cCraftingRecipe * a_Recipe);
|
|
|
|
void Push(TakeDamageInfo * a_TDI);
|
2013-08-08 10:02:07 -04:00
|
|
|
void Push(cWindow * a_Window);
|
2013-08-19 03:39:18 -04:00
|
|
|
void Push(cPluginLua * a_Plugin);
|
2013-08-08 10:02:07 -04:00
|
|
|
void Push(const HTTPRequest * a_Request);
|
2013-08-08 10:30:02 -04:00
|
|
|
void Push(cWebAdmin * a_WebAdmin);
|
|
|
|
void Push(const HTTPTemplateRequest * a_Request);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
void Push(cTNTEntity * a_TNTEntity);
|
|
|
|
void Push(Vector3i * a_Vector);
|
2014-03-20 04:16:47 -04:00
|
|
|
void Push(void * a_Ptr);
|
2013-08-11 08:57:07 -04:00
|
|
|
void Push(cHopperEntity * a_Hopper);
|
|
|
|
void Push(cBlockEntity * a_BlockEntity);
|
2014-03-04 15:55:24 -05:00
|
|
|
|
|
|
|
/** Retrieve value at a_StackPos, if it is a valid bool. If not, a_Value is unchanged */
|
|
|
|
void GetStackValue(int a_StackPos, bool & a_Value);
|
|
|
|
|
|
|
|
/** Retrieve value at a_StackPos, if it is a valid string. If not, a_Value is unchanged */
|
|
|
|
void GetStackValue(int a_StackPos, AString & a_Value);
|
|
|
|
|
|
|
|
/** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */
|
|
|
|
void GetStackValue(int a_StackPos, int & a_Value);
|
|
|
|
|
|
|
|
/** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */
|
|
|
|
void GetStackValue(int a_StackPos, double & a_Value);
|
|
|
|
|
2014-01-11 16:51:10 -05:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 0-param 0-return Lua function in a single line: */
|
2013-08-08 10:02:07 -04:00
|
|
|
template <typename FnT>
|
|
|
|
bool Call(FnT a_FnName)
|
|
|
|
{
|
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return CallFunction(0);
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 1-param 0-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT1
|
|
|
|
>
|
2013-08-08 10:02:07 -04:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1)
|
|
|
|
{
|
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
return CallFunction(0);
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 2-param 0-return Lua function in a single line: */
|
2013-08-08 10:02:07 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2
|
|
|
|
>
|
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
2013-08-08 10:02:07 -04:00
|
|
|
Push(a_Arg2);
|
2013-08-08 08:08:21 -04:00
|
|
|
return CallFunction(0);
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 3-param 0-return Lua function in a single line: */
|
2013-11-30 08:22:26 -05:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3
|
|
|
|
>
|
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3)
|
|
|
|
{
|
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
return CallFunction(0);
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 0-param 1-return Lua function in a single line: */
|
2013-12-29 06:51:58 -05:00
|
|
|
template<
|
|
|
|
typename FnT, typename RetT1
|
|
|
|
>
|
|
|
|
bool Call(FnT a_FnName, const cRet & a_Mark, RetT1 & a_Ret1)
|
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-12-29 06:51:58 -05:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-12-29 06:51:58 -05:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 1-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename RetT1
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2014-01-21 16:59:08 -05:00
|
|
|
int InitialTop = lua_gettop(m_LuaState);
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2014-01-21 16:59:08 -05:00
|
|
|
ASSERT(InitialTop == lua_gettop(m_LuaState));
|
2013-08-08 08:08:21 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 2-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename RetT1
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 3-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-06 02:59:54 -04:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 4-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-06 02:59:54 -04:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 5-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 6-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename RetT1
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 7-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT7, typename RetT1
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 8-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT7, typename ArgT8, typename RetT1
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
Push(a_Arg8);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 9-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
Push(a_Arg8);
|
|
|
|
Push(a_Arg9);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 10-param 1-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
Push(a_Arg8);
|
|
|
|
Push(a_Arg9);
|
|
|
|
Push(a_Arg10);
|
|
|
|
if (!CallFunction(1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-1, a_Ret1);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 1-param 2-return Lua function in a single line: */
|
2013-08-08 10:02:07 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
2013-08-08 10:02:07 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 10:02:07 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
2013-08-08 10:02:07 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 2-param 2-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename RetT1, typename RetT2
|
2013-08-08 08:08:21 -04:00
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 3-param 2-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3,
|
|
|
|
typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 4-param 2-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4,
|
|
|
|
typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 5-param 2-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
|
|
|
typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 6-param 2-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
|
|
|
typename ArgT6,
|
|
|
|
typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 7-param 2-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
|
|
|
typename ArgT6, typename ArgT7,
|
|
|
|
typename RetT1, typename RetT2
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
if (!CallFunction(2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-2, a_Ret1);
|
|
|
|
GetStackValue(-1, a_Ret2);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 7-param 3-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
|
|
|
typename ArgT6, typename ArgT7,
|
|
|
|
typename RetT1, typename RetT2, typename RetT3
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
if (!CallFunction(3))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-3, a_Ret1);
|
|
|
|
GetStackValue(-2, a_Ret2);
|
|
|
|
GetStackValue(-1, a_Ret3);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 8-param 3-return Lua function in a single line: */
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
template<
|
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
|
|
|
typename ArgT6, typename ArgT7, typename ArgT8,
|
|
|
|
typename RetT1, typename RetT2, typename RetT3
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
Push(a_Arg8);
|
|
|
|
if (!CallFunction(3))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-3, a_Ret1);
|
|
|
|
GetStackValue(-2, a_Ret2);
|
|
|
|
GetStackValue(-1, a_Ret3);
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
lua_pop(m_LuaState, 3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Call any 9-param 5-return Lua function in a single line: */
|
2013-08-08 08:08:21 -04:00
|
|
|
template<
|
2013-08-08 10:02:07 -04:00
|
|
|
typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
|
2013-08-08 08:08:21 -04:00
|
|
|
typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9,
|
|
|
|
typename RetT1, typename RetT2, typename RetT3, typename RetT4, typename RetT5
|
|
|
|
>
|
2013-12-22 08:46:55 -05:00
|
|
|
bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
2013-12-22 08:46:55 -05:00
|
|
|
UNUSED(a_Mark);
|
2013-08-08 08:08:21 -04:00
|
|
|
if (!PushFunction(a_FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Push(a_Arg1);
|
|
|
|
Push(a_Arg2);
|
|
|
|
Push(a_Arg3);
|
|
|
|
Push(a_Arg4);
|
|
|
|
Push(a_Arg5);
|
|
|
|
Push(a_Arg6);
|
|
|
|
Push(a_Arg7);
|
|
|
|
Push(a_Arg8);
|
|
|
|
Push(a_Arg9);
|
|
|
|
if (!CallFunction(5))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 15:55:24 -05:00
|
|
|
GetStackValue(-5, a_Ret1);
|
|
|
|
GetStackValue(-4, a_Ret2);
|
|
|
|
GetStackValue(-3, a_Ret3);
|
|
|
|
GetStackValue(-2, a_Ret4);
|
|
|
|
GetStackValue(-1, a_Ret5);
|
2013-08-08 08:08:21 -04:00
|
|
|
lua_pop(m_LuaState, 5);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-08 10:02:07 -04:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */
|
2013-11-22 10:49:38 -05:00
|
|
|
bool CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam = -1);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are of the specified usertype; also logs warning if not. Used for regular functions */
|
2013-08-07 08:26:18 -04:00
|
|
|
bool CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam = -1);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are tables; also logs warning if not */
|
2013-08-07 08:26:18 -04:00
|
|
|
bool CheckParamTable(int a_StartParam, int a_EndParam = -1);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are numbers; also logs warning if not */
|
2013-08-07 08:26:18 -04:00
|
|
|
bool CheckParamNumber(int a_StartParam, int a_EndParam = -1);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are strings; also logs warning if not */
|
2013-11-22 14:11:24 -05:00
|
|
|
bool CheckParamString(int a_StartParam, int a_EndParam = -1);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameters on the stack are functions; also logs warning if not */
|
2014-01-19 17:45:26 -05:00
|
|
|
bool CheckParamFunction(int a_StartParam, int a_EndParam = -1);
|
|
|
|
|
2014-02-11 09:03:35 -05:00
|
|
|
/** 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);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
|
2013-08-07 08:26:18 -04:00
|
|
|
bool CheckParamEnd(int a_Param);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
|
2013-08-04 17:11:25 -04:00
|
|
|
bool ReportErrors(int status);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
|
2013-08-04 17:11:25 -04:00
|
|
|
static bool ReportErrors(lua_State * a_LuaState, int status);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Logs all items in the current stack trace to the server console */
|
2014-03-19 17:55:47 -04:00
|
|
|
void LogStackTrace(int a_StartingDepth = 0);
|
2013-08-21 14:06:37 -04:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Logs all items in the current stack trace to the server console */
|
2014-03-19 17:55:47 -04:00
|
|
|
static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
|
2014-01-11 16:51:10 -05:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Returns the type of the item on the specified position in the stack */
|
2013-08-21 14:06:37 -04:00
|
|
|
AString GetTypeText(int a_StackPos);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** 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. */
|
|
|
|
int CallFunctionWithForeignParams(
|
|
|
|
const AString & a_FunctionName,
|
|
|
|
cLuaState & a_SrcLuaState,
|
|
|
|
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);
|
|
|
|
|
|
|
|
/** 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 = NULL);
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
protected:
|
|
|
|
lua_State * m_LuaState;
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** If true, the state is owned by this object and will be auto-Closed. False => attached state */
|
2013-08-06 02:01:00 -04:00
|
|
|
bool m_IsOwned;
|
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
/** 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;
|
2013-08-06 02:59:54 -04:00
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Name of the currently pushed function (for the Push / Call chain) */
|
2013-08-06 02:59:54 -04:00
|
|
|
AString m_CurrentFunctionName;
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Number of arguments currently pushed (for the Push / Call chain) */
|
2013-08-06 02:59:54 -04:00
|
|
|
int m_NumCurrentFunctionArgs;
|
2014-01-11 16:51:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
/** Pushes the function of the specified name onto the stack.
|
|
|
|
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 is stored in a referenced table by name
|
|
|
|
Returns true if successful. Logs a warning on failure
|
|
|
|
*/
|
|
|
|
bool PushFunction(const cTableRef & a_TableRef);
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
/** Pushes a usertype of the specified class type onto the stack */
|
2014-01-11 16:51:10 -05:00
|
|
|
void PushUserType(void * a_Object, const char * a_Type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls the function that has been pushed onto the stack by PushFunction(),
|
|
|
|
with arguments pushed by PushXXX().
|
|
|
|
Returns true if successful, logs a warning on failure.
|
|
|
|
*/
|
|
|
|
bool CallFunction(int a_NumReturnValues);
|
|
|
|
|
2014-01-11 17:10:40 -05:00
|
|
|
/** Used as the error reporting function for function calls */
|
|
|
|
static int ReportFnCallErrors(lua_State * a_LuaState);
|
2013-08-04 17:11:25 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|