2012-06-14 09:06:06 -04:00
# include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
# include "ManualBindings.h"
2014-03-25 13:15:05 -04:00
# undef TOLUA_TEMPLATE_BIND
2015-02-21 03:41:14 -05:00
# include <sstream>
# include <iomanip>
2013-12-08 12:24:56 -05:00
# include "tolua++/include/tolua++.h"
2014-06-28 12:20:46 -04:00
# include "polarssl/md5.h"
2015-02-21 03:41:14 -05:00
# include "polarssl/sha1.h"
2013-08-09 09:15:56 -04:00
# include "PluginLua.h"
2012-09-23 18:09:57 -04:00
# include "PluginManager.h"
2013-05-30 15:34:09 -04:00
# include "LuaWindow.h"
2014-02-09 14:39:45 -05:00
# include "LuaChunkStay.h"
2013-12-08 06:17:54 -05:00
# include "../Root.h"
# include "../World.h"
# include "../Entities/Player.h"
# include "../WebAdmin.h"
# include "../ClientHandle.h"
2014-01-22 13:35:36 -05:00
# include "../BlockArea.h"
2014-07-30 16:19:51 -04:00
# include "../BlockEntities/BeaconEntity.h"
2013-12-08 06:17:54 -05:00
# include "../BlockEntities/ChestEntity.h"
2014-01-18 09:59:33 -05:00
# include "../BlockEntities/CommandBlockEntity.h"
2013-12-08 06:17:54 -05:00
# include "../BlockEntities/DispenserEntity.h"
# include "../BlockEntities/DropperEntity.h"
# include "../BlockEntities/FurnaceEntity.h"
# include "../BlockEntities/HopperEntity.h"
2013-12-14 11:52:22 -05:00
# include "../BlockEntities/NoteEntity.h"
2014-02-19 08:45:09 -05:00
# include "../BlockEntities/MobHeadEntity.h"
2014-03-06 19:30:34 -05:00
# include "../BlockEntities/FlowerPotEntity.h"
2013-12-08 06:17:54 -05:00
# include "../LineBlockTracer.h"
2014-01-22 13:39:09 -05:00
# include "../WorldStorage/SchematicFileSerializer.h"
2014-03-04 16:17:23 -05:00
# include "../CompositeChat.h"
2015-02-22 11:34:20 -05:00
# include "../StringCompression.h"
2012-06-14 09:06:06 -04:00
2012-07-02 07:21:21 -04:00
2014-07-17 16:50:58 -04:00
// Better error reporting for Lua
2014-05-01 17:43:11 -04:00
static int tolua_do_error ( lua_State * L , const char * a_pMsg , tolua_Error * a_pToLuaError )
2013-02-02 18:55:29 -05:00
{
// Retrieve current function name
lua_Debug entry ;
2013-02-10 09:37:23 -05:00
VERIFY ( lua_getstack ( L , 0 , & entry ) ) ;
VERIFY ( lua_getinfo ( L , " n " , & entry ) ) ;
2013-02-02 18:55:29 -05:00
// Insert function name into error msg
AString msg ( a_pMsg ) ;
ReplaceString ( msg , " #funcname# " , entry . name ? entry . name : " ? " ) ;
// Send the error to Lua
tolua_error ( L , msg . c_str ( ) , a_pToLuaError ) ;
return 0 ;
}
2014-05-01 17:43:11 -04:00
static int lua_do_error ( lua_State * L , const char * a_pFormat , . . . )
2013-02-02 18:55:29 -05:00
{
// Retrieve current function name
lua_Debug entry ;
2013-02-10 09:37:23 -05:00
VERIFY ( lua_getstack ( L , 0 , & entry ) ) ;
VERIFY ( lua_getinfo ( L , " n " , & entry ) ) ;
2013-02-02 18:55:29 -05:00
// Insert function name into error msg
AString msg ( a_pFormat ) ;
2015-04-23 13:41:01 -04:00
ReplaceString ( msg , " #funcname# " , ( entry . name ! = nullptr ) ? entry . name : " ? " ) ;
2013-02-02 18:55:29 -05:00
// Copied from luaL_error and modified
va_list argp ;
va_start ( argp , a_pFormat ) ;
luaL_where ( L , 1 ) ;
lua_pushvfstring ( L , msg . c_str ( ) , argp ) ;
va_end ( argp ) ;
lua_concat ( L , 2 ) ;
return lua_error ( L ) ;
}
2014-07-17 16:50:58 -04:00
// Lua bound functions with special return types
2014-08-05 07:47:10 -04:00
static int tolua_Clamp ( lua_State * tolua_S )
{
cLuaState LuaState ( tolua_S ) ;
int NumArgs = lua_gettop ( LuaState ) ;
if ( NumArgs ! = 3 )
{
return lua_do_error ( LuaState , " Error in function call '#funcname#': Requires 3 arguments, got %i " , NumArgs ) ;
}
if ( ! lua_isnumber ( LuaState , 1 ) | | ! lua_isnumber ( LuaState , 2 ) | | ! lua_isnumber ( LuaState , 3 ) )
{
return lua_do_error ( LuaState , " Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3 " ) ;
}
2014-08-05 12:39:18 -04:00
lua_Number Number = tolua_tonumber ( LuaState , 1 , 0 ) ;
lua_Number Min = tolua_tonumber ( LuaState , 2 , 0 ) ;
lua_Number Max = tolua_tonumber ( LuaState , 3 , 0 ) ;
2014-08-05 07:47:10 -04:00
2014-08-05 12:39:18 -04:00
lua_Number Result = Clamp ( Number , Min , Max ) ;
2014-08-05 07:47:10 -04:00
LuaState . Push ( Result ) ;
return 1 ;
}
2015-02-23 06:53:02 -05:00
static int tolua_CompressStringZLIB ( lua_State * tolua_S )
2015-02-22 11:34:20 -05:00
{
2015-02-23 06:53:02 -05:00
cLuaState S ( tolua_S ) ;
if (
2015-02-23 10:09:35 -05:00
! S . CheckParamString ( 1 ) | |
2015-02-23 06:53:02 -05:00
(
2015-02-23 10:09:35 -05:00
! S . CheckParamNumber ( 2 ) & &
2015-02-23 09:40:31 -05:00
! S . CheckParamEnd ( 2 )
2015-02-23 06:53:02 -05:00
)
)
{
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
// Get the params:
AString ToCompress ;
int CompressionLevel = 5 ;
S . GetStackValues ( 1 , ToCompress , CompressionLevel ) ;
// Compress the string:
2015-02-22 11:34:20 -05:00
AString res ;
2015-02-23 06:53:02 -05:00
CompressString ( ToCompress . data ( ) , ToCompress . size ( ) , res , CompressionLevel ) ;
S . Push ( res ) ;
return 1 ;
}
2015-02-22 11:34:20 -05:00
2015-02-23 06:53:02 -05:00
static int tolua_UncompressStringZLIB ( lua_State * tolua_S )
{
cLuaState S ( tolua_S ) ;
if (
2015-02-23 10:09:35 -05:00
! S . CheckParamString ( 1 ) | |
2015-02-23 09:29:07 -05:00
! S . CheckParamNumber ( 2 )
2015-02-23 06:53:02 -05:00
)
{
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
// Get the params:
AString ToUncompress ;
int UncompressedSize ;
S . GetStackValues ( 1 , ToUncompress , UncompressedSize ) ;
// Compress the string:
AString res ;
UncompressString ( ToUncompress . data ( ) , ToUncompress . size ( ) , res , UncompressedSize ) ;
S . Push ( res ) ;
2015-02-22 11:34:20 -05:00
return 1 ;
}
2015-02-23 06:53:02 -05:00
static int tolua_CompressStringGZIP ( lua_State * tolua_S )
2015-02-22 11:34:20 -05:00
{
2015-02-23 06:53:02 -05:00
cLuaState S ( tolua_S ) ;
2015-02-23 09:29:07 -05:00
if (
2015-02-23 10:09:35 -05:00
! S . CheckParamString ( 1 ) | |
2015-02-23 09:29:07 -05:00
! S . CheckParamEnd ( 2 )
)
2015-02-23 06:53:02 -05:00
{
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
// Get the params:
AString ToCompress ;
S . GetStackValues ( 1 , ToCompress ) ;
// Compress the string:
AString res ;
CompressStringGZIP ( ToCompress . data ( ) , ToCompress . size ( ) , res ) ;
S . Push ( res ) ;
return 1 ;
}
static int tolua_UncompressStringGZIP ( lua_State * tolua_S )
{
cLuaState S ( tolua_S ) ;
if (
2015-02-23 10:09:35 -05:00
! S . CheckParamString ( 1 ) | |
2015-02-23 09:29:07 -05:00
! S . CheckParamEnd ( 2 )
2015-02-23 06:53:02 -05:00
)
{
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
// Get the params:
AString ToUncompress ;
S . GetStackValues ( 1 , ToUncompress ) ;
// Compress the string:
2015-02-22 11:34:20 -05:00
AString res ;
2015-02-23 06:53:02 -05:00
UncompressStringGZIP ( ToUncompress . data ( ) , ToUncompress . size ( ) , res ) ;
S . Push ( res ) ;
return 1 ;
}
2015-02-22 11:34:20 -05:00
2015-02-23 06:53:02 -05:00
static int tolua_InflateString ( lua_State * tolua_S )
{
cLuaState S ( tolua_S ) ;
if (
2015-02-23 10:09:35 -05:00
! S . CheckParamString ( 1 ) | |
2015-02-23 09:29:07 -05:00
! S . CheckParamEnd ( 2 )
2015-02-23 06:53:02 -05:00
)
{
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
// Get the params:
AString ToUncompress ;
S . GetStackValues ( 1 , ToUncompress ) ;
// Compress the string:
AString res ;
InflateString ( ToUncompress . data ( ) , ToUncompress . size ( ) , res ) ;
S . Push ( res ) ;
2015-02-22 11:34:20 -05:00
return 1 ;
}
2013-08-06 11:17:26 -04:00
static int tolua_StringSplit ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2013-08-06 11:17:26 -04:00
cLuaState LuaState ( tolua_S ) ;
std : : string str = ( std : : string ) tolua_tocppstring ( LuaState , 1 , 0 ) ;
std : : string delim = ( std : : string ) tolua_tocppstring ( LuaState , 2 , 0 ) ;
AStringVector Split = StringSplit ( str , delim ) ;
2013-08-08 08:08:21 -04:00
LuaState . Push ( Split ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2015-03-10 23:14:17 -04:00
static int tolua_StringSplitWithQuotes ( lua_State * tolua_S )
{
2015-03-11 15:02:11 -04:00
cLuaState S ( tolua_S ) ;
AString str ;
AString delim ;
S . GetStackValues ( 1 , str , delim ) ;
2015-03-10 23:14:17 -04:00
AStringVector Split = StringSplitWithQuotes ( str , delim ) ;
2015-03-11 15:02:11 -04:00
S . Push ( Split ) ;
2015-03-10 23:14:17 -04:00
return 1 ;
}
2013-09-11 15:12:34 -04:00
static int tolua_StringSplitAndTrim ( lua_State * tolua_S )
{
cLuaState LuaState ( tolua_S ) ;
std : : string str = ( std : : string ) tolua_tocppstring ( LuaState , 1 , 0 ) ;
std : : string delim = ( std : : string ) tolua_tocppstring ( LuaState , 2 , 0 ) ;
AStringVector Split = StringSplitAndTrim ( str , delim ) ;
LuaState . Push ( Split ) ;
return 1 ;
}
2014-03-31 16:51:14 -04:00
/** Retrieves the log message from the first param on the Lua stack.
Can take either a string or a cCompositeChat .
*/
static AString GetLogMessage ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2014-03-31 16:51:14 -04:00
tolua_Error err ;
if ( tolua_isusertype ( tolua_S , 1 , " cCompositeChat " , false , & err ) )
{
2014-10-20 16:55:07 -04:00
return ( ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ) - > ExtractText ( ) ;
2014-03-31 16:51:14 -04:00
}
else
{
size_t len = 0 ;
const char * str = lua_tolstring ( tolua_S , 1 , & len ) ;
2014-10-20 16:55:07 -04:00
if ( str ! = nullptr )
2014-03-31 16:51:14 -04:00
{
return AString ( str , len ) ;
}
}
return " " ;
}
static int tolua_LOG ( lua_State * tolua_S )
{
2015-02-20 03:51:18 -05:00
// If there's no param, spit out an error message instead of crashing:
if ( lua_isnil ( tolua_S , 1 ) )
{
LOGWARNING ( " Attempting to LOG a nil value! " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
2014-04-01 03:32:14 -04:00
// If the param is a cCompositeChat, read the log level from it:
2014-08-12 11:05:04 -04:00
cLogger : : eLogLevel LogLevel = cLogger : : llRegular ;
2014-04-01 03:32:14 -04:00
tolua_Error err ;
if ( tolua_isusertype ( tolua_S , 1 , " cCompositeChat " , false , & err ) )
{
2014-10-20 16:55:07 -04:00
LogLevel = cCompositeChat : : MessageTypeToLogLevel ( ( ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ) - > GetMessageType ( ) ) ;
2014-04-01 03:32:14 -04:00
}
// Log the message:
2014-08-12 11:05:04 -04:00
cLogger : : GetInstance ( ) . LogSimple ( GetLogMessage ( tolua_S ) . c_str ( ) , LogLevel ) ;
2012-06-14 09:06:06 -04:00
return 0 ;
}
2014-03-31 16:51:14 -04:00
static int tolua_LOGINFO ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2015-02-20 03:51:18 -05:00
// If there's no param, spit out an error message instead of crashing:
if ( lua_isnil ( tolua_S , 1 ) )
{
LOGWARNING ( " Attempting to LOGINFO a nil value! " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
2014-08-12 11:05:04 -04:00
cLogger : : GetInstance ( ) . LogSimple ( GetLogMessage ( tolua_S ) . c_str ( ) , cLogger : : llInfo ) ;
2012-06-14 09:06:06 -04:00
return 0 ;
}
2014-03-31 16:51:14 -04:00
static int tolua_LOGWARN ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2015-02-20 03:51:18 -05:00
// If there's no param, spit out an error message instead of crashing:
if ( lua_isnil ( tolua_S , 1 ) )
{
LOGWARNING ( " Attempting to LOGWARN a nil value! " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
2014-08-12 11:05:04 -04:00
cLogger : : GetInstance ( ) . LogSimple ( GetLogMessage ( tolua_S ) . c_str ( ) , cLogger : : llWarning ) ;
2012-06-14 09:06:06 -04:00
return 0 ;
}
2014-03-31 16:51:14 -04:00
static int tolua_LOGERROR ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2015-02-20 03:51:18 -05:00
// If there's no param, spit out an error message instead of crashing:
if ( lua_isnil ( tolua_S , 1 ) )
{
LOGWARNING ( " Attempting to LOGERROR a nil value! " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
2014-08-12 11:05:04 -04:00
cLogger : : GetInstance ( ) . LogSimple ( GetLogMessage ( tolua_S ) . c_str ( ) , cLogger : : llError ) ;
2012-06-14 09:06:06 -04:00
return 0 ;
}
2014-04-01 16:47:39 -04:00
static int tolua_Base64Encode ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamString ( 1 ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
AString Src ;
L . GetStackValue ( 1 , Src ) ;
AString res = Base64Encode ( Src ) ;
L . Push ( res ) ;
return 1 ;
}
static int tolua_Base64Decode ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamString ( 1 ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
AString Src ;
L . GetStackValue ( 1 , Src ) ;
AString res = Base64Decode ( Src ) ;
L . Push ( res ) ;
return 1 ;
}
2015-01-28 09:14:05 -05:00
cPluginLua * GetLuaPlugin ( lua_State * L )
2013-05-30 15:34:09 -04:00
{
// Get the plugin identification out of LuaState:
lua_getglobal ( L , LUA_PLUGIN_INSTANCE_VAR_NAME ) ;
if ( ! lua_islightuserdata ( L , - 1 ) )
{
2013-08-06 11:17:26 -04:00
LOGWARNING ( " %s: cannot get plugin instance, what have you done to my Lua state? " , __FUNCTION__ ) ;
2013-08-06 13:27:48 -04:00
lua_pop ( L , 1 ) ;
2014-10-20 16:55:07 -04:00
return nullptr ;
2013-05-30 15:34:09 -04:00
}
2013-08-19 03:39:18 -04:00
cPluginLua * Plugin = ( cPluginLua * ) lua_topointer ( L , - 1 ) ;
2013-05-30 15:34:09 -04:00
lua_pop ( L , 1 ) ;
return Plugin ;
}
2013-08-05 09:41:24 -04:00
2013-11-22 14:11:24 -05:00
static int tolua_cFile_GetFolderContents ( lua_State * tolua_S )
{
cLuaState LuaState ( tolua_S ) ;
if (
! LuaState . CheckParamUserTable ( 1 , " cFile " ) | |
! LuaState . CheckParamString ( 2 ) | |
! LuaState . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2013-11-23 14:26:23 -05:00
AString Folder = ( AString ) tolua_tocppstring ( LuaState , 2 , 0 ) ;
2013-11-22 14:11:24 -05:00
AStringVector Contents = cFile : : GetFolderContents ( Folder ) ;
LuaState . Push ( Contents ) ;
return 1 ;
}
2015-04-23 13:41:01 -04:00
/** Binds the DoWith(ItemName) functions of regular classes. */
2014-08-28 09:44:36 -04:00
template <
2013-02-02 18:55:29 -05:00
class Ty1 ,
class Ty2 ,
2015-04-23 13:41:01 -04:00
bool ( Ty1 : : * DoWithFn ) ( const AString & , cItemCallback < Ty2 > & )
2014-08-28 09:44:36 -04:00
>
2015-04-23 13:41:01 -04:00
static int tolua_DoWith ( lua_State * tolua_S )
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamString ( 2 ) | |
! L . CheckParamFunction ( 3 )
)
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
return 0 ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2015-04-23 13:41:01 -04:00
// Get parameters:
Ty1 * Self ;
AString ItemName ;
cLuaState : : cRef FnRef ;
L . GetStackValues ( 1 , Self , ItemName , FnRef ) ;
if ( Self = = nullptr )
2013-08-05 09:41:24 -04:00
{
2015-04-23 13:41:01 -04:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Invalid 'self' " ) ;
2013-08-05 09:41:24 -04:00
}
2015-04-23 13:41:01 -04:00
if ( ItemName . empty ( ) | | ( ItemName [ 0 ] = = 0 ) )
2013-08-05 09:41:24 -04:00
{
2015-04-23 13:41:01 -04:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a non-empty string for parameter #1 " ) ;
}
if ( ! FnRef . IsValid ( ) )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a valid callback function for parameter #2 " ) ;
2013-08-05 09:41:24 -04:00
}
2015-04-23 13:41:01 -04:00
class cLuaCallback : public cItemCallback < Ty2 >
2013-08-05 09:41:24 -04:00
{
2015-04-23 13:41:01 -04:00
public :
cLuaCallback ( cLuaState & a_LuaState , cLuaState : : cRef & a_FnRef ) :
m_LuaState ( a_LuaState ) ,
m_FnRef ( a_FnRef )
2013-08-05 09:41:24 -04:00
{
}
2015-04-23 13:41:01 -04:00
private :
virtual bool Item ( Ty2 * a_Item ) override
{
bool ret = false ;
m_LuaState . Call ( m_FnRef , a_Item , cLuaState : : Return , ret ) ;
return ret ;
}
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
} Callback ( L , FnRef ) ;
// Call the DoWith function:
bool res = ( Self - > * DoWithFn ) ( ItemName , Callback ) ;
// Push the result as the return value:
L . Push ( res ) ;
return 1 ;
}
/** Template for static functions DoWith(ItemName), on a type that has a static ::Get() function. */
template <
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * DoWithFn ) ( const AString & , cItemCallback < Ty2 > & )
>
static int tolua_StaticDoWith ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamString ( 2 ) | |
! L . CheckParamFunction ( 3 )
)
{
return 0 ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2015-04-23 13:41:01 -04:00
// Get parameters:
AString ItemName ;
cLuaState : : cRef FnRef ;
L . GetStackValues ( 2 , ItemName , FnRef ) ;
if ( ItemName . empty ( ) | | ( ItemName [ 0 ] = = 0 ) )
2013-08-05 09:41:24 -04:00
{
2015-04-23 13:41:01 -04:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a non-empty string for parameter #1 " ) ;
}
if ( ! FnRef . IsValid ( ) )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a valid callback function for parameter #2 " ) ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
class cLuaCallback : public cItemCallback < Ty2 >
2013-02-02 18:55:29 -05:00
{
2013-08-05 09:41:24 -04:00
public :
2015-04-23 13:41:01 -04:00
cLuaCallback ( cLuaState & a_LuaState , cLuaState : : cRef & a_FnRef ) :
m_LuaState ( a_LuaState ) ,
m_FnRef ( a_FnRef )
2015-04-19 04:57:41 -04:00
{
}
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
private :
virtual bool Item ( Ty2 * a_Item ) override
{
2015-04-23 13:41:01 -04:00
bool ret = false ;
m_LuaState . Call ( m_FnRef , a_Item , cLuaState : : Return , ret ) ;
return ret ;
2013-08-05 09:41:24 -04:00
}
2015-04-23 13:41:01 -04:00
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
} Callback ( L , FnRef ) ;
2013-02-02 18:55:29 -05:00
2015-04-23 13:41:01 -04:00
// Call the DoWith function:
bool res = ( Ty1 : : Get ( ) - > * DoWithFn ) ( ItemName , Callback ) ;
2013-02-02 18:55:29 -05:00
2015-04-23 13:41:01 -04:00
// Push the result as the return value:
L . Push ( res ) ;
2013-08-05 09:41:24 -04:00
return 1 ;
}
2014-08-28 09:44:36 -04:00
template <
2013-08-05 09:41:24 -04:00
class Ty1 ,
class Ty2 ,
2015-03-21 10:18:17 -04:00
bool ( Ty1 : : * Func1 ) ( UInt32 , cItemCallback < Ty2 > & )
2013-08-05 09:41:24 -04:00
>
static int tolua_DoWithID ( lua_State * tolua_S )
{
int NumArgs = lua_gettop ( tolua_S ) - 1 ; /* This includes 'self' */
if ( ( NumArgs ! = 2 ) & & ( NumArgs ! = 3 ) )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Requires 2 or 3 arguments, got %i " , NumArgs ) ;
}
2014-10-20 16:55:07 -04:00
Ty1 * self = ( Ty1 * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-08-05 09:41:24 -04:00
int ItemID = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
if ( ! lua_isfunction ( tolua_S , 3 ) )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a function for parameter #2 " , NumArgs ) ;
}
/* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
int TableRef = LUA_REFNIL ;
if ( NumArgs = = 3 )
{
TableRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( TableRef = = LUA_REFNIL )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get value reference of parameter #3 " , NumArgs ) ;
}
}
/* table value is popped, and now function is on top of the stack */
int FuncRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FuncRef = = LUA_REFNIL )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get function reference of parameter #2 " , NumArgs ) ;
}
class cLuaCallback : public cItemCallback < Ty2 >
{
public :
cLuaCallback ( lua_State * a_LuaState , int a_FuncRef , int a_TableRef ) :
LuaState ( a_LuaState ) ,
FuncRef ( a_FuncRef ) ,
TableRef ( a_TableRef )
2015-04-19 04:57:41 -04:00
{
}
2013-08-05 09:41:24 -04:00
private :
virtual bool Item ( Ty2 * a_Item ) override
{
2015-03-19 11:24:32 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , FuncRef ) ; // Push function to call
tolua_pushusertype ( LuaState , a_Item , a_Item - > GetClass ( ) ) ; // Push the item
2013-08-05 09:41:24 -04:00
if ( TableRef ! = LUA_REFNIL )
{
2015-03-19 11:24:32 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , TableRef ) ; // Push the optional callbackdata param
2013-08-05 09:41:24 -04:00
}
int s = lua_pcall ( LuaState , ( TableRef = = LUA_REFNIL ? 1 : 2 ) , 1 , 0 ) ;
2013-08-05 10:02:41 -04:00
if ( cLuaState : : ReportErrors ( LuaState , s ) )
2013-08-05 09:41:24 -04:00
{
return true ; // Abort enumeration
}
if ( lua_isboolean ( LuaState , - 1 ) )
{
return ( tolua_toboolean ( LuaState , - 1 , 0 ) > 0 ) ;
}
return false ; /* Continue enumeration */
}
lua_State * LuaState ;
int FuncRef ;
int TableRef ;
} Callback ( tolua_S , FuncRef , TableRef ) ;
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
bool bRetVal = ( self - > * Func1 ) ( ItemID , Callback ) ;
/* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , TableRef ) ;
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , FuncRef ) ;
/* Push return value on stack */
2014-07-21 09:19:48 -04:00
tolua_pushboolean ( tolua_S , bRetVal ) ;
2013-08-05 09:41:24 -04:00
return 1 ;
2012-07-02 07:21:21 -04:00
}
2013-02-02 18:55:29 -05:00
2014-08-28 09:44:36 -04:00
template <
2013-08-07 08:34:00 -04:00
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * Func1 ) ( int , int , int , cItemCallback < Ty2 > & )
>
2013-02-02 18:55:29 -05:00
static int tolua_DoWithXYZ ( lua_State * tolua_S )
{
2013-08-05 09:41:24 -04:00
int NumArgs = lua_gettop ( tolua_S ) - 1 ; /* This includes 'self' */
if ( ( NumArgs ! = 4 ) & & ( NumArgs ! = 5 ) )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Requires 4 or 5 arguments, got %i " , NumArgs ) ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2014-10-20 16:55:07 -04:00
Ty1 * self = ( Ty1 * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-08-05 09:41:24 -04:00
if ( ! lua_isnumber ( tolua_S , 2 ) | | ! lua_isnumber ( tolua_S , 3 ) | | ! lua_isnumber ( tolua_S , 4 ) )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3 " ) ;
2013-08-05 09:41:24 -04:00
}
int ItemX = ( ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ) ;
int ItemY = ( ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ) ;
int ItemZ = ( ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ) ;
2015-04-19 04:57:41 -04:00
if ( ! lua_isfunction ( tolua_S , 5 ) )
2013-08-05 09:41:24 -04:00
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a function for parameter #4 " ) ;
2013-08-05 09:41:24 -04:00
}
/* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
int TableRef = LUA_REFNIL ;
if ( NumArgs = = 5 )
{
TableRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( TableRef = = LUA_REFNIL )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get value reference of parameter #5 " ) ;
2013-08-05 09:41:24 -04:00
}
}
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
/* table value is popped, and now function is on top of the stack */
int FuncRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FuncRef = = LUA_REFNIL )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get function reference of parameter #4 " ) ;
2013-08-05 09:41:24 -04:00
}
class cLuaCallback : public cItemCallback < Ty2 >
{
public :
2015-04-19 04:57:41 -04:00
cLuaCallback ( lua_State * a_LuaState , int a_FuncRef , int a_TableRef ) :
LuaState ( a_LuaState ) ,
FuncRef ( a_FuncRef ) ,
TableRef ( a_TableRef )
{
}
2013-08-05 09:41:24 -04:00
private :
virtual bool Item ( Ty2 * a_Item ) override
{
2015-04-19 04:57:41 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , FuncRef ) ; /* Push function reference */
2013-08-05 09:41:24 -04:00
tolua_pushusertype ( LuaState , a_Item , Ty2 : : GetClassStatic ( ) ) ;
if ( TableRef ! = LUA_REFNIL )
{
2015-04-19 04:57:41 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , TableRef ) ; /* Push table reference */
2013-08-05 09:41:24 -04:00
}
int s = lua_pcall ( LuaState , ( TableRef = = LUA_REFNIL ? 1 : 2 ) , 1 , 0 ) ;
2013-08-04 17:11:25 -04:00
if ( cLuaState : : ReportErrors ( LuaState , s ) )
2013-05-25 07:57:28 -04:00
{
return true ; // Abort enumeration
}
2013-08-05 09:41:24 -04:00
if ( lua_isboolean ( LuaState , - 1 ) )
{
return ( tolua_toboolean ( LuaState , - 1 , 0 ) > 0 ) ;
}
return false ; /* Continue enumeration */
}
lua_State * LuaState ;
int FuncRef ;
int TableRef ;
} Callback ( tolua_S , FuncRef , TableRef ) ;
2013-02-02 18:55:29 -05:00
bool bRetVal = ( self - > * Func1 ) ( ItemX , ItemY , ItemZ , Callback ) ;
2013-08-05 09:41:24 -04:00
/* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , TableRef ) ;
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , FuncRef ) ;
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
/* Push return value on stack */
2014-07-21 09:19:48 -04:00
tolua_pushboolean ( tolua_S , bRetVal ) ;
2013-08-05 09:41:24 -04:00
return 1 ;
2013-02-02 18:55:29 -05:00
}
2012-09-02 09:34:59 -04:00
2012-08-22 19:05:12 -04:00
2014-08-28 09:44:36 -04:00
template <
2014-07-17 16:50:58 -04:00
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * Func1 ) ( int , int , cItemCallback < Ty2 > & )
>
static int tolua_ForEachInChunk ( lua_State * tolua_S )
2013-02-02 18:55:29 -05:00
{
2013-08-05 09:41:24 -04:00
int NumArgs = lua_gettop ( tolua_S ) - 1 ; /* This includes 'self' */
if ( ( NumArgs ! = 3 ) & & ( NumArgs ! = 4 ) )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Requires 3 or 4 arguments, got %i " , NumArgs ) ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2014-10-20 16:55:07 -04:00
Ty1 * self = ( Ty1 * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-08-05 09:41:24 -04:00
if ( ! lua_isnumber ( tolua_S , 2 ) | | ! lua_isnumber ( tolua_S , 3 ) )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a number for parameters #1 and #2 " ) ;
2013-08-05 09:41:24 -04:00
}
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
int ChunkX = ( ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ) ;
int ChunkZ = ( ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ) ;
2013-02-02 18:55:29 -05:00
2015-04-19 04:57:41 -04:00
if ( ! lua_isfunction ( tolua_S , 4 ) )
2013-08-05 09:41:24 -04:00
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a function for parameter #3 " ) ;
2013-08-05 09:41:24 -04:00
}
/* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
int TableRef = LUA_REFNIL ;
if ( NumArgs = = 4 )
{
TableRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( TableRef = = LUA_REFNIL )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get value reference of parameter #4 " ) ;
2013-08-05 09:41:24 -04:00
}
}
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
/* table value is popped, and now function is on top of the stack */
int FuncRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FuncRef = = LUA_REFNIL )
{
2013-02-02 18:55:29 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get function reference of parameter #3 " ) ;
2013-08-05 09:41:24 -04:00
}
class cLuaCallback : public cItemCallback < Ty2 >
{
public :
2015-04-19 04:57:41 -04:00
cLuaCallback ( lua_State * a_LuaState , int a_FuncRef , int a_TableRef ) :
LuaState ( a_LuaState ) ,
FuncRef ( a_FuncRef ) ,
TableRef ( a_TableRef )
{
}
2013-08-05 09:41:24 -04:00
private :
virtual bool Item ( Ty2 * a_Item ) override
{
2015-04-19 04:57:41 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , FuncRef ) ; /* Push function reference */
2013-08-05 09:41:24 -04:00
tolua_pushusertype ( LuaState , a_Item , Ty2 : : GetClassStatic ( ) ) ;
if ( TableRef ! = LUA_REFNIL )
{
2015-04-19 04:57:41 -04:00
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , TableRef ) ; /* Push table reference */
2013-08-05 09:41:24 -04:00
}
int s = lua_pcall ( LuaState , ( TableRef = = LUA_REFNIL ? 1 : 2 ) , 1 , 0 ) ;
2013-08-05 10:02:41 -04:00
if ( cLuaState : : ReportErrors ( LuaState , s ) )
2013-08-05 09:41:24 -04:00
{
return true ; /* Abort enumeration */
}
if ( lua_isboolean ( LuaState , - 1 ) )
{
return ( tolua_toboolean ( LuaState , - 1 , 0 ) > 0 ) ;
}
return false ; /* Continue enumeration */
}
lua_State * LuaState ;
int FuncRef ;
int TableRef ;
} Callback ( tolua_S , FuncRef , TableRef ) ;
2013-02-02 18:55:29 -05:00
bool bRetVal = ( self - > * Func1 ) ( ChunkX , ChunkZ , Callback ) ;
2013-08-05 09:41:24 -04:00
/* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , TableRef ) ;
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , FuncRef ) ;
2013-02-02 18:55:29 -05:00
2013-08-05 09:41:24 -04:00
/* Push return value on stack */
2014-07-21 09:19:48 -04:00
tolua_pushboolean ( tolua_S , bRetVal ) ;
2013-08-05 09:41:24 -04:00
return 1 ;
2012-06-16 04:35:07 -04:00
}
2014-09-03 11:01:23 -04:00
template <
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * Func1 ) ( const cBoundingBox & , cItemCallback < Ty2 > & )
>
static int tolua_ForEachInBox ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cWorld " ) | |
! L . CheckParamUserType ( 2 , " cBoundingBox " ) | |
! L . CheckParamFunction ( 3 ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Get the params:
2014-10-20 16:55:07 -04:00
Ty1 * Self = nullptr ;
cBoundingBox * Box = nullptr ;
2014-09-03 11:01:23 -04:00
L . GetStackValues ( 1 , Self , Box ) ;
2014-10-20 16:55:07 -04:00
if ( ( Self = = nullptr ) | | ( Box = = nullptr ) )
2014-10-06 07:48:44 -04:00
{
LOGWARNING ( " Invalid world (%p) or boundingbox (%p) " , Self , Box ) ;
L . LogStackTrace ( ) ;
return 0 ;
}
2014-09-03 11:01:23 -04:00
// Create a reference for the function:
cLuaState : : cRef FnRef ( L , 3 ) ;
// Callback wrapper for the Lua function:
class cLuaCallback : public cItemCallback < Ty2 >
{
public :
cLuaCallback ( cLuaState & a_LuaState , cLuaState : : cRef & a_FuncRef ) :
m_LuaState ( a_LuaState ) ,
m_FnRef ( a_FuncRef )
2015-04-19 04:57:41 -04:00
{
}
2014-09-03 11:01:23 -04:00
private :
2015-04-23 13:41:01 -04:00
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
2014-09-03 11:01:23 -04:00
// cItemCallback<Ty2> overrides:
virtual bool Item ( Ty2 * a_Item ) override
{
bool res = false ;
if ( ! m_LuaState . Call ( m_FnRef , a_Item , cLuaState : : Return , res ) )
{
LOGWARNING ( " Failed to call Lua callback " ) ;
m_LuaState . LogStackTrace ( ) ;
return true ; // Abort enumeration
}
return res ;
}
} Callback ( L , FnRef ) ;
bool bRetVal = ( Self - > * Func1 ) ( * Box , Callback ) ;
FnRef . UnRef ( ) ;
/* Push return value on stack */
tolua_pushboolean ( tolua_S , bRetVal ) ;
return 1 ;
}
2014-08-28 09:44:36 -04:00
template <
2014-07-17 16:50:58 -04:00
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * Func1 ) ( cItemCallback < Ty2 > & )
>
2013-02-02 18:55:29 -05:00
static int tolua_ForEach ( lua_State * tolua_S )
{
2015-04-23 13:41:01 -04:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamFunction ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
return 0 ;
2013-02-02 18:55:29 -05:00
}
2015-04-23 13:41:01 -04:00
// Get the params:
Ty1 * self ;
L . GetStackValues ( 1 , self ) ;
cLuaState : : cRef FnRef ( L , 2 ) ;
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Invalid 'self'. " ) ;
2013-02-02 18:55:29 -05:00
}
2015-04-23 13:41:01 -04:00
class cLuaCallback : public cItemCallback < Ty2 >
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
public :
cLuaCallback ( cLuaState & a_LuaState , cLuaState : : cRef & a_FnRef ) :
m_LuaState ( a_LuaState ) ,
m_FnRef ( a_FnRef )
{
}
2012-06-14 09:06:06 -04:00
2015-04-23 13:41:01 -04:00
private :
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
virtual bool Item ( Ty2 * a_Item ) override
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
bool res = false ; // By default continue the enumeration
m_LuaState . Call ( m_FnRef , a_Item , cLuaState : : Return , res ) ;
return res ;
2013-02-02 18:55:29 -05:00
}
2015-04-23 13:41:01 -04:00
} Callback ( L , FnRef ) ;
2012-06-14 09:06:06 -04:00
2015-04-23 13:41:01 -04:00
// Call the enumeration:
bool res = ( self - > * Func1 ) ( Callback ) ;
// Push the return value:
L . Push ( res ) ;
return 1 ;
}
/** Implements bindings for ForEach() functions in a class that is static (has a ::Get() static function). */
template <
class Ty1 ,
class Ty2 ,
bool ( Ty1 : : * Func1 ) ( cItemCallback < Ty2 > & )
>
static int tolua_StaticForEach ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamFunction ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
2013-02-02 18:55:29 -05:00
{
2015-04-23 13:41:01 -04:00
return 0 ;
2013-02-02 18:55:29 -05:00
}
2012-06-14 09:06:06 -04:00
2015-04-23 13:41:01 -04:00
// Get the params:
cLuaState : : cRef FnRef ( L , 2 ) ;
2013-02-02 18:55:29 -05:00
class cLuaCallback : public cItemCallback < Ty2 >
{
public :
2015-04-23 13:41:01 -04:00
cLuaCallback ( cLuaState & a_LuaState , cLuaState : : cRef & a_FnRef ) :
m_LuaState ( a_LuaState ) ,
m_FnRef ( a_FnRef )
2015-04-19 04:57:41 -04:00
{
}
2013-02-02 18:55:29 -05:00
private :
2015-04-23 13:41:01 -04:00
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
2013-02-02 18:55:29 -05:00
virtual bool Item ( Ty2 * a_Item ) override
{
2015-04-23 13:41:01 -04:00
bool res = false ; // By default continue the enumeration
m_LuaState . Call ( m_FnRef , a_Item , cLuaState : : Return , res ) ;
return res ;
2013-02-02 18:55:29 -05:00
}
2015-04-23 13:41:01 -04:00
} Callback ( L , FnRef ) ;
2012-09-02 09:34:59 -04:00
2015-04-23 13:41:01 -04:00
// Call the enumeration:
bool res = ( Ty1 : : Get ( ) - > * Func1 ) ( Callback ) ;
2012-06-14 09:06:06 -04:00
2015-04-23 13:41:01 -04:00
// Push the return value:
L . Push ( res ) ;
2013-02-02 18:55:29 -05:00
return 1 ;
}
2012-06-17 02:57:13 -04:00
2012-06-14 09:06:06 -04:00
2013-09-15 14:29:20 -04:00
static int tolua_cWorld_GetBlockInfo ( lua_State * tolua_S )
{
// Exported manually, because tolua would generate useless additional parameters (a_BlockType .. a_BlockSkyLight)
// Function signature: GetBlockInfo(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta, BlockSkyLight, BlockBlockLight]
# ifndef TOLUA_RELEASE
tolua_Error tolua_err ;
if (
! tolua_isusertype ( tolua_S , 1 , " cWorld " , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 2 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 3 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 4 , 0 , & tolua_err ) | |
! tolua_isnoobj ( tolua_S , 5 , & tolua_err )
)
goto tolua_lerror ;
else
# endif
{
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-09-15 14:29:20 -04:00
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
# ifndef TOLUA_RELEASE
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-09-15 14:29:20 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'GetBlockInfo' " , nullptr ) ;
2013-09-15 14:29:20 -04:00
}
# endif
{
BLOCKTYPE BlockType ;
NIBBLETYPE BlockMeta , BlockSkyLight , BlockBlockLight ;
bool res = self - > GetBlockInfo ( BlockX , BlockY , BlockZ , BlockType , BlockMeta , BlockSkyLight , BlockBlockLight ) ;
tolua_pushboolean ( tolua_S , res ? 1 : 0 ) ;
if ( res )
{
tolua_pushnumber ( tolua_S , BlockType ) ;
tolua_pushnumber ( tolua_S , BlockMeta ) ;
tolua_pushnumber ( tolua_S , BlockSkyLight ) ;
tolua_pushnumber ( tolua_S , BlockBlockLight ) ;
return 5 ;
}
}
}
return 1 ;
# ifndef TOLUA_RELEASE
tolua_lerror :
tolua_error ( tolua_S , " #ferror in function 'GetBlockInfo'. " , & tolua_err ) ;
return 0 ;
# endif
}
static int tolua_cWorld_GetBlockTypeMeta ( lua_State * tolua_S )
{
// Exported manually, because tolua would generate useless additional parameters (a_BlockType, a_BlockMeta)
// Function signature: GetBlockTypeMeta(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta]
# ifndef TOLUA_RELEASE
tolua_Error tolua_err ;
if (
! tolua_isusertype ( tolua_S , 1 , " cWorld " , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 2 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 3 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 4 , 0 , & tolua_err ) | |
! tolua_isnoobj ( tolua_S , 5 , & tolua_err )
)
goto tolua_lerror ;
else
# endif
{
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-09-15 14:29:20 -04:00
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
# ifndef TOLUA_RELEASE
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-09-15 14:29:20 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'GetBlockTypeMeta' " , nullptr ) ;
2013-09-15 14:29:20 -04:00
}
# endif
{
BLOCKTYPE BlockType ;
NIBBLETYPE BlockMeta ;
bool res = self - > GetBlockTypeMeta ( BlockX , BlockY , BlockZ , BlockType , BlockMeta ) ;
tolua_pushboolean ( tolua_S , res ? 1 : 0 ) ;
if ( res )
{
tolua_pushnumber ( tolua_S , BlockType ) ;
tolua_pushnumber ( tolua_S , BlockMeta ) ;
return 3 ;
}
}
}
return 1 ;
# ifndef TOLUA_RELEASE
tolua_lerror :
tolua_error ( tolua_S , " #ferror in function 'GetBlockTypeMeta'. " , & tolua_err ) ;
return 0 ;
# endif
}
2013-09-15 15:47:56 -04:00
static int tolua_cWorld_GetSignLines ( lua_State * tolua_S )
{
// Exported manually, because tolua would generate useless additional parameters (a_Line1 .. a_Line4)
# ifndef TOLUA_RELEASE
tolua_Error tolua_err ;
if (
! tolua_isusertype ( tolua_S , 1 , " cWorld " , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 2 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 3 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 4 , 0 , & tolua_err ) | |
! tolua_isnoobj ( tolua_S , 10 , & tolua_err )
)
goto tolua_lerror ;
else
# endif
{
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-09-15 15:47:56 -04:00
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
# ifndef TOLUA_RELEASE
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-09-15 15:47:56 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'GetSignLines' " , nullptr ) ;
2013-09-15 15:47:56 -04:00
}
# endif
{
AString Line1 , Line2 , Line3 , Line4 ;
2013-09-15 15:52:25 -04:00
bool res = self - > GetSignLines ( BlockX , BlockY , BlockZ , Line1 , Line2 , Line3 , Line4 ) ;
2013-09-15 15:47:56 -04:00
tolua_pushboolean ( tolua_S , res ? 1 : 0 ) ;
if ( res )
{
tolua_pushstring ( tolua_S , Line1 . c_str ( ) ) ;
tolua_pushstring ( tolua_S , Line2 . c_str ( ) ) ;
tolua_pushstring ( tolua_S , Line3 . c_str ( ) ) ;
tolua_pushstring ( tolua_S , Line4 . c_str ( ) ) ;
return 5 ;
}
}
}
return 1 ;
# ifndef TOLUA_RELEASE
tolua_lerror :
tolua_error ( tolua_S , " #ferror in function 'GetSignLines'. " , & tolua_err ) ;
return 0 ;
# endif
}
2013-06-12 03:14:06 -04:00
static int tolua_cWorld_SetSignLines ( lua_State * tolua_S )
{
// Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4)
# ifndef TOLUA_RELEASE
tolua_Error tolua_err ;
if (
! tolua_isusertype ( tolua_S , 1 , " cWorld " , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 2 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 3 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 4 , 0 , & tolua_err ) | |
! tolua_iscppstring ( tolua_S , 5 , 0 , & tolua_err ) | |
! tolua_iscppstring ( tolua_S , 6 , 0 , & tolua_err ) | |
! tolua_iscppstring ( tolua_S , 7 , 0 , & tolua_err ) | |
! tolua_iscppstring ( tolua_S , 8 , 0 , & tolua_err ) | |
! tolua_isusertype ( tolua_S , 9 , " cPlayer " , 1 , & tolua_err ) | |
! tolua_isnoobj ( tolua_S , 10 , & tolua_err )
)
goto tolua_lerror ;
else
# endif
{
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-06-12 03:14:06 -04:00
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
const AString Line1 = tolua_tocppstring ( tolua_S , 5 , 0 ) ;
const AString Line2 = tolua_tocppstring ( tolua_S , 6 , 0 ) ;
const AString Line3 = tolua_tocppstring ( tolua_S , 7 , 0 ) ;
const AString Line4 = tolua_tocppstring ( tolua_S , 8 , 0 ) ;
2014-10-20 16:55:07 -04:00
cPlayer * Player = ( cPlayer * ) tolua_tousertype ( tolua_S , 9 , nullptr ) ;
2013-06-12 03:14:06 -04:00
# ifndef TOLUA_RELEASE
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-06-12 03:14:06 -04:00
{
2014-11-17 08:57:24 -05:00
tolua_error ( tolua_S , " invalid 'self' in function 'SetSignLines' " , nullptr ) ;
2013-06-12 03:14:06 -04:00
}
# endif
{
2014-11-15 09:16:52 -05:00
bool res = self - > SetSignLines ( BlockX , BlockY , BlockZ , Line1 , Line2 , Line3 , Line4 , Player ) ;
2013-06-12 03:14:06 -04:00
tolua_pushboolean ( tolua_S , res ? 1 : 0 ) ;
}
}
return 1 ;
# ifndef TOLUA_RELEASE
tolua_lerror :
2014-11-17 08:57:24 -05:00
tolua_error ( tolua_S , " #ferror in function 'SetSignLines'. " , & tolua_err ) ;
2013-06-12 03:14:06 -04:00
return 0 ;
# endif
}
2013-08-05 09:54:10 -04:00
static int tolua_cWorld_TryGetHeight ( lua_State * tolua_S )
{
// Exported manually, because tolua would require the out-only param a_Height to be used when calling
2014-07-19 08:53:41 -04:00
// Takes a_World, a_BlockX, a_BlockZ
2013-08-05 09:54:10 -04:00
// Returns Height, IsValid
# ifndef TOLUA_RELEASE
tolua_Error tolua_err ;
if (
! tolua_isusertype ( tolua_S , 1 , " cWorld " , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 2 , 0 , & tolua_err ) | |
! tolua_isnumber ( tolua_S , 3 , 0 , & tolua_err ) | |
! tolua_isnoobj ( tolua_S , 4 , & tolua_err )
)
goto tolua_lerror ;
else
# endif
{
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-08-05 09:54:10 -04:00
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
# ifndef TOLUA_RELEASE
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-08-05 09:54:10 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " Invalid 'self' in function 'TryGetHeight' " , nullptr ) ;
2013-08-05 09:54:10 -04:00
}
# endif
{
int Height = 0 ;
bool res = self - > TryGetHeight ( BlockX , BlockZ , Height ) ;
tolua_pushboolean ( tolua_S , res ? 1 : 0 ) ;
2014-02-08 07:35:08 -05:00
if ( res )
{
tolua_pushnumber ( tolua_S , Height ) ;
return 2 ;
}
2013-08-05 09:54:10 -04:00
}
}
return 1 ;
# ifndef TOLUA_RELEASE
tolua_lerror :
tolua_error ( tolua_S , " #ferror in function 'TryGetHeight'. " , & tolua_err ) ;
return 0 ;
# endif
}
2013-10-12 16:24:59 -04:00
class cLuaWorldTask :
2015-03-20 10:13:33 -04:00
public cWorld : : cTask ,
public cPluginLua : : cResettable
2013-10-12 16:24:59 -04:00
{
public :
cLuaWorldTask ( cPluginLua & a_Plugin , int a_FnRef ) :
2015-03-20 10:13:33 -04:00
cPluginLua : : cResettable ( a_Plugin ) ,
2013-10-12 16:24:59 -04:00
m_FnRef ( a_FnRef )
{
}
protected :
int m_FnRef ;
// cWorld::cTask overrides:
virtual void Run ( cWorld & a_World ) override
{
2015-03-20 10:13:33 -04:00
cCSLock Lock ( m_CSPlugin ) ;
if ( m_Plugin ! = nullptr )
{
m_Plugin - > Call ( m_FnRef , & a_World ) ;
}
2013-10-12 16:24:59 -04:00
}
} ;
2014-01-16 13:56:08 -05:00
2013-10-12 16:24:59 -04:00
static int tolua_cWorld_QueueTask ( lua_State * tolua_S )
{
// Binding for cWorld::QueueTask
// Params: function
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = GetLuaPlugin ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-10-12 16:24:59 -04:00
{
// An error message has been already printed in GetLuaPlugin()
return 0 ;
}
// Retrieve the args:
2014-10-20 16:55:07 -04:00
cWorld * self = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2013-10-12 16:24:59 -04:00
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Not called on an object instance " ) ;
}
if ( ! lua_isfunction ( tolua_S , 2 ) )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Expected a function for parameter #1 " ) ;
}
// Create a reference to the function:
int FnRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FnRef = = LUA_REFNIL )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get function reference of parameter #1 " ) ;
}
2015-03-20 10:13:33 -04:00
auto task = std : : make_shared < cLuaWorldTask > ( * Plugin , FnRef ) ;
Plugin - > AddResettable ( task ) ;
self - > QueueTask ( task ) ;
2013-10-12 16:24:59 -04:00
return 0 ;
}
2014-01-16 13:56:08 -05:00
2014-01-14 15:17:03 -05:00
class cLuaScheduledWorldTask :
2015-03-20 10:13:33 -04:00
public cWorld : : cTask ,
public cPluginLua : : cResettable
2014-01-14 15:17:03 -05:00
{
public :
2014-01-19 17:49:19 -05:00
cLuaScheduledWorldTask ( cPluginLua & a_Plugin , int a_FnRef ) :
2015-03-20 10:13:33 -04:00
cPluginLua : : cResettable ( a_Plugin ) ,
2014-01-14 15:17:03 -05:00
m_FnRef ( a_FnRef )
{
}
protected :
int m_FnRef ;
// cWorld::cTask overrides:
virtual void Run ( cWorld & a_World ) override
{
2015-03-20 10:13:33 -04:00
cCSLock Lock ( m_CSPlugin ) ;
if ( m_Plugin ! = nullptr )
{
m_Plugin - > Call ( m_FnRef , & a_World ) ;
}
2014-01-14 15:17:03 -05:00
}
} ;
2014-01-16 13:56:08 -05:00
2014-01-14 15:17:03 -05:00
static int tolua_cWorld_ScheduleTask ( lua_State * tolua_S )
{
// Binding for cWorld::ScheduleTask
// Params: function, Ticks
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = GetLuaPlugin ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2014-01-14 15:17:03 -05:00
{
// An error message has been already printed in GetLuaPlugin()
return 0 ;
}
// Retrieve the args:
2014-01-19 17:49:19 -05:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cWorld " ) | |
! L . CheckParamNumber ( 2 ) | |
! L . CheckParamFunction ( 3 )
)
2014-01-14 15:17:03 -05:00
{
2014-01-19 17:49:19 -05:00
return 0 ;
2014-01-14 15:17:03 -05:00
}
2014-10-20 16:55:07 -04:00
cWorld * World = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( World = = nullptr )
2014-01-14 15:17:03 -05:00
{
2014-01-19 17:49:19 -05:00
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Not called on an object instance " ) ;
2014-01-14 15:17:03 -05:00
}
// Create a reference to the function:
int FnRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FnRef = = LUA_REFNIL )
{
return lua_do_error ( tolua_S , " Error in function call '#funcname#': Could not get function reference of parameter #1 " ) ;
}
2014-01-19 17:49:19 -05:00
int DelayTicks = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
2013-10-12 16:24:59 -04:00
2015-03-20 10:13:33 -04:00
auto task = std : : make_shared < cLuaScheduledWorldTask > ( * Plugin , FnRef ) ;
Plugin - > AddResettable ( task ) ;
World - > ScheduleTask ( DelayTicks , task ) ;
2014-01-14 15:17:03 -05:00
return 0 ;
}
2013-10-12 16:24:59 -04:00
2014-01-16 13:56:08 -05:00
2013-02-15 08:00:59 -05:00
static int tolua_cPluginManager_GetAllPlugins ( lua_State * tolua_S )
{
2015-04-19 04:57:41 -04:00
// API function no longer available:
LOGWARNING ( " cPluginManager:GetAllPlugins() is no longer available, use cPluginManager:ForEachPlugin() instead " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
2013-02-15 08:00:59 -05:00
2015-04-19 04:57:41 -04:00
// Return an empty table:
2013-02-15 08:00:59 -05:00
lua_newtable ( tolua_S ) ;
return 1 ;
}
2013-12-05 16:03:07 -05:00
static int tolua_cPluginManager_GetCurrentPlugin ( lua_State * S )
{
cPluginLua * Plugin = GetLuaPlugin ( S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-12-05 16:03:07 -05:00
{
// An error message has already been printed in GetLuaPlugin()
return 0 ;
}
tolua_pushusertype ( S , Plugin , " cPluginLua " ) ;
return 1 ;
}
2015-04-19 04:57:41 -04:00
static int tolua_cPluginManager_GetPlugin ( lua_State * tolua_S )
{
// API function no longer available:
LOGWARNING ( " cPluginManager:GetPlugin() is no longer available. Use cPluginManager:DoWithPlugin() or cPluginManager:CallPlugin() instead. " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return 0 ;
}
2014-02-04 18:16:33 -05:00
static int tolua_cPluginManager_LogStackTrace ( lua_State * S )
{
cLuaState : : LogStackTrace ( S ) ;
return 0 ;
}
2013-08-21 15:29:30 -04:00
static int tolua_cPluginManager_AddHook_FnRef ( cPluginManager * a_PluginManager , cLuaState & S , int a_ParamIdx )
{
// Helper function for cPluginmanager:AddHook() binding
// Takes care of the new case (#121): args are HOOK_TYPE and CallbackFunction
// The arg types have already been checked
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = GetLuaPlugin ( S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-08-21 15:29:30 -04:00
{
// An error message has been already printed in GetLuaPlugin()
return 0 ;
}
// Retrieve and check the hook type
int HookType = ( int ) tolua_tonumber ( S , a_ParamIdx , - 1 ) ;
if ( ! a_PluginManager - > IsValidHookType ( HookType ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Invalid HOOK_TYPE parameter: %d " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
// Add the hook to the plugin
if ( ! Plugin - > AddHookRef ( HookType , a_ParamIdx + 1 ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Cannot add hook %d, unknown error. " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
a_PluginManager - > AddHook ( Plugin , HookType ) ;
// Success
return 0 ;
}
static int tolua_cPluginManager_AddHook_DefFn ( cPluginManager * a_PluginManager , cLuaState & S , int a_ParamIdx )
{
// Helper function for cPluginmanager:AddHook() binding
// Takes care of the old case (#121): args are cPluginLua and HOOK_TYPE
// The arg types have already been checked
// Retrieve and check the cPlugin parameter
2014-10-20 16:55:07 -04:00
cPluginLua * Plugin = ( cPluginLua * ) tolua_tousertype ( S , a_ParamIdx , nullptr ) ;
if ( Plugin = = nullptr )
2013-08-21 15:29:30 -04:00
{
LOGWARNING ( " cPluginManager.AddHook(): Invalid Plugin parameter, expected a valid cPlugin object. Hook not added " ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
if ( Plugin ! = GetLuaPlugin ( S ) )
{
// The plugin parameter passed to us is not our stored plugin. Disallow this!
LOGWARNING ( " cPluginManager.AddHook(): Invalid Plugin parameter, cannot add hook to foreign plugins. Hook not added. " ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
// Retrieve and check the hook type
int HookType = ( int ) tolua_tonumber ( S , a_ParamIdx + 1 , - 1 ) ;
if ( ! a_PluginManager - > IsValidHookType ( HookType ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Invalid HOOK_TYPE parameter: %d " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
// Get the standard name for the callback function:
const char * FnName = cPluginLua : : GetHookFnName ( HookType ) ;
2014-10-20 16:55:07 -04:00
if ( FnName = = nullptr )
2013-08-21 15:29:30 -04:00
{
LOGWARNING ( " cPluginManager.AddHook(): Unknown hook type (%d). Hook not added. " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
// Retrieve the function to call and add it to the plugin:
lua_pushstring ( S , FnName ) ;
bool res = Plugin - > AddHookRef ( HookType , 1 ) ;
lua_pop ( S , 1 ) ; // Pop the function off the stack
if ( ! res )
{
LOGWARNING ( " cPluginManager.AddHook(): Function %s not found. Hook not added. " , FnName ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
a_PluginManager - > AddHook ( Plugin , HookType ) ;
// Success
return 0 ;
}
static int tolua_cPluginManager_AddHook ( lua_State * tolua_S )
{
/*
Function signatures :
2014-01-05 09:46:45 -05:00
cPluginManager : AddHook ( HOOK_TYPE , CallbackFunction ) - - ( 1 ) recommended
cPluginManager . AddHook ( HOOK_TYPE , CallbackFunction ) - - ( 2 ) accepted silently ( # 401 deprecates this )
cPluginManager : Get ( ) : AddHook ( HOOK_TYPE , CallbackFunction ) - - ( 3 ) accepted silently
cPluginManager : Get ( ) : AddHook ( Plugin , HOOK_TYPE ) - - ( 4 ) old style ( # 121 ) , accepted but complained about in the console
cPluginManager . AddHook ( Plugin , HOOK_TYPE ) - - ( 5 ) old style ( # 121 ) mangled , accepted but complained about in the console
2013-08-21 15:29:30 -04:00
*/
cLuaState S ( tolua_S ) ;
cPluginManager * PlgMgr = cPluginManager : : Get ( ) ;
2014-01-05 09:46:45 -05:00
// If the first param is a cPluginManager instance, use it instead of the global one:
2013-08-21 15:29:30 -04:00
int ParamIdx = 1 ;
tolua_Error err ;
if ( tolua_isusertype ( S , 1 , " cPluginManager " , 0 , & err ) )
{
// Style 2 or 3, retrieve the PlgMgr instance
2014-10-20 16:55:07 -04:00
PlgMgr = ( cPluginManager * ) tolua_tousertype ( S , 1 , nullptr ) ;
if ( PlgMgr = = nullptr )
2013-08-21 15:29:30 -04:00
{
LOGWARNING ( " Malformed plugin, use cPluginManager.AddHook(HOOK_TYPE, CallbackFunction). Fixing the call for you. " ) ;
S . LogStackTrace ( ) ;
PlgMgr = cPluginManager : : Get ( ) ;
}
ParamIdx + = 1 ;
}
2014-01-05 09:46:45 -05:00
else if ( tolua_isusertable ( S , 1 , " cPluginManager " , 0 , & err ) )
{
// Style 1, use the global PlgMgr, but increment ParamIdx
ParamIdx + + ;
}
2013-08-21 15:29:30 -04:00
if ( lua_isnumber ( S , ParamIdx ) & & lua_isfunction ( S , ParamIdx + 1 ) )
{
// The next params are a number and a function, assume style 1 or 2
return tolua_cPluginManager_AddHook_FnRef ( PlgMgr , S , ParamIdx ) ;
}
else if ( tolua_isusertype ( S , ParamIdx , " cPlugin " , 0 , & err ) & & lua_isnumber ( S , ParamIdx + 1 ) )
{
// The next params are a cPlugin and a number, assume style 3 or 4
2013-08-21 15:32:40 -04:00
LOGINFO ( " cPluginManager.AddHook(): Deprecated format used, use cPluginManager.AddHook(HOOK_TYPE, CallbackFunction) instead. Fixing the call for you. " ) ;
2013-08-21 15:41:34 -04:00
S . LogStackTrace ( ) ;
2013-08-21 15:29:30 -04:00
return tolua_cPluginManager_AddHook_DefFn ( PlgMgr , S , ParamIdx ) ;
}
AString ParamDesc ;
Printf ( ParamDesc , " %s, %s, %s " , S . GetTypeText ( 1 ) . c_str ( ) , S . GetTypeText ( 2 ) . c_str ( ) , S . GetTypeText ( 3 ) . c_str ( ) ) ;
2014-01-05 09:46:45 -05:00
LOGWARNING ( " cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added. " , ParamDesc . c_str ( ) ) ;
2013-08-21 15:29:30 -04:00
S . LogStackTrace ( ) ;
return 0 ;
}
2013-02-01 14:55:42 -05:00
static int tolua_cPluginManager_ForEachCommand ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
int NumArgs = lua_gettop ( tolua_S ) - 1 ; /* This includes 'self' */
2014-07-20 17:10:31 -04:00
if ( NumArgs ! = 1 )
2013-02-01 14:55:42 -05:00
{
LOGWARN ( " Error in function call 'ForEachCommand': Requires 1 argument, got %i " , NumArgs ) ;
return 0 ;
}
2012-06-14 09:06:06 -04:00
2014-10-20 16:55:07 -04:00
cPluginManager * self = ( cPluginManager * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2013-02-01 14:55:42 -05:00
{
LOGWARN ( " Error in function call 'ForEachCommand': Not called on an object instance " ) ;
return 0 ;
}
2012-06-14 09:06:06 -04:00
2013-02-01 14:55:42 -05:00
if ( ! lua_isfunction ( tolua_S , 2 ) )
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
LOGWARN ( " Error in function call 'ForEachCommand': Expected a function for parameter #1 " ) ;
return 0 ;
2012-06-14 09:06:06 -04:00
}
2013-02-01 14:55:42 -05:00
int FuncRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FuncRef = = LUA_REFNIL )
{
LOGWARN ( " Error in function call 'ForEachCommand': Could not get function reference of parameter #1 " ) ;
return 0 ;
}
class cLuaCallback : public cPluginManager : : cCommandEnumCallback
{
public :
2015-04-19 04:57:41 -04:00
cLuaCallback ( lua_State * a_LuaState , int a_FuncRef ) :
LuaState ( a_LuaState ) ,
FuncRef ( a_FuncRef )
{
}
2013-02-01 14:55:42 -05:00
private :
virtual bool Command ( const AString & a_Command , const cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString ) override
{
2014-02-26 15:37:38 -05:00
UNUSED ( a_Plugin ) ;
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , FuncRef ) ; /* Push function reference */
2013-02-01 14:55:42 -05:00
tolua_pushcppstring ( LuaState , a_Command ) ;
tolua_pushcppstring ( LuaState , a_Permission ) ;
tolua_pushcppstring ( LuaState , a_HelpString ) ;
int s = lua_pcall ( LuaState , 3 , 1 , 0 ) ;
2013-08-04 17:11:25 -04:00
if ( cLuaState : : ReportErrors ( LuaState , s ) )
2013-02-01 14:55:42 -05:00
{
return true ; /* Abort enumeration */
}
if ( lua_isboolean ( LuaState , - 1 ) )
{
2015-04-19 04:57:41 -04:00
return ( tolua_toboolean ( LuaState , - 1 , 0 ) > 0 ) ;
2013-02-01 14:55:42 -05:00
}
return false ; /* Continue enumeration */
}
lua_State * LuaState ;
int FuncRef ;
} Callback ( tolua_S , FuncRef ) ;
bool bRetVal = self - > ForEachCommand ( Callback ) ;
/* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , FuncRef ) ;
/* Push return value on stack */
tolua_pushboolean ( tolua_S , bRetVal ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2013-02-15 08:00:59 -05:00
static int tolua_cPluginManager_ForEachConsoleCommand ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2013-02-15 08:00:59 -05:00
int NumArgs = lua_gettop ( tolua_S ) - 1 ; /* This includes 'self' */
2014-07-20 17:10:31 -04:00
if ( NumArgs ! = 1 )
2013-02-15 08:00:59 -05:00
{
LOGWARN ( " Error in function call 'ForEachConsoleCommand': Requires 1 argument, got %i " , NumArgs ) ;
return 0 ;
}
2012-06-14 09:06:06 -04:00
2014-10-20 16:55:07 -04:00
cPluginManager * self = ( cPluginManager * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2013-02-15 08:00:59 -05:00
{
LOGWARN ( " Error in function call 'ForEachConsoleCommand': Not called on an object instance " ) ;
return 0 ;
}
2012-06-14 09:06:06 -04:00
2013-02-15 08:00:59 -05:00
if ( ! lua_isfunction ( tolua_S , 2 ) )
2012-06-14 09:06:06 -04:00
{
2013-02-15 08:00:59 -05:00
LOGWARN ( " Error in function call 'ForEachConsoleCommand': Expected a function for parameter #1 " ) ;
return 0 ;
}
int FuncRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( FuncRef = = LUA_REFNIL )
{
LOGWARN ( " Error in function call 'ForEachConsoleCommand': Could not get function reference of parameter #1 " ) ;
return 0 ;
}
class cLuaCallback : public cPluginManager : : cCommandEnumCallback
{
public :
2015-04-19 04:57:41 -04:00
cLuaCallback ( lua_State * a_LuaState , int a_FuncRef ) :
LuaState ( a_LuaState ) ,
FuncRef ( a_FuncRef )
{
}
2013-02-15 08:00:59 -05:00
private :
virtual bool Command ( const AString & a_Command , const cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString ) override
2012-10-13 19:34:47 -04:00
{
2014-02-26 15:37:38 -05:00
UNUSED ( a_Plugin ) ;
UNUSED ( a_Permission ) ;
lua_rawgeti ( LuaState , LUA_REGISTRYINDEX , FuncRef ) ; /* Push function reference */
2013-02-15 08:00:59 -05:00
tolua_pushcppstring ( LuaState , a_Command ) ;
tolua_pushcppstring ( LuaState , a_HelpString ) ;
int s = lua_pcall ( LuaState , 2 , 1 , 0 ) ;
2013-08-04 17:11:25 -04:00
if ( cLuaState : : ReportErrors ( LuaState , s ) )
2013-02-15 08:00:59 -05:00
{
return true ; /* Abort enumeration */
}
if ( lua_isboolean ( LuaState , - 1 ) )
{
2015-04-19 04:57:41 -04:00
return ( tolua_toboolean ( LuaState , - 1 , 0 ) > 0 ) ;
2013-02-15 08:00:59 -05:00
}
return false ; /* Continue enumeration */
2012-10-13 19:34:47 -04:00
}
2013-02-15 08:00:59 -05:00
lua_State * LuaState ;
int FuncRef ;
} Callback ( tolua_S , FuncRef ) ;
bool bRetVal = self - > ForEachConsoleCommand ( Callback ) ;
/* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , FuncRef ) ;
/* Push return value on stack */
tolua_pushboolean ( tolua_S , bRetVal ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2013-02-15 08:00:59 -05:00
2013-02-01 14:55:42 -05:00
static int tolua_cPluginManager_BindCommand ( lua_State * L )
{
2013-09-18 10:46:13 -04:00
/* Function signatures:
cPluginManager : BindCommand ( Command , Permission , Function , HelpString )
2013-09-18 10:50:05 -04:00
cPluginManager . BindCommand ( Command , Permission , Function , HelpString ) - - without the " self " param
2013-09-18 10:46:13 -04:00
*/
2013-08-19 03:39:18 -04:00
cPluginLua * Plugin = GetLuaPlugin ( L ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-02-01 14:55:42 -05:00
{
2013-05-30 15:34:09 -04:00
return 0 ;
2013-02-01 14:55:42 -05:00
}
// Read the arguments to this API call:
tolua_Error tolua_err ;
2013-09-18 10:46:13 -04:00
int idx = 1 ;
2014-01-31 03:19:46 -05:00
if (
tolua_isusertype ( L , 1 , " cPluginManager " , 0 , & tolua_err ) | |
tolua_isusertable ( L , 1 , " cPluginManager " , 0 , & tolua_err )
)
2013-09-18 10:46:13 -04:00
{
idx + + ;
}
2013-02-01 14:55:42 -05:00
if (
2013-09-18 10:46:13 -04:00
! tolua_iscppstring ( L , idx , 0 , & tolua_err ) | |
! tolua_iscppstring ( L , idx + 1 , 0 , & tolua_err ) | |
! tolua_iscppstring ( L , idx + 3 , 0 , & tolua_err ) | |
! tolua_isnoobj ( L , idx + 4 , & tolua_err )
2013-02-01 14:55:42 -05:00
)
{
tolua_error ( L , " #ferror in function 'BindCommand'. " , & tolua_err ) ;
return 0 ;
}
2013-09-18 10:46:13 -04:00
if ( ! lua_isfunction ( L , idx + 2 ) )
2013-02-01 14:55:42 -05:00
{
luaL_error ( L , " \" BindCommand \" function expects a function as its 3rd parameter. Command-binding aborted. " ) ;
return 0 ;
}
2013-09-18 10:46:13 -04:00
cPluginManager * self = cPluginManager : : Get ( ) ;
AString Command ( tolua_tocppstring ( L , idx , " " ) ) ;
AString Permission ( tolua_tocppstring ( L , idx + 1 , " " ) ) ;
AString HelpString ( tolua_tocppstring ( L , idx + 3 , " " ) ) ;
2013-02-01 14:55:42 -05:00
// Store the function reference:
lua_pop ( L , 1 ) ; // Pop the help string off the stack
int FnRef = luaL_ref ( L , LUA_REGISTRYINDEX ) ; // Store function reference
if ( FnRef = = LUA_REFNIL )
{
2013-02-02 11:16:35 -05:00
LOGERROR ( " \" BindCommand \" : Cannot create a function reference. Command \" %s \" not bound. " , Command . c_str ( ) ) ;
2013-02-01 14:55:42 -05:00
return 0 ;
}
if ( ! self - > BindCommand ( Command , Plugin , Permission , HelpString ) )
{
2013-11-13 09:54:56 -05:00
// Refused. Possibly already bound. Error message has been given, display the callstack:
cLuaState LS ( L ) ;
LS . LogStackTrace ( ) ;
2013-02-01 14:55:42 -05:00
return 0 ;
}
Plugin - > BindCommand ( Command , FnRef ) ;
2014-03-14 06:18:14 -04:00
lua_pushboolean ( L , true ) ;
return 1 ;
2013-02-01 14:55:42 -05:00
}
2012-06-14 09:06:06 -04:00
2013-02-15 08:00:59 -05:00
static int tolua_cPluginManager_BindConsoleCommand ( lua_State * L )
{
2013-09-18 10:50:05 -04:00
/* Function signatures:
cPluginManager : BindConsoleCommand ( Command , Function , HelpString )
cPluginManager . BindConsoleCommand ( Command , Function , HelpString ) - - without the " self " param
*/
2013-02-15 08:00:59 -05:00
// Get the plugin identification out of LuaState:
2013-09-18 10:50:05 -04:00
cPluginLua * Plugin = GetLuaPlugin ( L ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-02-15 08:00:59 -05:00
{
2013-09-18 10:50:05 -04:00
return 0 ;
2013-02-15 08:00:59 -05:00
}
// Read the arguments to this API call:
tolua_Error tolua_err ;
2013-09-18 10:50:05 -04:00
int idx = 1 ;
2014-03-14 09:37:39 -04:00
if (
tolua_isusertype ( L , 1 , " cPluginManager " , 0 , & tolua_err ) | |
tolua_isusertable ( L , 1 , " cPluginManager " , 0 , & tolua_err )
)
2013-09-18 10:50:05 -04:00
{
idx + + ;
}
2013-02-15 08:00:59 -05:00
if (
2013-09-18 10:50:05 -04:00
! tolua_iscppstring ( L , idx , 0 , & tolua_err ) | | // Command
! tolua_iscppstring ( L , idx + 2 , 0 , & tolua_err ) | | // HelpString
! tolua_isnoobj ( L , idx + 3 , & tolua_err )
2013-02-15 08:00:59 -05:00
)
{
tolua_error ( L , " #ferror in function 'BindConsoleCommand'. " , & tolua_err ) ;
return 0 ;
}
2013-09-18 10:50:05 -04:00
if ( ! lua_isfunction ( L , idx + 1 ) )
2013-02-15 08:00:59 -05:00
{
luaL_error ( L , " \" BindConsoleCommand \" function expects a function as its 2nd parameter. Command-binding aborted. " ) ;
return 0 ;
}
2013-09-18 10:50:05 -04:00
cPluginManager * self = cPluginManager : : Get ( ) ;
AString Command ( tolua_tocppstring ( L , idx , " " ) ) ;
AString HelpString ( tolua_tocppstring ( L , idx + 2 , " " ) ) ;
2013-02-15 08:00:59 -05:00
// Store the function reference:
lua_pop ( L , 1 ) ; // Pop the help string off the stack
int FnRef = luaL_ref ( L , LUA_REGISTRYINDEX ) ; // Store function reference
if ( FnRef = = LUA_REFNIL )
{
LOGERROR ( " \" BindConsoleCommand \" : Cannot create a function reference. Console Command \" %s \" not bound. " , Command . c_str ( ) ) ;
return 0 ;
}
if ( ! self - > BindConsoleCommand ( Command , Plugin , HelpString ) )
{
2013-11-13 09:54:56 -05:00
// Refused. Possibly already bound. Error message has been given, display the callstack:
cLuaState LS ( L ) ;
LS . LogStackTrace ( ) ;
2013-02-15 08:00:59 -05:00
return 0 ;
}
Plugin - > BindConsoleCommand ( Command , FnRef ) ;
2014-03-14 06:18:14 -04:00
lua_pushboolean ( L , true ) ;
return 1 ;
2013-02-15 08:00:59 -05:00
}
2014-01-21 16:59:08 -05:00
static int tolua_cPluginManager_CallPlugin ( lua_State * tolua_S )
{
/*
Function signature :
cPluginManager : CallPlugin ( " PluginName " , " FunctionName " , args . . . )
*/
// Check the parameters:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cPluginManager " ) | |
! L . CheckParamString ( 2 , 3 ) )
{
return 0 ;
}
// Retrieve the plugin name and function name
AString PluginName , FunctionName ;
L . ToString ( 2 , PluginName ) ;
L . ToString ( 3 , FunctionName ) ;
if ( PluginName . empty ( ) | | FunctionName . empty ( ) )
{
LOGWARNING ( " cPluginManager:CallPlugin(): Invalid plugin name or function name " ) ;
L . LogStackTrace ( ) ;
return 0 ;
}
// If requesting calling the current plugin, refuse:
cPluginLua * ThisPlugin = GetLuaPlugin ( L ) ;
2014-10-20 16:55:07 -04:00
if ( ThisPlugin = = nullptr )
2014-01-21 16:59:08 -05:00
{
return 0 ;
}
if ( ThisPlugin - > GetName ( ) = = PluginName )
{
LOGWARNING ( " cPluginManager::CallPlugin(): Calling self is not implemented (why would it?) " ) ;
L . LogStackTrace ( ) ;
return 0 ;
}
// Call the destination plugin using a plugin callback:
class cCallback :
public cPluginManager : : cPluginCallback
{
public :
int m_NumReturns ;
cCallback ( const AString & a_FunctionName , cLuaState & a_SrcLuaState ) :
2014-02-04 16:26:35 -05:00
m_NumReturns ( 0 ) ,
2014-01-21 16:59:08 -05:00
m_FunctionName ( a_FunctionName ) ,
2014-02-04 16:26:35 -05:00
m_SrcLuaState ( a_SrcLuaState )
2014-01-21 16:59:08 -05:00
{
}
protected :
const AString & m_FunctionName ;
cLuaState & m_SrcLuaState ;
virtual bool Item ( cPlugin * a_Plugin ) override
{
2015-04-19 04:57:41 -04:00
if ( ! a_Plugin - > IsLoaded ( ) )
{
return false ;
}
m_NumReturns = static_cast < cPluginLua * > ( a_Plugin ) - > CallFunctionFromForeignState (
2014-01-21 16:59:08 -05:00
m_FunctionName , m_SrcLuaState , 4 , lua_gettop ( m_SrcLuaState )
) ;
return true ;
}
} Callback ( FunctionName , L ) ;
if ( ! cPluginManager : : Get ( ) - > DoWithPlugin ( PluginName , Callback ) )
{
return 0 ;
}
return Callback . m_NumReturns ;
}
2015-04-19 04:57:41 -04:00
static int tolua_cPluginManager_FindPlugins ( lua_State * tolua_S )
{
// API function no longer exists:
LOGWARNING ( " cPluginManager:FindPlugins() is obsolete, use cPluginManager:RefreshPluginList() instead! " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
// Still, do the actual work performed by the API function when it existed:
cPluginManager : : Get ( ) - > RefreshPluginList ( ) ;
return 0 ;
}
2014-02-10 16:47:10 -05:00
static int tolua_cWorld_ChunkStay ( lua_State * tolua_S )
2014-02-09 14:39:45 -05:00
{
2014-02-10 16:47:10 -05:00
/* Function signature:
World : ChunkStay ( ChunkCoordTable , OnChunkAvailable , OnAllChunksAvailable )
ChunkCoordTable = = { { Chunk1x , Chunk1z } , { Chunk2x , Chunk2z } , . . . }
*/
2014-02-09 14:39:45 -05:00
cLuaState L ( tolua_S ) ;
if (
2014-02-11 09:04:35 -05:00
! L . CheckParamUserType ( 1 , " cWorld " ) | |
! L . CheckParamTable ( 2 ) | |
! L . CheckParamFunctionOrNil ( 3 , 4 )
2014-02-09 14:39:45 -05:00
)
{
return 0 ;
}
2014-02-10 16:47:10 -05:00
cPluginLua * Plugin = GetLuaPlugin ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2014-02-09 14:39:45 -05:00
{
return 0 ;
}
2014-02-10 16:47:10 -05:00
// Read the params:
2014-10-20 16:55:07 -04:00
cWorld * World = ( cWorld * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( World = = nullptr )
2014-02-09 14:39:45 -05:00
{
2014-02-10 16:47:10 -05:00
LOGWARNING ( " World:ChunkStay(): invalid world parameter " ) ;
2014-02-09 14:39:45 -05:00
L . LogStackTrace ( ) ;
return 0 ;
}
2014-04-25 19:35:25 -04:00
cLuaChunkStay * ChunkStay = new cLuaChunkStay ( * Plugin ) ;
2014-02-10 16:47:10 -05:00
if ( ! ChunkStay - > AddChunks ( 2 ) )
{
2014-04-25 19:35:25 -04:00
delete ChunkStay ;
2014-10-20 16:55:07 -04:00
ChunkStay = nullptr ;
2014-02-10 16:47:10 -05:00
return 0 ;
}
ChunkStay - > Enable ( * World - > GetChunkMap ( ) , 3 , 4 ) ;
2014-02-09 14:39:45 -05:00
return 0 ;
}
2014-12-12 07:32:52 -05:00
static int tolua_cWorld_PrepareChunk ( lua_State * tolua_S )
{
/* Function signature:
World : PrepareChunk ( ChunkX , ChunkZ , Callback )
*/
// Check the param types:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cWorld " ) | |
! L . CheckParamNumber ( 2 , 3 ) | |
! L . CheckParamFunctionOrNil ( 4 )
)
{
return 0 ;
}
// Read the params:
cWorld * world = nullptr ;
int chunkX = 0 , chunkZ = 0 ;
L . GetStackValues ( 1 , world , chunkX , chunkZ ) ;
if ( world = = nullptr )
{
LOGWARNING ( " World:PrepareChunk(): invalid world parameter " ) ;
L . LogStackTrace ( ) ;
return 0 ;
}
// Wrap the Lua callback inside a C++ callback class:
class cCallback :
public cChunkCoordCallback
{
public :
cCallback ( lua_State * a_LuaState ) :
m_LuaState ( a_LuaState ) ,
m_Callback ( m_LuaState , 4 )
{
}
// cChunkCoordCallback override:
virtual void Call ( int a_CBChunkX , int a_CBChunkZ ) override
{
if ( m_Callback . IsValid ( ) )
{
m_LuaState . Call ( m_Callback , a_CBChunkX , a_CBChunkZ ) ;
}
// This is the last reference of this object, we must delete it so that it doesn't leak:
delete this ;
}
protected :
cLuaState m_LuaState ;
cLuaState : : cRef m_Callback ;
} ;
cCallback * callback = new cCallback ( tolua_S ) ;
// Call the chunk preparation:
world - > PrepareChunk ( chunkX , chunkZ , callback ) ;
return 0 ;
}
2014-08-19 11:34:11 -04:00
static int tolua_cPlayer_GetPermissions ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2014-08-19 11:34:11 -04:00
// Function signature: cPlayer:GetPermissions() -> {permissions-array}
2012-06-14 09:06:06 -04:00
2014-08-19 11:34:11 -04:00
// Check the params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cPlayer " ) | |
! L . CheckParamEnd ( 2 )
)
2012-06-14 09:06:06 -04:00
{
2014-08-19 11:34:11 -04:00
return 0 ;
2012-06-14 09:06:06 -04:00
}
2014-08-19 11:34:11 -04:00
// Get the params:
2014-10-20 16:55:07 -04:00
cPlayer * self = ( cPlayer * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2012-06-14 09:06:06 -04:00
{
2014-08-19 11:34:11 -04:00
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , self ) ;
return 0 ;
2012-06-14 09:06:06 -04:00
}
2014-08-19 11:34:11 -04:00
// Push the permissions:
L . Push ( self - > GetPermissions ( ) ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2013-05-30 15:34:09 -04:00
static int tolua_cPlayer_OpenWindow ( lua_State * tolua_S )
{
// Function signature: cPlayer:OpenWindow(Window)
// Retrieve the plugin instance from the Lua state
2013-08-19 03:39:18 -04:00
cPluginLua * Plugin = GetLuaPlugin ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-05-30 15:34:09 -04:00
{
return 0 ;
}
// Get the parameters:
2014-10-20 16:55:07 -04:00
cPlayer * self = ( cPlayer * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
cWindow * wnd = ( cWindow * ) tolua_tousertype ( tolua_S , 2 , nullptr ) ;
if ( ( self = = nullptr ) | | ( wnd = = nullptr ) )
2013-05-30 15:34:09 -04:00
{
LOGWARNING ( " %s: invalid self (%p) or wnd (%p) " , __FUNCTION__ , self , wnd ) ;
return 0 ;
}
// If cLuaWindow, add a reference, so that Lua won't delete the cLuaWindow object mid-processing
tolua_Error err ;
if ( tolua_isusertype ( tolua_S , 2 , " cLuaWindow " , 0 , & err ) )
{
cLuaWindow * LuaWnd = ( cLuaWindow * ) wnd ;
// Only if not already referenced
if ( ! LuaWnd - > IsLuaReferenced ( ) )
{
int LuaRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
if ( LuaRef = = LUA_REFNIL )
{
LOGWARNING ( " %s: Cannot create a window reference. Cannot open window \" %s \" . " ,
__FUNCTION__ , wnd - > GetWindowTitle ( ) . c_str ( )
) ;
return 0 ;
}
LuaWnd - > SetLuaRef ( Plugin , LuaRef ) ;
}
}
// Open the window
self - > OpenWindow ( wnd ) ;
return 0 ;
}
2014-08-19 11:34:11 -04:00
static int tolua_cPlayer_PermissionMatches ( lua_State * tolua_S )
{
// Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool
// Check the params:
cLuaState L ( tolua_S ) ;
if (
2014-10-01 06:59:31 -04:00
! L . CheckParamUserTable ( 1 , " cPlayer " ) | |
! L . CheckParamString ( 2 , 3 ) | |
! L . CheckParamEnd ( 4 )
2014-08-19 11:34:11 -04:00
)
{
return 0 ;
}
// Get the params:
AString Permission , Template ;
L . GetStackValues ( 2 , Permission , Template ) ;
// Push the result of the match:
2014-10-01 06:59:31 -04:00
L . Push ( cPlayer : : PermissionMatches ( StringSplit ( Permission , " . " ) , StringSplit ( Template , " . " ) ) ) ;
2014-08-19 11:34:11 -04:00
return 1 ;
}
2013-05-31 03:16:14 -04:00
template <
class OBJTYPE ,
2013-08-19 03:39:18 -04:00
void ( OBJTYPE : : * SetCallback ) ( cPluginLua * a_Plugin , int a_FnRef )
2013-05-31 03:16:14 -04:00
>
static int tolua_SetObjectCallback ( lua_State * tolua_S )
2013-05-30 16:40:43 -04:00
{
2013-05-31 03:16:14 -04:00
// Function signature: OBJTYPE:SetWhateverCallback(CallbackFunction)
2013-05-30 16:40:43 -04:00
// Retrieve the plugin instance from the Lua state
2013-08-19 03:39:18 -04:00
cPluginLua * Plugin = GetLuaPlugin ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
if ( Plugin = = nullptr )
2013-05-30 16:40:43 -04:00
{
// Warning message has already been printed by GetLuaPlugin(), bail out silently
return 0 ;
}
2013-05-31 03:16:14 -04:00
// Get the parameters - self and the function reference:
2014-10-20 16:55:07 -04:00
OBJTYPE * self = ( OBJTYPE * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2013-05-30 16:40:43 -04:00
{
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , self ) ;
return 0 ;
}
2013-05-31 03:16:14 -04:00
int FnRef = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ; // Store function reference for later retrieval
2013-05-30 16:40:43 -04:00
if ( FnRef = = LUA_REFNIL )
{
LOGERROR ( " %s: Cannot create a function reference. Callback not set. " , __FUNCTION__ ) ;
return 0 ;
}
// Set the callback
2013-05-31 03:16:14 -04:00
( self - > * SetCallback ) ( Plugin , FnRef ) ;
2013-05-30 16:40:43 -04:00
return 0 ;
}
2013-08-19 03:39:18 -04:00
static int tolua_cPluginLua_AddWebTab ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2014-10-20 16:55:07 -04:00
cPluginLua * self = ( cPluginLua * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2012-06-14 09:06:06 -04:00
tolua_Error tolua_err ;
tolua_err . array = 0 ;
2013-09-18 16:30:36 -04:00
tolua_err . index = 3 ;
tolua_err . type = " function " ;
2012-06-14 09:06:06 -04:00
std : : string Title = " " ;
int Reference = LUA_REFNIL ;
2013-09-18 16:30:36 -04:00
if (
2014-07-19 08:53:41 -04:00
tolua_isstring ( tolua_S , 2 , 0 , & tolua_err ) & &
lua_isfunction ( tolua_S , 3 )
2013-09-18 16:30:36 -04:00
)
2012-06-14 09:06:06 -04:00
{
Reference = luaL_ref ( tolua_S , LUA_REGISTRYINDEX ) ;
2014-07-19 08:53:41 -04:00
Title = ( ( std : : string ) tolua_tocppstring ( tolua_S , 2 , 0 ) ) ;
2012-06-14 09:06:06 -04:00
}
else
{
2013-02-02 18:55:29 -05:00
return tolua_do_error ( tolua_S , " #ferror calling function '#funcname#' " , & tolua_err ) ;
2012-06-14 09:06:06 -04:00
}
2014-07-20 17:10:31 -04:00
if ( Reference ! = LUA_REFNIL )
2012-06-14 09:06:06 -04:00
{
2014-07-20 17:10:31 -04:00
if ( ! self - > AddWebTab ( Title . c_str ( ) , tolua_S , Reference ) )
2012-06-14 09:06:06 -04:00
{
2014-07-20 17:10:31 -04:00
luaL_unref ( tolua_S , LUA_REGISTRYINDEX , Reference ) ;
2012-06-14 09:06:06 -04:00
}
}
else
{
2014-07-20 17:10:31 -04:00
LOGWARNING ( " cPluginLua:AddWebTab: invalid function reference in 2nd argument (Title: \" %s \" ) " , Title . c_str ( ) ) ;
2012-06-14 09:06:06 -04:00
}
return 0 ;
}
2015-04-19 04:57:41 -04:00
static int tolua_cPlugin_GetDirectory ( lua_State * tolua_S )
2012-08-22 10:22:21 -04:00
{
2015-04-19 04:57:41 -04:00
cLuaState L ( tolua_S ) ;
// Log the obsoletion warning:
LOGWARNING ( " cPlugin:GetDirectory() is obsolete, use cPlugin:GetFolderName() instead. " ) ;
L . LogStackTrace ( ) ;
// Retrieve the params:
cPlugin * Plugin = static_cast < cPluginLua * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
// Get the folder name:
L . Push ( Plugin - > GetFolderName ( ) ) ;
return 1 ;
2012-08-22 10:22:21 -04:00
}
2012-10-10 17:50:46 -04:00
2015-04-19 04:57:41 -04:00
static int tolua_cPlugin_GetLocalDirectory ( lua_State * tolua_S )
2012-10-10 17:50:46 -04:00
{
2014-01-21 16:59:08 -05:00
cLuaState L ( tolua_S ) ;
2012-10-10 17:50:46 -04:00
2014-01-21 16:59:08 -05:00
// Log the obsoletion warning:
2015-04-19 04:57:41 -04:00
LOGWARNING ( " cPlugin:GetLocalDirectory() is obsolete, use cPlugin:GetLocalFolder() instead. " ) ;
2014-01-21 16:59:08 -05:00
L . LogStackTrace ( ) ;
2015-04-19 04:57:41 -04:00
// Retrieve the params:
cPlugin * Plugin = static_cast < cPluginLua * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-01-21 16:59:08 -05:00
2015-04-19 04:57:41 -04:00
// Get the folder:
L . Push ( Plugin - > GetLocalFolder ( ) ) ;
return 1 ;
2012-10-10 17:50:46 -04:00
}
2012-08-22 10:22:21 -04:00
2015-02-21 03:41:14 -05:00
static int tolua_md5 ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2015-02-21 03:41:14 -05:00
// Calculate the raw md5 checksum byte array:
2014-06-27 13:34:53 -04:00
unsigned char Output [ 16 ] ;
size_t len = 0 ;
const unsigned char * SourceString = ( const unsigned char * ) lua_tolstring ( tolua_S , 1 , & len ) ;
2015-02-21 03:41:14 -05:00
if ( SourceString = = nullptr )
{
return 0 ;
}
2014-06-27 13:34:53 -04:00
md5 ( SourceString , len , Output ) ;
lua_pushlstring ( tolua_S , ( const char * ) Output , ARRAYCOUNT ( Output ) ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2015-02-21 03:41:14 -05:00
/** Does the same as tolua_md5, but reports that the usage is obsolete and the plugin should use cCrypto.md5(). */
static int tolua_md5_obsolete ( lua_State * tolua_S )
{
LOGWARNING ( " Using md5() is obsolete, please change your plugin to use cCryptoHash.md5() " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
return tolua_md5 ( tolua_S ) ;
}
static int tolua_md5HexString ( lua_State * tolua_S )
{
// Calculate the raw md5 checksum byte array:
unsigned char md5Output [ 16 ] ;
size_t len = 0 ;
const unsigned char * SourceString = ( const unsigned char * ) lua_tolstring ( tolua_S , 1 , & len ) ;
if ( SourceString = = nullptr )
{
return 0 ;
}
md5 ( SourceString , len , md5Output ) ;
// Convert the md5 checksum to hex string:
std : : stringstream Output ;
2015-03-02 19:28:58 -05:00
Output < < std : : hex < < std : : setfill ( ' 0 ' ) ;
2015-02-21 03:41:14 -05:00
for ( size_t i = 0 ; i < ARRAYCOUNT ( md5Output ) ; i + + )
{
2015-03-02 19:28:58 -05:00
Output < < std : : setw ( 2 ) < < static_cast < unsigned short > ( md5Output [ i ] ) ; // Need to cast to a number, otherwise a char is output
2015-02-21 03:41:14 -05:00
}
lua_pushlstring ( tolua_S , Output . str ( ) . c_str ( ) , Output . str ( ) . size ( ) ) ;
return 1 ;
}
static int tolua_sha1 ( lua_State * tolua_S )
{
// Calculate the raw SHA1 checksum byte array from the input string:
unsigned char Output [ 20 ] ;
size_t len = 0 ;
const unsigned char * SourceString = ( const unsigned char * ) lua_tolstring ( tolua_S , 1 , & len ) ;
if ( SourceString = = nullptr )
{
return 0 ;
}
sha1 ( SourceString , len , Output ) ;
lua_pushlstring ( tolua_S , ( const char * ) Output , ARRAYCOUNT ( Output ) ) ;
return 1 ;
}
static int tolua_sha1HexString ( lua_State * tolua_S )
{
// Calculate the raw SHA1 checksum byte array from the input string:
unsigned char sha1Output [ 20 ] ;
size_t len = 0 ;
const unsigned char * SourceString = ( const unsigned char * ) lua_tolstring ( tolua_S , 1 , & len ) ;
if ( SourceString = = nullptr )
{
return 0 ;
}
sha1 ( SourceString , len , sha1Output ) ;
// Convert the sha1 checksum to hex string:
std : : stringstream Output ;
2015-03-02 19:28:58 -05:00
Output < < std : : hex < < std : : setfill ( ' 0 ' ) ;
2015-02-21 03:41:14 -05:00
for ( size_t i = 0 ; i < ARRAYCOUNT ( sha1Output ) ; i + + )
{
2015-03-02 19:28:58 -05:00
Output < < std : : setw ( 2 ) < < static_cast < unsigned short > ( sha1Output [ i ] ) ; // Need to cast to a number, otherwise a char is output
2015-02-21 03:41:14 -05:00
}
lua_pushlstring ( tolua_S , Output . str ( ) . c_str ( ) , Output . str ( ) . size ( ) ) ;
return 1 ;
}
2014-07-21 09:19:48 -04:00
static int tolua_push_StringStringMap ( lua_State * tolua_S , std : : map < std : : string , std : : string > & a_StringStringMap )
2012-06-14 09:06:06 -04:00
{
lua_newtable ( tolua_S ) ;
int top = lua_gettop ( tolua_S ) ;
2014-07-20 17:10:31 -04:00
for ( std : : map < std : : string , std : : string > : : iterator it = a_StringStringMap . begin ( ) ; it ! = a_StringStringMap . end ( ) ; + + it )
2012-06-14 09:06:06 -04:00
{
const char * key = it - > first . c_str ( ) ;
const char * value = it - > second . c_str ( ) ;
lua_pushstring ( tolua_S , key ) ;
lua_pushstring ( tolua_S , value ) ;
lua_settable ( tolua_S , top ) ;
}
return 1 ;
}
static int tolua_get_HTTPRequest_Params ( lua_State * tolua_S )
{
2014-10-20 16:55:07 -04:00
HTTPRequest * self = ( HTTPRequest * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2012-06-14 09:06:06 -04:00
return tolua_push_StringStringMap ( tolua_S , self - > Params ) ;
}
static int tolua_get_HTTPRequest_PostParams ( lua_State * tolua_S )
{
2014-10-20 16:55:07 -04:00
HTTPRequest * self = ( HTTPRequest * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2012-06-14 09:06:06 -04:00
return tolua_push_StringStringMap ( tolua_S , self - > PostParams ) ;
}
static int tolua_get_HTTPRequest_FormData ( lua_State * tolua_S )
{
2014-10-20 16:55:07 -04:00
HTTPRequest * self = ( HTTPRequest * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2012-06-14 09:06:06 -04:00
std : : map < std : : string , HTTPFormData > & FormData = self - > FormData ;
lua_newtable ( tolua_S ) ;
int top = lua_gettop ( tolua_S ) ;
2014-07-20 17:10:31 -04:00
for ( std : : map < std : : string , HTTPFormData > : : iterator it = FormData . begin ( ) ; it ! = FormData . end ( ) ; + + it )
2012-06-14 09:06:06 -04:00
{
2014-07-21 09:19:48 -04:00
lua_pushstring ( tolua_S , it - > first . c_str ( ) ) ;
tolua_pushusertype ( tolua_S , & ( it - > second ) , " HTTPFormData " ) ;
// lua_pushlstring(tolua_S, it->second.Value.c_str(), it->second.Value.size()); // Might contain binary data
2012-06-14 09:06:06 -04:00
lua_settable ( tolua_S , top ) ;
}
return 1 ;
}
2013-07-28 20:37:59 -04:00
static int tolua_cWebAdmin_GetPlugins ( lua_State * tolua_S )
{
2014-10-20 16:55:07 -04:00
cWebAdmin * self = ( cWebAdmin * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
2013-07-28 20:37:59 -04:00
const cWebAdmin : : PluginList & AllPlugins = self - > GetPlugins ( ) ;
2014-05-01 17:43:11 -04:00
lua_createtable ( tolua_S , ( int ) AllPlugins . size ( ) , 0 ) ;
2013-07-28 20:37:59 -04:00
int newTable = lua_gettop ( tolua_S ) ;
int index = 1 ;
cWebAdmin : : PluginList : : const_iterator iter = AllPlugins . begin ( ) ;
2014-05-01 17:43:11 -04:00
while ( iter ! = AllPlugins . end ( ) )
2013-07-28 20:37:59 -04:00
{
2014-05-01 17:43:11 -04:00
const cWebPlugin * Plugin = * iter ;
tolua_pushusertype ( tolua_S , ( void * ) Plugin , " const cWebPlugin " ) ;
2013-07-28 20:37:59 -04:00
lua_rawseti ( tolua_S , newTable , index ) ;
+ + iter ;
+ + index ;
}
return 1 ;
}
2014-08-09 16:54:43 -04:00
/** Binding for cWebAdmin::GetHTMLEscapedString.
Manual code required because ToLua generates an extra return value */
static int tolua_AllToLua_cWebAdmin_GetHTMLEscapedString ( lua_State * tolua_S )
{
// Check the param types:
cLuaState S ( tolua_S ) ;
if (
! S . CheckParamUserTable ( 1 , " cWebAdmin " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the parameters:
AString Input ;
S . GetStackValue ( 2 , Input ) ;
// Convert and return:
S . Push ( cWebAdmin : : GetHTMLEscapedString ( Input ) ) ;
return 1 ;
}
/** Binding for cWebAdmin::GetURLEncodedString.
Manual code required because ToLua generates an extra return value */
static int tolua_AllToLua_cWebAdmin_GetURLEncodedString ( lua_State * tolua_S )
{
// Check the param types:
cLuaState S ( tolua_S ) ;
if (
! S . CheckParamUserTable ( 1 , " cWebAdmin " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the parameters:
AString Input ;
S . GetStackValue ( 2 , Input ) ;
// Convert and return:
S . Push ( cWebAdmin : : GetURLEncodedString ( Input ) ) ;
return 1 ;
}
2013-07-28 20:37:59 -04:00
static int tolua_cWebPlugin_GetTabNames ( lua_State * tolua_S )
{
2015-04-19 08:35:04 -04:00
// Returns a map of (SafeTitle -> Title) for the plugin's web tabs.
auto self = reinterpret_cast < cWebPlugin * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
auto TabNames = self - > GetTabNames ( ) ;
2013-07-28 20:37:59 -04:00
lua_newtable ( tolua_S ) ;
int index = 1 ;
2015-04-19 08:35:04 -04:00
for ( auto itr = TabNames . cbegin ( ) , end = TabNames . cend ( ) ; itr ! = end ; + + itr )
{
tolua_pushstring ( tolua_S , itr - > second . c_str ( ) ) ; // Because the SafeTitle is supposed to be unique, use it as key
tolua_pushstring ( tolua_S , itr - > first . c_str ( ) ) ;
2013-07-28 20:37:59 -04:00
lua_rawset ( tolua_S , - 3 ) ;
+ + index ;
}
return 1 ;
}
2014-01-09 08:25:37 -05:00
static int tolua_cClientHandle_SendPluginMessage ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamUserType ( 1 , " cClientHandle " ) | |
! S . CheckParamString ( 2 , 3 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cClientHandle * Client = ( cClientHandle * ) tolua_tousertype ( L , 1 , nullptr ) ;
if ( Client = = nullptr )
2014-01-09 08:25:37 -05:00
{
LOGWARNING ( " ClientHandle is nil in cClientHandle:SendPluginMessage() " ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
AString Channel , Message ;
Channel . assign ( lua_tostring ( L , 2 ) , lua_strlen ( L , 2 ) ) ;
Message . assign ( lua_tostring ( L , 3 ) , lua_strlen ( L , 3 ) ) ;
Client - > SendPluginMessage ( Channel , Message ) ;
return 0 ;
}
2014-08-03 15:32:20 -04:00
static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamString ( 3 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Retrieve the parameters:
AString UUID , PlayerName ;
S . GetStackValue ( 2 , PlayerName ) ;
S . GetStackValue ( 3 , UUID ) ;
// Store in the cache:
cRoot : : Get ( ) - > GetMojangAPI ( ) . AddPlayerNameToUUIDMapping ( PlayerName , UUID ) ;
return 0 ;
}
static int tolua_cMojangAPI_GetPlayerNameFromUUID ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
AString UUID ;
S . GetStackValue ( 2 , UUID ) ;
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false ;
if ( lua_gettop ( L ) = = 3 )
{
ShouldUseCacheOnly = ( lua_toboolean ( L , 3 ) ! = 0 ) ;
lua_pop ( L , 1 ) ;
}
// Return the PlayerName:
AString PlayerName = cRoot : : Get ( ) - > GetMojangAPI ( ) . GetPlayerNameFromUUID ( UUID , ShouldUseCacheOnly ) ;
S . Push ( PlayerName ) ;
return 1 ;
}
static int tolua_cMojangAPI_GetUUIDFromPlayerName ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
AString PlayerName ;
S . GetStackValue ( 2 , PlayerName ) ;
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false ;
if ( lua_gettop ( L ) = = 3 )
{
ShouldUseCacheOnly = ( lua_toboolean ( L , 3 ) ! = 0 ) ;
lua_pop ( L , 1 ) ;
}
// Return the UUID:
AString UUID = cRoot : : Get ( ) - > GetMojangAPI ( ) . GetUUIDFromPlayerName ( PlayerName , ShouldUseCacheOnly ) ;
S . Push ( UUID ) ;
return 1 ;
}
2014-07-30 07:44:03 -04:00
static int tolua_cMojangAPI_GetUUIDsFromPlayerNames ( lua_State * L )
2014-07-28 11:09:39 -04:00
{
cLuaState S ( L ) ;
if (
2014-07-30 07:44:03 -04:00
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
2014-07-28 11:09:39 -04:00
! S . CheckParamTable ( 2 ) | |
2014-07-31 04:02:50 -04:00
! S . CheckParamEnd ( 4 )
2014-07-28 11:09:39 -04:00
)
{
return 0 ;
}
// Convert the input table into AStringVector:
AStringVector PlayerNames ;
int NumNames = luaL_getn ( L , 2 ) ;
PlayerNames . reserve ( NumNames ) ;
for ( int i = 1 ; i < = NumNames ; i + + )
{
lua_rawgeti ( L , 2 , i ) ;
AString Name ;
2014-07-31 04:02:50 -04:00
S . GetStackValue ( - 1 , Name ) ;
2014-07-28 11:09:39 -04:00
if ( ! Name . empty ( ) )
{
PlayerNames . push_back ( Name ) ;
}
lua_pop ( L , 1 ) ;
}
2014-07-31 04:02:50 -04:00
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false ;
if ( lua_gettop ( L ) = = 3 )
{
ShouldUseCacheOnly = ( lua_toboolean ( L , 3 ) ! = 0 ) ;
lua_pop ( L , 1 ) ;
}
2014-07-28 11:09:39 -04:00
// Push the output table onto the stack:
2014-07-31 04:02:50 -04:00
lua_newtable ( L ) ;
2014-07-28 11:09:39 -04:00
// Get the UUIDs:
2014-07-31 04:02:50 -04:00
AStringVector UUIDs = cRoot : : Get ( ) - > GetMojangAPI ( ) . GetUUIDsFromPlayerNames ( PlayerNames , ShouldUseCacheOnly ) ;
2014-07-28 11:09:39 -04:00
if ( UUIDs . size ( ) ! = PlayerNames . size ( ) )
{
// A hard error has occured while processing the request, no UUIDs were returned. Return an empty table:
return 1 ;
}
// Convert to output table, PlayerName -> UUID:
2014-07-31 04:02:50 -04:00
size_t len = UUIDs . size ( ) ;
for ( size_t i = 0 ; i < len ; i + + )
2014-07-28 11:09:39 -04:00
{
if ( UUIDs [ i ] . empty ( ) )
{
// No UUID was provided for PlayerName[i], skip it in the resulting table
continue ;
}
lua_pushlstring ( L , UUIDs [ i ] . c_str ( ) , UUIDs [ i ] . length ( ) ) ;
lua_setfield ( L , 3 , PlayerNames [ i ] . c_str ( ) ) ;
}
return 1 ;
}
2014-08-21 09:19:30 -04:00
static int tolua_cMojangAPI_MakeUUIDDashed ( lua_State * L )
{
// Function signature: cMojangAPI:MakeUUIDDashed(UUID) -> string
// Check params:
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the params:
AString UUID ;
S . GetStackValue ( 2 , UUID ) ;
// Push the result:
S . Push ( cRoot : : Get ( ) - > GetMojangAPI ( ) . MakeUUIDDashed ( UUID ) ) ;
return 1 ;
}
static int tolua_cMojangAPI_MakeUUIDShort ( lua_State * L )
{
// Function signature: cMojangAPI:MakeUUIDShort(UUID) -> string
// Check params:
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the params:
AString UUID ;
S . GetStackValue ( 2 , UUID ) ;
// Push the result:
S . Push ( cRoot : : Get ( ) - > GetMojangAPI ( ) . MakeUUIDShort ( UUID ) ) ;
return 1 ;
}
2013-04-10 15:52:03 -04:00
static int Lua_ItemGrid_GetSlotCoords ( lua_State * L )
{
tolua_Error tolua_err ;
if (
! tolua_isusertype ( L , 1 , " const cItemGrid " , 0 , & tolua_err ) | |
! tolua_isnumber ( L , 2 , 0 , & tolua_err ) | |
! tolua_isnoobj ( L , 3 , & tolua_err )
)
{
goto tolua_lerror ;
}
{
2014-10-20 16:55:07 -04:00
const cItemGrid * self = ( const cItemGrid * ) tolua_tousertype ( L , 1 , nullptr ) ;
2013-04-10 17:25:26 -04:00
int SlotNum = ( int ) tolua_tonumber ( L , 2 , 0 ) ;
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2013-04-10 17:25:26 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( L , " invalid 'self' in function 'cItemGrid:GetSlotCoords' " , nullptr ) ;
2013-04-10 17:25:26 -04:00
return 0 ;
}
int X , Y ;
self - > GetSlotCoords ( SlotNum , X , Y ) ;
tolua_pushnumber ( L , ( lua_Number ) X ) ;
tolua_pushnumber ( L , ( lua_Number ) Y ) ;
return 2 ;
2013-04-10 15:52:03 -04:00
}
tolua_lerror :
2013-05-24 05:16:09 -04:00
tolua_error ( L , " #ferror in function 'cItemGrid:GetSlotCoords'. " , & tolua_err ) ;
2013-04-10 15:52:03 -04:00
return 0 ;
}
2013-08-07 08:34:00 -04:00
/// Provides interface between a Lua table of callbacks and the cBlockTracer::cCallbacks
class cLuaBlockTracerCallbacks :
public cBlockTracer : : cCallbacks
{
public :
cLuaBlockTracerCallbacks ( cLuaState & a_LuaState , int a_ParamNum ) :
m_LuaState ( a_LuaState ) ,
m_TableRef ( a_LuaState , a_ParamNum )
{
}
2013-08-27 13:57:37 -04:00
virtual bool OnNextBlock ( int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta , char a_EntryFace ) override
2013-08-07 08:34:00 -04:00
{
2014-01-11 16:51:10 -05:00
bool res = false ;
if ( ! m_LuaState . Call (
cLuaState : : cTableRef ( m_TableRef , " OnNextBlock " ) ,
a_BlockX , a_BlockY , a_BlockZ , a_BlockType , a_BlockMeta , a_EntryFace ,
cLuaState : : Return , res
) )
2013-08-07 08:34:00 -04:00
{
// No such function in the table, skip the callback
return false ;
}
return res ;
}
2013-08-27 13:57:37 -04:00
virtual bool OnNextBlockNoData ( int a_BlockX , int a_BlockY , int a_BlockZ , char a_EntryFace ) override
2013-08-07 08:34:00 -04:00
{
2014-01-11 16:51:10 -05:00
bool res = false ;
if ( ! m_LuaState . Call (
cLuaState : : cTableRef ( m_TableRef , " OnNextBlockNoData " ) ,
a_BlockX , a_BlockY , a_BlockZ , a_EntryFace ,
cLuaState : : Return , res
) )
2013-08-07 08:34:00 -04:00
{
// No such function in the table, skip the callback
return false ;
}
return res ;
}
virtual bool OnOutOfWorld ( double a_BlockX , double a_BlockY , double a_BlockZ ) override
{
2014-01-11 16:51:10 -05:00
bool res = false ;
if ( ! m_LuaState . Call (
cLuaState : : cTableRef ( m_TableRef , " OnOutOfWorld " ) ,
a_BlockX , a_BlockY , a_BlockZ ,
cLuaState : : Return , res
) )
2013-08-07 08:34:00 -04:00
{
// No such function in the table, skip the callback
return false ;
}
return res ;
}
virtual bool OnIntoWorld ( double a_BlockX , double a_BlockY , double a_BlockZ ) override
{
2014-01-11 16:51:10 -05:00
bool res = false ;
if ( ! m_LuaState . Call (
cLuaState : : cTableRef ( m_TableRef , " OnIntoWorld " ) ,
a_BlockX , a_BlockY , a_BlockZ ,
cLuaState : : Return , res
) )
2013-08-07 08:34:00 -04:00
{
// No such function in the table, skip the callback
return false ;
}
return res ;
}
virtual void OnNoMoreHits ( void ) override
{
2014-01-11 16:51:10 -05:00
m_LuaState . Call ( cLuaState : : cTableRef ( m_TableRef , " OnNoMoreHits " ) ) ;
2013-08-07 08:34:00 -04:00
}
virtual void OnNoChunk ( void ) override
{
2014-01-11 16:51:10 -05:00
m_LuaState . Call ( cLuaState : : cTableRef ( m_TableRef , " OnNoChunk " ) ) ;
2013-08-07 08:34:00 -04:00
}
protected :
cLuaState & m_LuaState ;
cLuaState : : cRef m_TableRef ;
} ;
static int tolua_cLineBlockTracer_Trace ( lua_State * tolua_S )
{
2014-01-31 04:20:06 -05:00
/* Supported function signatures:
cLineBlockTracer : Trace ( World , Callbacks , StartX , StartY , StartZ , EndX , EndY , EndZ ) // Canonical
cLineBlockTracer . Trace ( World , Callbacks , StartX , StartY , StartZ , EndX , EndY , EndZ )
*/
// If the first param is the cLineBlockTracer class, shift param index by one:
int idx = 1 ;
tolua_Error err ;
if ( tolua_isusertable ( tolua_S , 1 , " cLineBlockTracer " , 0 , & err ) )
{
idx = 2 ;
}
// Check params:
2013-08-07 08:34:00 -04:00
cLuaState L ( tolua_S ) ;
if (
2014-01-31 04:20:06 -05:00
! L . CheckParamUserType ( idx , " cWorld " ) | |
! L . CheckParamTable ( idx + 1 ) | |
! L . CheckParamNumber ( idx + 2 , idx + 7 ) | |
! L . CheckParamEnd ( idx + 8 )
2013-08-07 08:34:00 -04:00
)
{
return 0 ;
}
2014-01-31 04:20:06 -05:00
// Trace:
2014-10-20 16:55:07 -04:00
cWorld * World = ( cWorld * ) tolua_tousertype ( L , idx , nullptr ) ;
2014-01-31 04:20:06 -05:00
cLuaBlockTracerCallbacks Callbacks ( L , idx + 1 ) ;
double StartX = tolua_tonumber ( L , idx + 2 , 0 ) ;
double StartY = tolua_tonumber ( L , idx + 3 , 0 ) ;
double StartZ = tolua_tonumber ( L , idx + 4 , 0 ) ;
double EndX = tolua_tonumber ( L , idx + 5 , 0 ) ;
double EndY = tolua_tonumber ( L , idx + 6 , 0 ) ;
double EndZ = tolua_tonumber ( L , idx + 7 , 0 ) ;
2013-08-07 08:34:00 -04:00
bool res = cLineBlockTracer : : Trace ( * World , Callbacks , StartX , StartY , StartZ , EndX , EndY , EndZ ) ;
tolua_pushboolean ( L , res ? 1 : 0 ) ;
return 1 ;
}
2013-11-22 06:26:06 -05:00
static int tolua_cRoot_GetFurnaceRecipe ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if (
2013-11-22 10:49:38 -05:00
! L . CheckParamUserTable ( 1 , " cRoot " ) | |
! L . CheckParamUserType ( 2 , " const cItem " ) | |
! L . CheckParamEnd ( 3 )
2013-11-22 06:26:06 -05:00
)
{
return 0 ;
}
// Check the input param:
2014-10-20 16:55:07 -04:00
cItem * Input = ( cItem * ) tolua_tousertype ( L , 2 , nullptr ) ;
if ( Input = = nullptr )
2013-11-22 06:26:06 -05:00
{
LOGWARNING ( " cRoot:GetFurnaceRecipe: the Input parameter is nil or missing. " ) ;
return 0 ;
}
// Get the recipe for the input
cFurnaceRecipe * FR = cRoot : : Get ( ) - > GetFurnaceRecipe ( ) ;
2014-08-31 13:00:36 -04:00
const cFurnaceRecipe : : cRecipe * Recipe = FR - > GetRecipeFrom ( * Input ) ;
2014-10-20 16:55:07 -04:00
if ( Recipe = = nullptr )
2013-11-22 06:26:06 -05:00
{
// There is no such furnace recipe for this input, return no value
return 0 ;
}
// Push the output, number of ticks and input as the three return values:
tolua_pushusertype ( L , Recipe - > Out , " const cItem " ) ;
tolua_pushnumber ( L , ( lua_Number ) ( Recipe - > CookTime ) ) ;
tolua_pushusertype ( L , Recipe - > In , " const cItem " ) ;
return 3 ;
}
2013-10-23 06:09:11 -04:00
static int tolua_cHopperEntity_GetOutputBlockPos ( lua_State * tolua_S )
{
// function cHopperEntity::GetOutputBlockPos()
// Exported manually because tolua would require meaningless params
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cHopperEntity " ) | |
! L . CheckParamNumber ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cHopperEntity * self = ( cHopperEntity * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2013-10-23 06:09:11 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cHopperEntity::GetOutputBlockPos()' " , nullptr ) ;
2013-10-23 06:09:11 -04:00
return 0 ;
}
NIBBLETYPE a_BlockMeta = ( ( NIBBLETYPE ) tolua_tonumber ( tolua_S , 2 , 0 ) ) ;
int a_OutputX , a_OutputY , a_OutputZ ;
bool res = self - > GetOutputBlockPos ( a_BlockMeta , a_OutputX , a_OutputY , a_OutputZ ) ;
tolua_pushboolean ( tolua_S , res ) ;
if ( res )
{
tolua_pushnumber ( tolua_S , ( lua_Number ) a_OutputX ) ;
tolua_pushnumber ( tolua_S , ( lua_Number ) a_OutputY ) ;
tolua_pushnumber ( tolua_S , ( lua_Number ) a_OutputZ ) ;
return 4 ;
}
return 1 ;
}
2014-01-22 13:35:36 -05:00
2014-02-20 04:48:29 -05:00
static int tolua_cBlockArea_GetBlockTypeMeta ( lua_State * tolua_S )
{
// function cBlockArea::GetBlockTypeMeta()
// Exported manually because tolua generates extra input params for the outputs
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamNumber ( 2 , 4 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-02-20 04:48:29 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta' " , nullptr ) ;
2014-02-20 04:48:29 -05:00
return 0 ;
}
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
BLOCKTYPE BlockType ;
NIBBLETYPE BlockMeta ;
self - > GetBlockTypeMeta ( BlockX , BlockY , BlockZ , BlockType , BlockMeta ) ;
tolua_pushnumber ( tolua_S , BlockType ) ;
tolua_pushnumber ( tolua_S , BlockMeta ) ;
return 2 ;
}
2014-02-23 08:03:24 -05:00
static int tolua_cBlockArea_GetOrigin ( lua_State * tolua_S )
{
// function cBlockArea::GetOrigin()
// Returns all three coords of the origin point
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamUserType ( 1 , " cBlockArea " ) )
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-02-23 08:03:24 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea:GetOrigin' " , nullptr ) ;
2014-02-23 08:03:24 -05:00
return 0 ;
}
// Push the three origin coords:
lua_pushnumber ( tolua_S , self - > GetOriginX ( ) ) ;
lua_pushnumber ( tolua_S , self - > GetOriginY ( ) ) ;
lua_pushnumber ( tolua_S , self - > GetOriginZ ( ) ) ;
return 3 ;
}
2014-02-20 04:48:29 -05:00
static int tolua_cBlockArea_GetRelBlockTypeMeta ( lua_State * tolua_S )
{
// function cBlockArea::GetRelBlockTypeMeta()
// Exported manually because tolua generates extra input params for the outputs
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamNumber ( 2 , 4 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-02-20 04:48:29 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta' " , nullptr ) ;
2014-02-20 04:48:29 -05:00
return 0 ;
}
int BlockX = ( int ) tolua_tonumber ( tolua_S , 2 , 0 ) ;
int BlockY = ( int ) tolua_tonumber ( tolua_S , 3 , 0 ) ;
int BlockZ = ( int ) tolua_tonumber ( tolua_S , 4 , 0 ) ;
BLOCKTYPE BlockType ;
NIBBLETYPE BlockMeta ;
self - > GetRelBlockTypeMeta ( BlockX , BlockY , BlockZ , BlockType , BlockMeta ) ;
tolua_pushnumber ( tolua_S , BlockType ) ;
tolua_pushnumber ( tolua_S , BlockMeta ) ;
return 2 ;
}
2014-02-23 08:03:24 -05:00
static int tolua_cBlockArea_GetSize ( lua_State * tolua_S )
{
// function cBlockArea::GetSize()
// Returns all three sizes of the area
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamUserType ( 1 , " cBlockArea " ) )
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-02-23 08:03:24 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea:GetSize' " , nullptr ) ;
2014-02-23 08:03:24 -05:00
return 0 ;
}
// Push the three origin coords:
lua_pushnumber ( tolua_S , self - > GetSizeX ( ) ) ;
lua_pushnumber ( tolua_S , self - > GetSizeY ( ) ) ;
lua_pushnumber ( tolua_S , self - > GetSizeZ ( ) ) ;
return 3 ;
}
2014-06-11 08:22:27 -04:00
static int tolua_cBlockArea_GetCoordRange ( lua_State * tolua_S )
{
// function cBlockArea::GetCoordRange()
// Returns all three sizes of the area, miuns one, so that they represent the maximum coord value
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamUserType ( 1 , " cBlockArea " ) )
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-06-11 08:22:27 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea:GetSize' " , nullptr ) ;
2014-06-11 08:22:27 -04:00
return 0 ;
}
// Push the three origin coords:
lua_pushnumber ( tolua_S , self - > GetSizeX ( ) - 1 ) ;
lua_pushnumber ( tolua_S , self - > GetSizeY ( ) - 1 ) ;
lua_pushnumber ( tolua_S , self - > GetSizeZ ( ) - 1 ) ;
return 3 ;
}
2014-01-22 13:35:36 -05:00
static int tolua_cBlockArea_LoadFromSchematicFile ( lua_State * tolua_S )
{
// function cBlockArea::LoadFromSchematicFile
2014-03-07 11:43:06 -05:00
// Exported manually because function has been moved to SchematicFileSerializer.cpp
2014-01-22 13:35:36 -05:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-01-22 13:35:36 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea::LoadFromSchematicFile' " , nullptr ) ;
2014-01-22 13:35:36 -05:00
return 0 ;
}
AString Filename = tolua_tostring ( tolua_S , 2 , 0 ) ;
2014-07-19 08:53:41 -04:00
bool res = cSchematicFileSerializer : : LoadFromSchematicFile ( * self , Filename ) ;
2014-01-22 13:35:36 -05:00
tolua_pushboolean ( tolua_S , res ) ;
return 1 ;
}
2014-02-20 04:48:29 -05:00
2014-03-07 03:17:13 -05:00
static int tolua_cBlockArea_LoadFromSchematicString ( lua_State * tolua_S )
{
// function cBlockArea::LoadFromSchematicString
2014-03-07 11:43:06 -05:00
// Exported manually because function has been moved to SchematicFileSerializer.cpp
2014-03-07 03:17:13 -05:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-07 03:17:13 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea::LoadFromSchematicFile' " , nullptr ) ;
2014-03-07 03:17:13 -05:00
return 0 ;
}
AString Data ;
L . GetStackValue ( 2 , Data ) ;
bool res = cSchematicFileSerializer : : LoadFromSchematicString ( * self , Data ) ;
tolua_pushboolean ( tolua_S , res ) ;
return 1 ;
}
2014-01-22 13:35:36 -05:00
static int tolua_cBlockArea_SaveToSchematicFile ( lua_State * tolua_S )
{
// function cBlockArea::SaveToSchematicFile
2014-03-07 11:43:06 -05:00
// Exported manually because function has been moved to SchematicFileSerializer.cpp
2014-01-22 13:35:36 -05:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-01-22 13:35:36 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea::SaveToSchematicFile' " , nullptr ) ;
2014-01-22 13:35:36 -05:00
return 0 ;
}
AString Filename = tolua_tostring ( tolua_S , 2 , 0 ) ;
2014-07-19 08:53:41 -04:00
bool res = cSchematicFileSerializer : : SaveToSchematicFile ( * self , Filename ) ;
2014-01-22 13:35:36 -05:00
tolua_pushboolean ( tolua_S , res ) ;
return 1 ;
}
2014-02-20 04:48:29 -05:00
2014-03-07 03:17:13 -05:00
static int tolua_cBlockArea_SaveToSchematicString ( lua_State * tolua_S )
{
// function cBlockArea::SaveToSchematicString
2014-03-07 11:43:06 -05:00
// Exported manually because function has been moved to SchematicFileSerializer.cpp
2014-03-07 03:17:13 -05:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cBlockArea " ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cBlockArea * self = ( cBlockArea * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-07 03:17:13 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cBlockArea::SaveToSchematicFile' " , nullptr ) ;
2014-03-07 03:17:13 -05:00
return 0 ;
}
2014-03-07 15:28:52 -05:00
AString Data ;
if ( cSchematicFileSerializer : : SaveToSchematicString ( * self , Data ) )
{
L . Push ( Data ) ;
return 1 ;
}
return 0 ;
2014-03-07 03:17:13 -05:00
}
2014-03-04 16:17:23 -05:00
static int tolua_cCompositeChat_AddRunCommandPart ( lua_State * tolua_S )
{
// function cCompositeChat:AddRunCommandPart(Message, Command, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:AddRunCommandPart' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Add the part:
AString Text , Command , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Command ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddRunCommandPart ( Text , Command , Style ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_AddSuggestCommandPart ( lua_State * tolua_S )
{
// function cCompositeChat:AddSuggestCommandPart(Message, Command, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:AddSuggestCommandPart' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Add the part:
AString Text , Command , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Command ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddSuggestCommandPart ( Text , Command , Style ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_AddTextPart ( lua_State * tolua_S )
{
// function cCompositeChat:AddTextPart(Message, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:AddTextPart' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Add the part:
AString Text , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Style ) ;
self - > AddTextPart ( Text , Style ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_AddUrlPart ( lua_State * tolua_S )
{
// function cCompositeChat:AddTextPart(Message, Url, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:AddUrlPart' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Add the part:
AString Text , Url , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Url ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddUrlPart ( Text , Url , Style ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_ParseText ( lua_State * tolua_S )
{
// function cCompositeChat:ParseText(TextMessage)
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:ParseText' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Parse the text:
AString Text ;
L . GetStackValue ( 2 , Text ) ;
self - > ParseText ( Text ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_SetMessageType ( lua_State * tolua_S )
{
// function cCompositeChat:SetMessageType(MessageType)
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamNumber ( 2 )
)
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:SetMessageType' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Set the type:
2014-05-30 16:41:47 -04:00
int MessageType = mtCustom ;
L . GetStackValue ( 2 , MessageType ) ;
2014-03-04 16:17:23 -05:00
self - > SetMessageType ( ( eMessageType ) MessageType ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
static int tolua_cCompositeChat_UnderlineUrls ( lua_State * tolua_S )
{
// function cCompositeChat:UnderlineUrls()
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamUserType ( 1 , " cCompositeChat " ) )
{
return 0 ;
}
2014-10-20 16:55:07 -04:00
cCompositeChat * self = ( cCompositeChat * ) tolua_tousertype ( tolua_S , 1 , nullptr ) ;
if ( self = = nullptr )
2014-03-04 16:17:23 -05:00
{
2014-10-20 16:55:07 -04:00
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:UnderlineUrls' " , nullptr ) ;
2014-03-04 16:17:23 -05:00
return 0 ;
}
// Call the processing
self - > UnderlineUrls ( ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
2013-06-05 16:15:19 -04:00
void ManualBindings : : Bind ( lua_State * tolua_S )
2012-06-14 09:06:06 -04:00
{
2014-10-20 16:55:07 -04:00
tolua_beginmodule ( tolua_S , nullptr ) ;
2015-02-21 03:41:14 -05:00
// Create the new classes:
tolua_usertype ( tolua_S , " cCryptoHash " ) ;
tolua_cclass ( tolua_S , " cCryptoHash " , " cCryptoHash " , " " , nullptr ) ;
2015-02-23 06:53:02 -05:00
tolua_usertype ( tolua_S , " cStringCompression " ) ;
tolua_cclass ( tolua_S , " cStringCompression " , " cStringCompression " , " " , nullptr ) ;
2015-03-19 07:34:16 -04:00
tolua_usertype ( tolua_S , " cLineBlockTracer " ) ;
tolua_cclass ( tolua_S , " cLineBlockTracer " , " cLineBlockTracer " , " " , nullptr ) ;
2015-02-21 03:41:14 -05:00
// Globals:
2015-03-11 15:02:11 -04:00
tolua_function ( tolua_S , " Clamp " , tolua_Clamp ) ;
tolua_function ( tolua_S , " StringSplit " , tolua_StringSplit ) ;
2015-03-10 23:14:17 -04:00
tolua_function ( tolua_S , " StringSplitWithQuotes " , tolua_StringSplitWithQuotes ) ;
2015-03-11 15:02:11 -04:00
tolua_function ( tolua_S , " StringSplitAndTrim " , tolua_StringSplitAndTrim ) ;
tolua_function ( tolua_S , " LOG " , tolua_LOG ) ;
tolua_function ( tolua_S , " LOGINFO " , tolua_LOGINFO ) ;
tolua_function ( tolua_S , " LOGWARN " , tolua_LOGWARN ) ;
tolua_function ( tolua_S , " LOGWARNING " , tolua_LOGWARN ) ;
tolua_function ( tolua_S , " LOGERROR " , tolua_LOGERROR ) ;
tolua_function ( tolua_S , " Base64Encode " , tolua_Base64Encode ) ;
tolua_function ( tolua_S , " Base64Decode " , tolua_Base64Decode ) ;
tolua_function ( tolua_S , " md5 " , tolua_md5_obsolete ) ; // OBSOLETE, use cCryptoHash.md5() instead
2013-01-26 21:00:33 -05:00
2013-11-22 14:11:24 -05:00
tolua_beginmodule ( tolua_S , " cFile " ) ;
tolua_function ( tolua_S , " GetFolderContents " , tolua_cFile_GetFolderContents ) ;
tolua_endmodule ( tolua_S ) ;
2014-01-25 13:13:54 -05:00
tolua_beginmodule ( tolua_S , " cBlockArea " ) ;
2014-03-07 03:17:13 -05:00
tolua_function ( tolua_S , " GetBlockTypeMeta " , tolua_cBlockArea_GetBlockTypeMeta ) ;
2014-06-11 08:22:27 -04:00
tolua_function ( tolua_S , " GetCoordRange " , tolua_cBlockArea_GetCoordRange ) ;
2014-03-07 03:17:13 -05:00
tolua_function ( tolua_S , " GetOrigin " , tolua_cBlockArea_GetOrigin ) ;
tolua_function ( tolua_S , " GetRelBlockTypeMeta " , tolua_cBlockArea_GetRelBlockTypeMeta ) ;
tolua_function ( tolua_S , " GetSize " , tolua_cBlockArea_GetSize ) ;
tolua_function ( tolua_S , " LoadFromSchematicFile " , tolua_cBlockArea_LoadFromSchematicFile ) ;
tolua_function ( tolua_S , " LoadFromSchematicString " , tolua_cBlockArea_LoadFromSchematicString ) ;
tolua_function ( tolua_S , " SaveToSchematicFile " , tolua_cBlockArea_SaveToSchematicFile ) ;
tolua_function ( tolua_S , " SaveToSchematicString " , tolua_cBlockArea_SaveToSchematicString ) ;
2014-01-22 13:35:36 -05:00
tolua_endmodule ( tolua_S ) ;
2014-03-04 16:17:23 -05:00
tolua_beginmodule ( tolua_S , " cCompositeChat " ) ;
tolua_function ( tolua_S , " AddRunCommandPart " , tolua_cCompositeChat_AddRunCommandPart ) ;
tolua_function ( tolua_S , " AddSuggestCommandPart " , tolua_cCompositeChat_AddSuggestCommandPart ) ;
tolua_function ( tolua_S , " AddTextPart " , tolua_cCompositeChat_AddTextPart ) ;
tolua_function ( tolua_S , " AddUrlPart " , tolua_cCompositeChat_AddUrlPart ) ;
tolua_function ( tolua_S , " ParseText " , tolua_cCompositeChat_ParseText ) ;
tolua_function ( tolua_S , " SetMessageType " , tolua_cCompositeChat_SetMessageType ) ;
tolua_function ( tolua_S , " UnderlineUrls " , tolua_cCompositeChat_UnderlineUrls ) ;
tolua_endmodule ( tolua_S ) ;
2014-01-25 13:13:54 -05:00
tolua_beginmodule ( tolua_S , " cHopperEntity " ) ;
2013-10-23 06:09:11 -04:00
tolua_function ( tolua_S , " GetOutputBlockPos " , tolua_cHopperEntity_GetOutputBlockPos ) ;
tolua_endmodule ( tolua_S ) ;
2013-08-07 08:34:00 -04:00
tolua_beginmodule ( tolua_S , " cLineBlockTracer " ) ;
tolua_function ( tolua_S , " Trace " , tolua_cLineBlockTracer_Trace ) ;
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cRoot " ) ;
2013-02-02 18:55:29 -05:00
tolua_function ( tolua_S , " FindAndDoWithPlayer " , tolua_DoWith < cRoot , cPlayer , & cRoot : : FindAndDoWithPlayer > ) ;
2014-11-05 15:57:38 -05:00
tolua_function ( tolua_S , " DoWithPlayerByUUID " , tolua_DoWith < cRoot , cPlayer , & cRoot : : DoWithPlayerByUUID > ) ;
2013-02-02 18:55:29 -05:00
tolua_function ( tolua_S , " ForEachPlayer " , tolua_ForEach < cRoot , cPlayer , & cRoot : : ForEachPlayer > ) ;
2013-08-05 09:26:43 -04:00
tolua_function ( tolua_S , " ForEachWorld " , tolua_ForEach < cRoot , cWorld , & cRoot : : ForEachWorld > ) ;
2013-11-22 06:26:06 -05:00
tolua_function ( tolua_S , " GetFurnaceRecipe " , tolua_cRoot_GetFurnaceRecipe ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cWorld " ) ;
2014-02-10 16:47:10 -05:00
tolua_function ( tolua_S , " ChunkStay " , tolua_cWorld_ChunkStay ) ;
2014-01-18 09:59:33 -05:00
tolua_function ( tolua_S , " DoWithBlockEntityAt " , tolua_DoWithXYZ < cWorld , cBlockEntity , & cWorld : : DoWithBlockEntityAt > ) ;
2014-07-30 16:19:51 -04:00
tolua_function ( tolua_S , " DoWithBeaconAt " , tolua_DoWithXYZ < cWorld , cBeaconEntity , & cWorld : : DoWithBeaconAt > ) ;
2014-01-18 09:59:33 -05:00
tolua_function ( tolua_S , " DoWithChestAt " , tolua_DoWithXYZ < cWorld , cChestEntity , & cWorld : : DoWithChestAt > ) ;
tolua_function ( tolua_S , " DoWithDispenserAt " , tolua_DoWithXYZ < cWorld , cDispenserEntity , & cWorld : : DoWithDispenserAt > ) ;
tolua_function ( tolua_S , " DoWithDropSpenserAt " , tolua_DoWithXYZ < cWorld , cDropSpenserEntity , & cWorld : : DoWithDropSpenserAt > ) ;
tolua_function ( tolua_S , " DoWithDropperAt " , tolua_DoWithXYZ < cWorld , cDropperEntity , & cWorld : : DoWithDropperAt > ) ;
tolua_function ( tolua_S , " DoWithEntityByID " , tolua_DoWithID < cWorld , cEntity , & cWorld : : DoWithEntityByID > ) ;
tolua_function ( tolua_S , " DoWithFurnaceAt " , tolua_DoWithXYZ < cWorld , cFurnaceEntity , & cWorld : : DoWithFurnaceAt > ) ;
tolua_function ( tolua_S , " DoWithNoteBlockAt " , tolua_DoWithXYZ < cWorld , cNoteEntity , & cWorld : : DoWithNoteBlockAt > ) ;
tolua_function ( tolua_S , " DoWithCommandBlockAt " , tolua_DoWithXYZ < cWorld , cCommandBlockEntity , & cWorld : : DoWithCommandBlockAt > ) ;
2014-03-07 05:44:16 -05:00
tolua_function ( tolua_S , " DoWithMobHeadAt " , tolua_DoWithXYZ < cWorld , cMobHeadEntity , & cWorld : : DoWithMobHeadAt > ) ;
2014-03-06 19:30:34 -05:00
tolua_function ( tolua_S , " DoWithFlowerPotAt " , tolua_DoWithXYZ < cWorld , cFlowerPotEntity , & cWorld : : DoWithFlowerPotAt > ) ;
2014-01-18 09:59:33 -05:00
tolua_function ( tolua_S , " DoWithPlayer " , tolua_DoWith < cWorld , cPlayer , & cWorld : : DoWithPlayer > ) ;
tolua_function ( tolua_S , " FindAndDoWithPlayer " , tolua_DoWith < cWorld , cPlayer , & cWorld : : FindAndDoWithPlayer > ) ;
2014-11-05 15:57:38 -05:00
tolua_function ( tolua_S , " DoWithPlayerByUUID " , tolua_DoWith < cWorld , cPlayer , & cWorld : : DoWithPlayerByUUID > ) ;
2013-11-20 15:53:29 -05:00
tolua_function ( tolua_S , " ForEachBlockEntityInChunk " , tolua_ForEachInChunk < cWorld , cBlockEntity , & cWorld : : ForEachBlockEntityInChunk > ) ;
tolua_function ( tolua_S , " ForEachChestInChunk " , tolua_ForEachInChunk < cWorld , cChestEntity , & cWorld : : ForEachChestInChunk > ) ;
tolua_function ( tolua_S , " ForEachEntity " , tolua_ForEach < cWorld , cEntity , & cWorld : : ForEachEntity > ) ;
2014-09-03 11:01:23 -04:00
tolua_function ( tolua_S , " ForEachEntityInBox " , tolua_ForEachInBox < cWorld , cEntity , & cWorld : : ForEachEntityInBox > ) ;
2013-11-20 15:53:29 -05:00
tolua_function ( tolua_S , " ForEachEntityInChunk " , tolua_ForEachInChunk < cWorld , cEntity , & cWorld : : ForEachEntityInChunk > ) ;
tolua_function ( tolua_S , " ForEachFurnaceInChunk " , tolua_ForEachInChunk < cWorld , cFurnaceEntity , & cWorld : : ForEachFurnaceInChunk > ) ;
tolua_function ( tolua_S , " ForEachPlayer " , tolua_ForEach < cWorld , cPlayer , & cWorld : : ForEachPlayer > ) ;
tolua_function ( tolua_S , " GetBlockInfo " , tolua_cWorld_GetBlockInfo ) ;
tolua_function ( tolua_S , " GetBlockTypeMeta " , tolua_cWorld_GetBlockTypeMeta ) ;
tolua_function ( tolua_S , " GetSignLines " , tolua_cWorld_GetSignLines ) ;
2014-12-12 07:32:52 -05:00
tolua_function ( tolua_S , " PrepareChunk " , tolua_cWorld_PrepareChunk ) ;
2013-11-20 15:53:29 -05:00
tolua_function ( tolua_S , " QueueTask " , tolua_cWorld_QueueTask ) ;
2014-01-16 14:30:25 -05:00
tolua_function ( tolua_S , " ScheduleTask " , tolua_cWorld_ScheduleTask ) ;
2013-11-20 15:53:29 -05:00
tolua_function ( tolua_S , " SetSignLines " , tolua_cWorld_SetSignLines ) ;
tolua_function ( tolua_S , " TryGetHeight " , tolua_cWorld_TryGetHeight ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
2014-02-23 06:25:02 -05:00
tolua_beginmodule ( tolua_S , " cMapManager " ) ;
tolua_function ( tolua_S , " DoWithMap " , tolua_DoWithID < cMapManager , cMap , & cMapManager : : DoWithMap > ) ;
tolua_endmodule ( tolua_S ) ;
2014-03-01 07:03:16 -05:00
tolua_beginmodule ( tolua_S , " cScoreboard " ) ;
tolua_function ( tolua_S , " ForEachObjective " , tolua_ForEach < cScoreboard , cObjective , & cScoreboard : : ForEachObjective > ) ;
2014-03-01 07:27:55 -05:00
tolua_function ( tolua_S , " ForEachTeam " , tolua_ForEach < cScoreboard , cTeam , & cScoreboard : : ForEachTeam > ) ;
2014-03-01 07:03:16 -05:00
tolua_endmodule ( tolua_S ) ;
2014-02-23 06:25:02 -05:00
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cPlugin " ) ;
2015-04-19 04:57:41 -04:00
tolua_function ( tolua_S , " GetDirectory " , tolua_cPlugin_GetDirectory ) ;
tolua_function ( tolua_S , " GetLocalDirectory " , tolua_cPlugin_GetLocalDirectory ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cPluginManager " ) ;
2013-09-18 10:46:13 -04:00
tolua_function ( tolua_S , " AddHook " , tolua_cPluginManager_AddHook ) ;
2013-02-15 08:00:59 -05:00
tolua_function ( tolua_S , " BindCommand " , tolua_cPluginManager_BindCommand ) ;
tolua_function ( tolua_S , " BindConsoleCommand " , tolua_cPluginManager_BindConsoleCommand ) ;
2014-01-21 16:59:08 -05:00
tolua_function ( tolua_S , " CallPlugin " , tolua_cPluginManager_CallPlugin ) ;
2015-04-23 13:41:01 -04:00
tolua_function ( tolua_S , " DoWithPlugin " , tolua_StaticDoWith < cPluginManager , cPlugin , & cPluginManager : : DoWithPlugin > ) ;
2015-04-19 04:57:41 -04:00
tolua_function ( tolua_S , " FindPlugins " , tolua_cPluginManager_FindPlugins ) ;
2013-02-15 08:00:59 -05:00
tolua_function ( tolua_S , " ForEachCommand " , tolua_cPluginManager_ForEachCommand ) ;
tolua_function ( tolua_S , " ForEachConsoleCommand " , tolua_cPluginManager_ForEachConsoleCommand ) ;
2015-04-23 13:41:01 -04:00
tolua_function ( tolua_S , " ForEachPlugin " , tolua_StaticForEach < cPluginManager , cPlugin , & cPluginManager : : ForEachPlugin > ) ;
2013-08-05 09:26:43 -04:00
tolua_function ( tolua_S , " GetAllPlugins " , tolua_cPluginManager_GetAllPlugins ) ;
2013-12-05 16:03:07 -05:00
tolua_function ( tolua_S , " GetCurrentPlugin " , tolua_cPluginManager_GetCurrentPlugin ) ;
2015-04-19 04:57:41 -04:00
tolua_function ( tolua_S , " GetPlugin " , tolua_cPluginManager_GetPlugin ) ;
2014-02-04 18:16:33 -05:00
tolua_function ( tolua_S , " LogStackTrace " , tolua_cPluginManager_LogStackTrace ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cPlayer " ) ;
2014-08-19 11:34:11 -04:00
tolua_function ( tolua_S , " GetPermissions " , tolua_cPlayer_GetPermissions ) ;
tolua_function ( tolua_S , " OpenWindow " , tolua_cPlayer_OpenWindow ) ;
tolua_function ( tolua_S , " PermissionMatches " , tolua_cPlayer_PermissionMatches ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-16 04:35:07 -04:00
2013-05-30 16:40:43 -04:00
tolua_beginmodule ( tolua_S , " cLuaWindow " ) ;
2013-05-31 03:16:14 -04:00
tolua_function ( tolua_S , " SetOnClosing " , tolua_SetObjectCallback < cLuaWindow , & cLuaWindow : : SetOnClosing > ) ;
tolua_function ( tolua_S , " SetOnSlotChanged " , tolua_SetObjectCallback < cLuaWindow , & cLuaWindow : : SetOnSlotChanged > ) ;
2013-05-30 16:40:43 -04:00
tolua_endmodule ( tolua_S ) ;
2013-08-19 03:39:18 -04:00
tolua_beginmodule ( tolua_S , " cPluginLua " ) ;
tolua_function ( tolua_S , " AddWebTab " , tolua_cPluginLua_AddWebTab ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2014-10-20 16:55:07 -04:00
tolua_cclass ( tolua_S , " HTTPRequest " , " HTTPRequest " , " " , nullptr ) ;
2014-07-19 08:53:41 -04:00
tolua_beginmodule ( tolua_S , " HTTPRequest " ) ;
// tolua_variable(tolua_S, "Method", tolua_get_HTTPRequest_Method, tolua_set_HTTPRequest_Method);
// tolua_variable(tolua_S, "Path", tolua_get_HTTPRequest_Path, tolua_set_HTTPRequest_Path);
tolua_variable ( tolua_S , " FormData " , tolua_get_HTTPRequest_FormData , 0 ) ;
tolua_variable ( tolua_S , " Params " , tolua_get_HTTPRequest_Params , 0 ) ;
tolua_variable ( tolua_S , " PostParams " , tolua_get_HTTPRequest_PostParams , 0 ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2013-07-28 20:37:59 -04:00
tolua_beginmodule ( tolua_S , " cWebAdmin " ) ;
2014-08-09 16:54:43 -04:00
tolua_function ( tolua_S , " GetHTMLEscapedString " , tolua_AllToLua_cWebAdmin_GetHTMLEscapedString ) ;
tolua_function ( tolua_S , " GetPlugins " , tolua_cWebAdmin_GetPlugins ) ;
tolua_function ( tolua_S , " GetURLEncodedString " , tolua_AllToLua_cWebAdmin_GetURLEncodedString ) ;
2013-07-28 20:37:59 -04:00
tolua_endmodule ( tolua_S ) ;
tolua_beginmodule ( tolua_S , " cWebPlugin " ) ;
tolua_function ( tolua_S , " GetTabNames " , tolua_cWebPlugin_GetTabNames ) ;
tolua_endmodule ( tolua_S ) ;
2012-06-14 09:06:06 -04:00
2012-06-16 04:35:07 -04:00
tolua_beginmodule ( tolua_S , " cClientHandle " ) ;
tolua_constant ( tolua_S , " MAX_VIEW_DISTANCE " , cClientHandle : : MAX_VIEW_DISTANCE ) ;
2013-08-05 09:26:43 -04:00
tolua_constant ( tolua_S , " MIN_VIEW_DISTANCE " , cClientHandle : : MIN_VIEW_DISTANCE ) ;
2014-01-09 08:25:37 -05:00
tolua_function ( tolua_S , " SendPluginMessage " , tolua_cClientHandle_SendPluginMessage ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2014-07-30 07:44:03 -04:00
tolua_beginmodule ( tolua_S , " cMojangAPI " ) ;
2014-08-03 15:32:20 -04:00
tolua_function ( tolua_S , " AddPlayerNameToUUIDMapping " , tolua_cMojangAPI_AddPlayerNameToUUIDMapping ) ;
tolua_function ( tolua_S , " GetPlayerNameFromUUID " , tolua_cMojangAPI_GetPlayerNameFromUUID ) ;
tolua_function ( tolua_S , " GetUUIDFromPlayerName " , tolua_cMojangAPI_GetUUIDFromPlayerName ) ;
tolua_function ( tolua_S , " GetUUIDsFromPlayerNames " , tolua_cMojangAPI_GetUUIDsFromPlayerNames ) ;
2014-08-21 09:19:30 -04:00
tolua_function ( tolua_S , " MakeUUIDDashed " , tolua_cMojangAPI_MakeUUIDDashed ) ;
tolua_function ( tolua_S , " MakeUUIDShort " , tolua_cMojangAPI_MakeUUIDShort ) ;
2014-07-30 07:44:03 -04:00
tolua_endmodule ( tolua_S ) ;
2013-04-10 15:52:03 -04:00
tolua_beginmodule ( tolua_S , " cItemGrid " ) ;
tolua_function ( tolua_S , " GetSlotCoords " , Lua_ItemGrid_GetSlotCoords ) ;
tolua_endmodule ( tolua_S ) ;
2015-02-21 03:41:14 -05:00
tolua_beginmodule ( tolua_S , " cCryptoHash " ) ;
tolua_function ( tolua_S , " md5 " , tolua_md5 ) ;
tolua_function ( tolua_S , " md5HexString " , tolua_md5HexString ) ;
tolua_function ( tolua_S , " sha1 " , tolua_sha1 ) ;
tolua_function ( tolua_S , " sha1HexString " , tolua_sha1HexString ) ;
tolua_endmodule ( tolua_S ) ;
2014-08-08 17:12:22 -04:00
2015-02-23 06:53:02 -05:00
tolua_beginmodule ( tolua_S , " cStringCompression " ) ;
tolua_function ( tolua_S , " CompressStringZLIB " , tolua_CompressStringZLIB ) ;
tolua_function ( tolua_S , " UncompressStringZLIB " , tolua_UncompressStringZLIB ) ;
tolua_function ( tolua_S , " CompressStringGZIP " , tolua_CompressStringGZIP ) ;
tolua_function ( tolua_S , " UncompressStringGZIP " , tolua_UncompressStringGZIP ) ;
tolua_function ( tolua_S , " InflateString " , tolua_InflateString ) ;
tolua_endmodule ( tolua_S ) ;
2014-08-08 17:12:22 -04:00
BindRankManager ( tolua_S ) ;
2015-01-28 09:14:05 -05:00
BindNetwork ( tolua_S ) ;
2012-06-14 09:06:06 -04:00
2015-03-21 10:18:17 -04:00
tolua_beginmodule ( tolua_S , " cEntity " ) ;
tolua_constant ( tolua_S , " INVALID_ID " , cEntity : : INVALID_ID ) ;
tolua_endmodule ( tolua_S ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
}