2017-09-19 04:34:08 -04:00
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"
2017-08-30 10:00:06 -04:00
# include "mbedtls/md5.h"
# include "mbedtls/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-01-22 13:35:36 -05:00
# include "../BlockArea.h"
2014-07-30 16:19:51 -04:00
# include "../BlockEntities/BeaconEntity.h"
2015-09-24 04:48:33 -04:00
# include "../BlockEntities/BrewingstandEntity.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"
2017-08-18 06:29:54 -04:00
# include "../BoundingBox.h"
2019-08-10 07:15:51 -04:00
# include "BuildInfo.h"
2017-08-18 06:29:54 -04:00
# include "../ClientHandle.h"
# include "../CommandOutput.h"
# include "../CompositeChat.h"
# include "../Entities/Player.h"
2016-06-30 13:35:00 -04:00
# include "../Generating/ChunkDesc.h"
2017-08-18 06:29:54 -04:00
# include "../HTTP/UrlParser.h"
# include "../Item.h"
2013-12-08 06:17:54 -05:00
# include "../LineBlockTracer.h"
2017-08-27 17:10:20 -04:00
# include "../Server.h"
2017-08-18 06:29:54 -04:00
# include "../Root.h"
2015-02-22 11:34:20 -05:00
# include "../StringCompression.h"
2017-08-18 06:29:54 -04:00
# include "../WebAdmin.h"
# include "../World.h"
2015-05-10 16:51:16 -04:00
2012-06-14 09:06:06 -04:00
2012-07-02 07:21:21 -04:00
2017-12-21 06:36:58 -05:00
// Hotpatching the Macro to prevent a Clang Warning (0 for pointer used)
# undef lua_tostring
# define lua_tostring(L, i) lua_tolstring(L, (i), nullptr)
2016-06-12 12:11:40 -04:00
////////////////////////////////////////////////////////////////////////////////
// LuaCommandHandler:
/** Defines a bridge between cPluginManager::cCommandHandler and cLuaState::cCallback. */
class LuaCommandHandler :
public cPluginManager : : cCommandHandler
{
public :
2016-06-27 14:49:59 -04:00
LuaCommandHandler ( cLuaState : : cCallbackPtr & & a_Callback ) :
m_Callback ( std : : move ( a_Callback ) )
2016-06-12 12:11:40 -04:00
{
}
virtual bool ExecuteCommand (
const AStringVector & a_Split ,
cPlayer * a_Player ,
const AString & a_Command ,
cCommandOutputCallback * a_Output
) override
{
bool res = false ;
AString s ;
if ( ! m_Callback - > Call ( a_Split , a_Player , a_Command , cLuaState : : Return , res , s ) )
{
return false ;
}
if ( res & & ( a_Output ! = nullptr ) & & ! s . empty ( ) )
{
a_Output - > Out ( s ) ;
}
return res ;
}
protected :
cLuaState : : cCallbackPtr m_Callback ;
} ;
////////////////////////////////////////////////////////////////////////////////
// cManualBindings:
2014-07-17 16:50:58 -04:00
// Better error reporting for Lua
2015-05-13 05:30:57 -04:00
int cManualBindings : : 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 ;
}
2018-01-03 12:41:16 -05:00
int cManualBindings : : lua_do_error ( lua_State * L , const char * a_pFormat , fmt : : ArgList a_ArgList )
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
luaL_where ( L , 1 ) ;
2018-01-03 12:41:16 -05:00
AString FmtMsg = Printf ( msg . c_str ( ) , a_ArgList ) ;
lua_pushlstring ( L , FmtMsg . data ( ) , FmtMsg . size ( ) ) ;
2013-02-02 18:55:29 -05:00
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 )
{
2015-05-13 05:30:57 -04:00
return cManualBindings : : lua_do_error ( LuaState , " Error in function call '#funcname#': Requires 3 arguments, got %i " , NumArgs ) ;
2014-08-05 07:47:10 -04:00
}
if ( ! lua_isnumber ( LuaState , 1 ) | | ! lua_isnumber ( LuaState , 2 ) | | ! lua_isnumber ( LuaState , 3 ) )
{
2015-05-13 05:30:57 -04:00
return cManualBindings : : lua_do_error ( LuaState , " Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3 " ) ;
2014-08-05 07:47:10 -04:00
}
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 ;
2015-08-14 16:19:15 -04:00
size_t UncompressedSize = 0 ;
2015-02-23 06:53:02 -05:00
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
{
2015-04-30 05:44:42 -04:00
// Get the params:
2013-08-06 11:17:26 -04:00
cLuaState LuaState ( tolua_S ) ;
2015-04-30 05:44:42 -04:00
AString str , delim ;
LuaState . GetStackValues ( 1 , str , delim ) ;
2013-08-06 11:17:26 -04:00
2015-04-30 05:44:42 -04:00
// Execute and push the result:
LuaState . Push ( StringSplit ( str , delim ) ) ;
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 )
{
2015-05-13 05:30:57 -04:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamString ( 1 , 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2013-09-11 15:12:34 -04:00
2015-05-13 05:30:57 -04:00
// Process:
AString str , delim ;
L . GetStackValues ( 1 , str , delim ) ;
L . Push ( StringSplitAndTrim ( str , delim ) ) ;
2013-09-11 15:12:34 -04:00
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 ) )
{
2018-05-02 03:50:36 -04:00
return static_cast < 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 ) )
{
2018-05-02 03:50:36 -04:00
LogLevel = cCompositeChat : : MessageTypeToLogLevel ( static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) - > GetMessageType ( ) ) ;
2014-04-01 03:32:14 -04:00
}
2016-02-05 16:45:45 -05:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-04-01 16:47:39 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-04-01 16:47:39 -04:00
AString Src ;
L . GetStackValue ( 1 , Src ) ;
AString res = Base64Decode ( Src ) ;
L . Push ( res ) ;
return 1 ;
}
2015-05-13 05:30:57 -04:00
cPluginLua * cManualBindings : : 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
}
2018-05-02 03:50:36 -04:00
cPluginLua * Plugin = static_cast < cPluginLua * > ( const_cast < void * > ( lua_topointer ( L , - 1 ) ) ) ;
2013-05-30 15:34:09 -04:00
lua_pop ( L , 1 ) ;
2016-02-05 16:45:45 -05:00
2013-05-30 15:34:09 -04:00
return Plugin ;
}
2013-08-05 09:41:24 -04:00
2015-09-26 16:54:18 -04:00
static int tolua_cFile_ChangeFileExt ( lua_State * tolua_S )
{
// API signature:
// ChangeFileExt(string, string) -> string
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 , 3 ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Execute:
AString FileName , NewExt ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , FileName , NewExt ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : ChangeFileExt ( FileName , NewExt ) ) ;
return 1 ;
}
static int tolua_cFile_Copy ( lua_State * tolua_S )
{
// API signature:
// cFile:Copy(string, string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 , 3 ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Execute:
AString SrcFile , DstFile ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , SrcFile , DstFile ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : Copy ( SrcFile , DstFile ) ) ;
return 1 ;
}
static int tolua_cFile_CreateFolder ( lua_State * tolua_S )
{
// API signature:
// cFile:CreateFolder(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString FolderPath ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , FolderPath ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : CreateFolder ( FolderPath ) ) ;
return 1 ;
}
static int tolua_cFile_CreateFolderRecursive ( lua_State * tolua_S )
{
// API signature:
// cFile:CreateFolderRecursive(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString FolderPath ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , FolderPath ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : CreateFolderRecursive ( FolderPath ) ) ;
return 1 ;
}
static int tolua_cFile_Delete ( lua_State * tolua_S )
{
// API signature:
// cFile:Delete(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : Delete ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_DeleteFile ( lua_State * tolua_S )
{
// API signature:
// cFile:DeleteFile(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : DeleteFile ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_DeleteFolder ( lua_State * tolua_S )
{
// API signature:
// cFile:DeleteFolder(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : DeleteFolder ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_DeleteFolderContents ( lua_State * tolua_S )
{
// API signature:
// cFile:DeleteFolderContents(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : DeleteFolderContents ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_Exists ( lua_State * tolua_S )
{
// API signature:
// cFile:Exists(string) -> bool
// Obsolete, use IsFile() or IsFolder() instead
cLuaState L ( tolua_S ) ;
LOGWARNING ( " cFile:Exists() is obsolete, use cFile:IsFolder() or cFile:IsFile() instead! " ) ;
L . LogStackTrace ( ) ;
// Check params:
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : Exists ( Path ) ) ;
return 1 ;
}
2013-11-22 14:11:24 -05:00
static int tolua_cFile_GetFolderContents ( lua_State * tolua_S )
{
2015-09-26 16:54:18 -04:00
// API signature:
// cFile:GetFolderContents(string) -> {string, string, ...}
2015-04-30 05:44:42 -04:00
// Check params:
2013-11-22 14:11:24 -05:00
cLuaState LuaState ( tolua_S ) ;
if (
! LuaState . CheckParamUserTable ( 1 , " cFile " ) | |
! LuaState . CheckParamString ( 2 ) | |
! LuaState . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2015-04-30 05:44:42 -04:00
// Get params:
AString Folder ;
2016-08-06 16:08:18 -04:00
VERIFY ( LuaState . GetStackValues ( 2 , Folder ) ) ;
2015-04-30 05:44:42 -04:00
// Execute and push result:
LuaState . Push ( cFile : : GetFolderContents ( Folder ) ) ;
return 1 ;
}
2015-09-26 16:54:18 -04:00
static int tolua_cFile_GetLastModificationTime ( lua_State * tolua_S )
{
// API signature:
// cFile:GetLastModificationTime(string) -> number
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : GetLastModificationTime ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_GetSize ( lua_State * tolua_S )
{
// API signature:
// cFile:GetSize(string) -> number
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : GetSize ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_IsFile ( lua_State * tolua_S )
{
// API signature:
// cFile:IsFile(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : IsFile ( Path ) ) ;
return 1 ;
}
static int tolua_cFile_IsFolder ( lua_State * tolua_S )
{
// API signature:
// cFile:IsFolder(string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Execute:
AString Path ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , Path ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : IsFolder ( Path ) ) ;
return 1 ;
}
2015-04-30 05:44:42 -04:00
static int tolua_cFile_ReadWholeFile ( lua_State * tolua_S )
{
2015-09-26 16:54:18 -04:00
// API signature:
// cFile:ReadWholeFile(string) -> string
2015-04-30 05:44:42 -04:00
// Check params:
2015-05-13 05:30:57 -04:00
cLuaState LuaState ( tolua_S ) ;
2014-01-19 17:49:19 -05:00
if (
2015-05-13 05:30:57 -04:00
! LuaState . CheckParamUserTable ( 1 , " cFile " ) | |
! LuaState . CheckParamString ( 2 ) | |
! LuaState . CheckParamEnd ( 3 )
2014-01-19 17:49:19 -05:00
)
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
}
2016-02-05 16:45:45 -05:00
2015-05-13 05:30:57 -04:00
// Get params:
AString FileName ;
2016-08-06 16:08:18 -04:00
VERIFY ( LuaState . GetStackValues ( 2 , FileName ) ) ;
2013-10-12 16:24:59 -04:00
2015-05-13 05:30:57 -04:00
// Execute and push result:
LuaState . Push ( cFile : : ReadWholeFile ( FileName ) ) ;
return 1 ;
2014-01-14 15:17:03 -05:00
}
2013-10-12 16:24:59 -04:00
2014-01-16 13:56:08 -05:00
2015-09-26 16:54:18 -04:00
static int tolua_cFile_Rename ( lua_State * tolua_S )
{
// API signature:
// cFile:Rename(string, string) -> bool
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cFile " ) | |
! L . CheckParamString ( 2 , 3 ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Execute:
AString SrcPath , DstPath ;
2016-08-06 16:08:18 -04:00
VERIFY ( L . GetStackValues ( 2 , SrcPath , DstPath ) ) ;
2015-09-26 16:54:18 -04:00
L . Push ( cFile : : Rename ( SrcPath , DstPath ) ) ;
return 1 ;
}
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 )
{
2015-05-13 05:30:57 -04:00
cPluginLua * Plugin = cManualBindings : : 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
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Retrieve the cPlugin from the LuaState:
2015-05-13 05:30:57 -04:00
cPluginLua * Plugin = cManualBindings : : 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 ;
}
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Retrieve and check the hook type
2016-03-02 04:12:43 -05:00
int HookType ;
if ( ! S . GetStackValue ( a_ParamIdx , HookType ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Cannot read the hook type. " ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
2013-08-21 15:29:30 -04:00
if ( ! a_PluginManager - > IsValidHookType ( HookType ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Invalid HOOK_TYPE parameter: %d " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Add the hook to the plugin
2016-06-27 14:49:59 -04:00
cLuaState : : cCallbackPtr callback ;
2016-03-02 04:12:43 -05:00
if ( ! S . GetStackValue ( a_ParamIdx + 1 , callback ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Cannot read the callback parameter " ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
2016-06-27 14:49:59 -04:00
if ( ! Plugin - > AddHookCallback ( HookType , std : : move ( callback ) ) )
2013-08-21 15:29:30 -04:00
{
LOGWARNING ( " cPluginManager.AddHook(): Cannot add hook %d, unknown error. " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
a_PluginManager - > AddHook ( Plugin , HookType ) ;
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// 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
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Retrieve and check the cPlugin parameter
2018-05-02 03:50:36 -04:00
cPluginLua * Plugin = static_cast < cPluginLua * > ( tolua_tousertype ( S , a_ParamIdx , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2015-05-13 05:30:57 -04:00
if ( Plugin ! = cManualBindings : : GetLuaPlugin ( S ) )
2013-08-21 15:29:30 -04:00
{
// 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 ;
}
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// Retrieve and check the hook type
2015-07-29 11:04:03 -04:00
int HookType = static_cast < int > ( tolua_tonumber ( S , a_ParamIdx + 1 , - 1 ) ) ;
2013-08-21 15:29:30 -04:00
if ( ! a_PluginManager - > IsValidHookType ( HookType ) )
{
LOGWARNING ( " cPluginManager.AddHook(): Invalid HOOK_TYPE parameter: %d " , HookType ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// 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:
2016-06-27 14:49:59 -04:00
cLuaState : : cCallbackPtr callback ;
2016-03-02 04:12:43 -05:00
lua_getglobal ( S , FnName ) ;
bool res = S . GetStackValue ( - 1 , callback ) ;
lua_pop ( S , 1 ) ;
if ( ! res | | ! callback - > IsValid ( ) )
2013-08-21 15:29:30 -04:00
{
LOGWARNING ( " cPluginManager.AddHook(): Function %s not found. Hook not added. " , FnName ) ;
S . LogStackTrace ( ) ;
return 0 ;
}
a_PluginManager - > AddHook ( Plugin , HookType ) ;
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
// 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
*/
2016-02-05 16:45:45 -05:00
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
2018-05-02 03:50:36 -04:00
PlgMgr = static_cast < cPluginManager * > ( tolua_tousertype ( S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 + + ;
}
2016-02-05 16:45:45 -05:00
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 ) ;
}
2016-02-05 16:45:45 -05:00
2013-08-21 15:29:30 -04:00
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
{
2015-05-14 13:46:18 -04:00
/*
Function signature :
cPluginManager : Get ( ) : ForEachCommand ( a_CallbackFn ) - > bool
*/
2012-06-14 09:06:06 -04:00
2015-05-14 13:46:18 -04:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cPluginManager " ) | |
! L . CheckParamFunction ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
2012-06-14 09:06:06 -04:00
{
2013-02-01 14:55:42 -05:00
return 0 ;
2012-06-14 09:06:06 -04:00
}
2013-02-01 14:55:42 -05:00
2015-05-14 13:46:18 -04:00
// Get the params:
cLuaState : : cRef FnRef ;
L . GetStackValues ( 2 , FnRef ) ;
if ( ! FnRef . IsValid ( ) )
2013-02-01 14:55:42 -05:00
{
LOGWARN ( " Error in function call 'ForEachCommand': Could not get function reference of parameter #1 " ) ;
return 0 ;
}
2015-05-14 13:46:18 -04:00
// Callback for enumerating all commands:
2013-02-01 14:55:42 -05:00
class cLuaCallback : public cPluginManager : : cCommandEnumCallback
{
public :
2015-05-14 13:46:18 -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-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 ) ;
2015-05-14 13:46:18 -04:00
bool ret = false ;
m_LuaState . Call ( m_FnRef , a_Command , a_Permission , a_HelpString , cLuaState : : Return , ret ) ;
return ret ;
2013-02-01 14:55:42 -05:00
}
2015-05-14 13:46:18 -04:00
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
} Callback ( L , FnRef ) ;
2013-02-01 14:55:42 -05:00
2015-05-14 13:46:18 -04:00
// Execute and push the returned value:
L . Push ( cPluginManager : : Get ( ) - > ForEachCommand ( Callback ) ) ;
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
{
2015-05-14 13:46:18 -04:00
/*
Function signature :
cPluginManager : Get ( ) : ForEachConsoleCommand ( a_CallbackFn ) - > bool
*/
2012-06-14 09:06:06 -04:00
2015-05-14 13:46:18 -04:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cPluginManager " ) | |
! L . CheckParamFunction ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
2012-06-14 09:06:06 -04:00
{
2013-02-15 08:00:59 -05:00
return 0 ;
}
2015-05-14 13:46:18 -04:00
// Get the params:
cLuaState : : cRef FnRef ;
L . GetStackValues ( 2 , FnRef ) ;
if ( ! FnRef . IsValid ( ) )
2013-02-15 08:00:59 -05:00
{
LOGWARN ( " Error in function call 'ForEachConsoleCommand': Could not get function reference of parameter #1 " ) ;
return 0 ;
}
2015-05-14 13:46:18 -04:00
// Callback for enumerating all commands:
2013-02-15 08:00:59 -05:00
class cLuaCallback : public cPluginManager : : cCommandEnumCallback
{
public :
2015-05-14 13:46:18 -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-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 ) ;
2015-05-14 13:46:18 -04:00
bool ret = false ;
m_LuaState . Call ( m_FnRef , a_Command , a_HelpString , cLuaState : : Return , ret ) ;
return ret ;
2012-10-13 19:34:47 -04:00
}
2015-05-14 13:46:18 -04:00
cLuaState & m_LuaState ;
cLuaState : : cRef & m_FnRef ;
} Callback ( L , FnRef ) ;
2013-02-15 08:00:59 -05:00
2015-05-14 13:46:18 -04:00
// Execute and push the returned value:
L . Push ( cPluginManager : : Get ( ) - > ForEachConsoleCommand ( Callback ) ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2013-02-15 08:00:59 -05:00
2016-06-12 12:11:40 -04:00
static int tolua_cPluginManager_BindCommand ( lua_State * a_LuaState )
2013-02-01 14:55:42 -05:00
{
2013-09-18 10:46:13 -04:00
/* Function signatures:
2016-09-08 17:06:38 -04:00
cPluginManager : Get ( ) : BindCommand ( Command , Permission , Function , HelpString ) - - regular
cPluginManager : BindCommand ( Command , Permission , Function , HelpString ) - - static
cPluginManager . BindCommand ( Command , Permission , Function , HelpString ) - - without the " self " param
2013-09-18 10:46:13 -04:00
*/
2016-06-12 12:11:40 -04:00
cLuaState L ( a_LuaState ) ;
2015-05-13 05:30:57 -04:00
cPluginLua * Plugin = cManualBindings : : 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
}
2016-02-05 16:45:45 -05:00
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 ( ) ;
2016-06-12 12:11:40 -04:00
AString Command , Permission , HelpString ;
cLuaState : : cCallbackPtr Handler ;
L . GetStackValues ( idx , Command , Permission , Handler , HelpString ) ;
if ( ! Handler - > IsValid ( ) )
2013-02-01 14:55:42 -05:00
{
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 ;
}
2016-02-05 16:45:45 -05:00
2016-06-27 14:49:59 -04:00
auto CommandHandler = std : : make_shared < LuaCommandHandler > ( std : : move ( Handler ) ) ;
2016-06-12 12:11:40 -04:00
if ( ! self - > BindCommand ( Command , Plugin , CommandHandler , Permission , HelpString ) )
2013-02-01 14:55:42 -05:00
{
2013-11-13 09:54:56 -05:00
// Refused. Possibly already bound. Error message has been given, display the callstack:
2016-06-12 12:11:40 -04:00
L . LogStackTrace ( ) ;
2013-02-01 14:55:42 -05:00
return 0 ;
}
2016-02-05 16:45:45 -05:00
2016-06-12 12:11:40 -04:00
L . Push ( true ) ;
2014-03-14 06:18:14 -04:00
return 1 ;
2013-02-01 14:55:42 -05:00
}
2012-06-14 09:06:06 -04:00
2016-06-12 12:11:40 -04:00
static int tolua_cPluginManager_BindConsoleCommand ( lua_State * a_LuaState )
2013-02-15 08:00:59 -05:00
{
2013-09-18 10:50:05 -04:00
/* Function signatures:
2016-09-08 17:06:38 -04:00
cPluginManager : Get ( ) : BindConsoleCommand ( Command , Function , HelpString ) - - regular
cPluginManager : BindConsoleCommand ( Command , Function , HelpString ) - - static
cPluginManager . BindConsoleCommand ( Command , Function , HelpString ) - - without the " self " param
2013-09-18 10:50:05 -04:00
*/
2016-02-05 16:45:45 -05:00
2013-02-15 08:00:59 -05:00
// Get the plugin identification out of LuaState:
2016-06-12 12:11:40 -04:00
cLuaState L ( a_LuaState ) ;
2015-05-13 05:30:57 -04:00
cPluginLua * Plugin = cManualBindings : : 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
}
2016-02-05 16:45:45 -05:00
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 ( ) ;
2016-06-12 12:11:40 -04:00
AString Command , HelpString ;
cLuaState : : cCallbackPtr Handler ;
L . GetStackValues ( idx , Command , Handler , HelpString ) ;
if ( ! Handler - > IsValid ( ) )
2013-02-15 08:00:59 -05:00
{
2016-06-12 12:11:40 -04:00
LOGERROR ( " \" BindConsoleCommand \" : Cannot create a function reference. Console command \" %s \" not bound. " , Command . c_str ( ) ) ;
2013-02-15 08:00:59 -05:00
return 0 ;
}
2016-02-05 16:45:45 -05:00
2016-06-27 14:49:59 -04:00
auto CommandHandler = std : : make_shared < LuaCommandHandler > ( std : : move ( Handler ) ) ;
2016-06-12 12:11:40 -04:00
if ( ! self - > BindConsoleCommand ( Command , Plugin , CommandHandler , HelpString ) )
2013-02-15 08:00:59 -05:00
{
2013-11-13 09:54:56 -05:00
// Refused. Possibly already bound. Error message has been given, display the callstack:
2016-06-12 12:11:40 -04:00
L . LogStackTrace ( ) ;
2013-02-15 08:00:59 -05:00
return 0 ;
}
2016-06-12 12:11:40 -04:00
L . Push ( true ) ;
2014-03-14 06:18:14 -04:00
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 . . . )
*/
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
// Check the parameters:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cPluginManager " ) | |
! L . CheckParamString ( 2 , 3 ) )
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
// 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 ;
}
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
// If requesting calling the current plugin, refuse:
2015-05-13 05:30:57 -04:00
cPluginLua * ThisPlugin = cManualBindings : : 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 ;
}
2016-02-05 16:45:45 -05:00
2014-01-21 16:59:08 -05:00
// Call the destination plugin using a plugin callback:
2017-09-11 17:20:49 -04:00
int NumReturns = 0 ;
auto PluginCallback = [ & ] ( cPlugin & a_Plugin )
2014-01-21 16:59:08 -05:00
{
2017-09-11 17:20:49 -04:00
if ( ! a_Plugin . IsLoaded ( ) )
2015-04-19 04:57:41 -04:00
{
return false ;
}
2017-09-11 17:20:49 -04:00
NumReturns = static_cast < cPluginLua & > ( a_Plugin ) . CallFunctionFromForeignState (
FunctionName , L , 4 , lua_gettop ( L )
2014-01-21 16:59:08 -05:00
) ;
return true ;
2017-09-11 17:20:49 -04:00
} ;
if ( ! cPluginManager : : Get ( ) - > DoWithPlugin ( PluginName , PluginCallback ) )
2014-01-21 16:59:08 -05:00
{
return 0 ;
}
2017-09-11 17:20:49 -04:00
if ( NumReturns < 0 )
2015-05-07 17:02:18 -04:00
{
// The call has failed, there are zero return values. Do NOT return negative number (Lua considers that a "yield")
return 0 ;
}
2017-09-11 17:20:49 -04:00
return NumReturns ;
2014-01-21 16:59:08 -05:00
}
2015-05-10 16:51:16 -04:00
static int tolua_cPluginManager_ExecuteConsoleCommand ( lua_State * tolua_S )
{
/*
Function signature :
cPluginManager : ExecuteConsoleCommand ( EntireCommandStr ) - > OutputString
*/
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cPluginManager " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the params:
AString Command ;
L . GetStackValues ( 2 , Command ) ;
auto Split = StringSplit ( Command , " " ) ;
// Store the command output in a string:
cStringAccumCommandOutputCallback CommandOutput ;
L . Push ( cPluginManager : : Get ( ) - > ExecuteConsoleCommand ( Split , CommandOutput , Command ) ) ;
L . Push ( CommandOutput . GetAccum ( ) ) ;
return 2 ;
}
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-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:
2018-05-02 03:50:36 -04:00
cPlayer * self = static_cast < cPlayer * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
if ( self = = nullptr )
2012-06-14 09:06:06 -04:00
{
2015-09-24 10:04:44 -04:00
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , static_cast < void * > ( self ) ) ;
2014-08-19 11:34:11 -04:00
return 0 ;
2012-06-14 09:06:06 -04:00
}
2016-02-05 16:45:45 -05: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 ;
}
2015-04-25 13:40:44 -04:00
static int tolua_cPlayer_GetRestrictions ( lua_State * tolua_S )
{
// Function signature: cPlayer:GetRestrictions() -> {restrictions-array}
// Check the params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cPlayer " ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
// Get the params:
2018-05-02 03:50:36 -04:00
cPlayer * self = static_cast < cPlayer * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2015-04-25 13:40:44 -04:00
if ( self = = nullptr )
{
2015-09-24 10:04:44 -04:00
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , static_cast < void * > ( self ) ) ;
2015-04-25 13:40:44 -04:00
return 0 ;
}
2016-02-05 16:45:45 -05:00
2015-04-25 13:40:44 -04:00
// Push the permissions:
L . Push ( self - > GetRestrictions ( ) ) ;
return 1 ;
}
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 ) ;
2016-02-05 16:45:45 -05:00
2014-08-19 11:34:11 -04:00
// 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 ;
}
2017-08-25 08:43:18 -04:00
static int tolua_cPlayer_GetUUID ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cPlayer " ) )
{
return 0 ;
}
// Get the params:
cPlayer * Self = nullptr ;
L . GetStackValue ( 1 , Self ) ;
// Return the UUID as a string
L . Push ( Self - > GetUUID ( ) . ToShortString ( ) ) ;
return 1 ;
}
2013-05-31 03:16:14 -04:00
template <
class OBJTYPE ,
2016-06-27 14:49:59 -04:00
void ( OBJTYPE : : * SetCallback ) ( cLuaState : : cCallbackPtr & & a_CallbackFn )
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
2013-05-31 03:16:14 -04:00
// Get the parameters - self and the function reference:
2016-06-10 15:30:07 -04:00
cLuaState L ( tolua_S ) ;
OBJTYPE * self ;
cLuaState : : cCallbackPtr callback ;
if ( ! L . GetStackValues ( 1 , self , callback ) )
2016-03-21 04:58:15 -04:00
{
2016-06-10 15:30:07 -04:00
LOGWARNING ( " %s: Cannot get parameters " , __FUNCTION__ ) ;
L . LogStackTrace ( ) ;
2013-05-30 16:40:43 -04:00
return 0 ;
}
2016-02-05 16:45:45 -05:00
2013-05-30 16:40:43 -04:00
// Set the callback
2016-06-27 14:49:59 -04:00
( self - > * SetCallback ) ( std : : move ( callback ) ) ;
2013-05-30 16:40:43 -04:00
return 0 ;
}
2016-03-02 04:05:10 -05:00
// Callback class used for the WebTab:
class cWebTabCallback :
public cWebAdmin : : cWebTabCallback
2012-06-14 09:06:06 -04:00
{
2016-03-02 04:05:10 -05:00
public :
/** The Lua callback to call to generate the page contents. */
cLuaState : : cCallback m_Callback ;
2012-06-14 09:06:06 -04:00
2016-03-02 04:05:10 -05:00
virtual bool Call (
const HTTPRequest & a_Request ,
const AString & a_UrlPath ,
AString & a_Content ,
AString & a_ContentType
) override
2015-08-07 10:44:52 -04:00
{
2016-03-02 04:05:10 -05:00
AString content , contentType ;
2017-05-09 07:21:03 -04:00
return m_Callback . Call ( const_cast < HTTPRequest * > ( & a_Request ) , a_UrlPath , cLuaState : : Return , a_Content , a_ContentType ) ;
2015-08-07 10:44:52 -04:00
}
2016-03-02 04:05:10 -05:00
} ;
2016-03-02 04:05:10 -05:00
2016-03-02 04:05:10 -05:00
static int tolua_cPluginLua_AddWebTab ( lua_State * tolua_S )
{
// OBSOLETE, use cWebAdmin:AddWebTab() instead!
// Function signature:
// cPluginLua:AddWebTab(Title, CallbackFn, [UrlPath])
// TODO: Warn about obsolete API usage
// Only implement after merging the new API change and letting some time for changes in the plugins
// Check params:
cLuaState LuaState ( tolua_S ) ;
cPluginLua * self = cManualBindings : : GetLuaPlugin ( tolua_S ) ;
if ( self = = nullptr )
2012-06-14 09:06:06 -04:00
{
2016-03-02 04:05:10 -05:00
return 0 ;
2012-06-14 09:06:06 -04:00
}
2016-03-02 04:05:10 -05:00
if (
! LuaState . CheckParamString ( 2 ) | |
! LuaState . CheckParamFunction ( 3 ) | |
// Optional string as param 4
! LuaState . CheckParamEnd ( 5 )
)
2012-06-14 09:06:06 -04:00
{
2016-03-02 04:05:10 -05:00
return 0 ;
2012-06-14 09:06:06 -04:00
}
2016-03-02 04:05:10 -05:00
// Read the params:
AString title , urlPath ;
auto callback = std : : make_shared < cWebTabCallback > ( ) ;
if ( ! LuaState . GetStackValues ( 2 , title , callback - > m_Callback ) )
2012-06-14 09:06:06 -04:00
{
2016-03-02 04:05:10 -05:00
LOGWARNING ( " cPlugin:AddWebTab(): Cannot read required parameters " ) ;
return 0 ;
2012-06-14 09:06:06 -04:00
}
2016-03-02 04:05:10 -05:00
if ( ! LuaState . GetStackValue ( 4 , urlPath ) )
2012-06-14 09:06:06 -04:00
{
2016-03-02 04:05:10 -05:00
urlPath = cWebAdmin : : GetURLEncodedString ( title ) ;
2012-06-14 09:06:06 -04:00
}
2016-03-02 04:05:10 -05:00
cRoot : : Get ( ) - > GetWebAdmin ( ) - > AddWebTab ( title , urlPath , self - > GetName ( ) , callback ) ;
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 ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
// Log the obsoletion warning:
LOGWARNING ( " cPlugin:GetDirectory() is obsolete, use cPlugin:GetFolderName() instead. " ) ;
L . LogStackTrace ( ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
// Retrieve the params:
cPlugin * Plugin = static_cast < cPluginLua * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
// 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 ) ;
2016-02-05 16:45:45 -05: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 ( ) ;
2016-02-05 16:45:45 -05:00
2015-04-19 04:57:41 -04:00
// Retrieve the params:
cPlugin * Plugin = static_cast < cPluginLua * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2016-02-05 16:45:45 -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 ;
2015-07-29 11:04:03 -04:00
const unsigned char * SourceString = reinterpret_cast < const unsigned char * > ( lua_tolstring ( tolua_S , 1 , & len ) ) ;
2015-02-21 03:41:14 -05:00
if ( SourceString = = nullptr )
{
return 0 ;
}
2017-08-30 10:00:06 -04:00
mbedtls_md5 ( SourceString , len , Output ) ;
2015-07-29 11:04:03 -04:00
lua_pushlstring ( tolua_S , reinterpret_cast < 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 ;
2015-07-29 11:04:03 -04:00
const unsigned char * SourceString = reinterpret_cast < const unsigned char * > ( lua_tolstring ( tolua_S , 1 , & len ) ) ;
2015-02-21 03:41:14 -05:00
if ( SourceString = = nullptr )
{
return 0 ;
}
2017-08-30 10:00:06 -04:00
mbedtls_md5 ( SourceString , len , md5Output ) ;
2015-02-21 03:41:14 -05:00
// 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 ;
2015-07-29 11:04:03 -04:00
const unsigned char * SourceString = reinterpret_cast < const unsigned char * > ( lua_tolstring ( tolua_S , 1 , & len ) ) ;
2015-02-21 03:41:14 -05:00
if ( SourceString = = nullptr )
{
return 0 ;
}
2017-08-30 10:00:06 -04:00
mbedtls_sha1 ( SourceString , len , Output ) ;
2015-07-29 11:04:03 -04:00
lua_pushlstring ( tolua_S , reinterpret_cast < const char * > ( Output ) , ARRAYCOUNT ( Output ) ) ;
2015-02-21 03:41:14 -05:00
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 ;
2015-07-29 11:04:03 -04:00
const unsigned char * SourceString = reinterpret_cast < const unsigned char * > ( lua_tolstring ( tolua_S , 1 , & len ) ) ;
2015-02-21 03:41:14 -05:00
if ( SourceString = = nullptr )
{
return 0 ;
}
2017-08-30 10:00:06 -04:00
mbedtls_sha1 ( SourceString , len , sha1Output ) ;
2015-02-21 03:41:14 -05:00
// 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 ;
}
2016-09-26 06:47:40 -04:00
static int tolua_get_HTTPRequest_Params ( lua_State * a_LuaState )
2012-06-14 09:06:06 -04:00
{
2016-09-26 06:47:40 -04:00
cLuaState L ( a_LuaState ) ;
HTTPRequest * self ;
if ( ! L . GetStackValues ( 1 , self ) )
2012-06-14 09:06:06 -04:00
{
2016-09-26 06:47:40 -04:00
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid self parameter, expected a HTTPRequest instance " , & err ) ;
return 0 ;
2012-06-14 09:06:06 -04:00
}
2016-09-26 06:47:40 -04:00
L . Push ( self - > Params ) ;
2012-06-14 09:06:06 -04:00
return 1 ;
}
2016-09-26 06:47:40 -04:00
static int tolua_get_HTTPRequest_PostParams ( lua_State * a_LuaState )
2012-06-14 09:06:06 -04:00
{
2016-09-26 06:47:40 -04:00
cLuaState L ( a_LuaState ) ;
HTTPRequest * self ;
if ( ! L . GetStackValues ( 1 , self ) )
{
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid self parameter, expected a HTTPRequest instance " , & err ) ;
return 0 ;
}
L . Push ( self - > PostParams ) ;
return 1 ;
2012-06-14 09:06:06 -04:00
}
2016-09-26 06:47:40 -04:00
static int tolua_get_HTTPRequest_FormData ( lua_State * a_LuaState )
2012-06-14 09:06:06 -04:00
{
2016-09-26 06:47:40 -04:00
cLuaState L ( a_LuaState ) ;
HTTPRequest * self ;
if ( ! L . GetStackValues ( 1 , self ) )
{
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid self parameter, expected a HTTPRequest instance " , & err ) ;
return 0 ;
}
2012-06-14 09:06:06 -04:00
2018-05-02 03:50:36 -04:00
auto & FormData = self - > FormData ;
2016-09-26 06:47:40 -04:00
lua_newtable ( a_LuaState ) ;
int top = lua_gettop ( a_LuaState ) ;
2018-05-02 03:50:36 -04:00
for ( auto & Data : FormData )
2012-06-14 09:06:06 -04:00
{
2018-05-02 03:50:36 -04:00
lua_pushstring ( a_LuaState , Data . first . c_str ( ) ) ;
tolua_pushusertype ( a_LuaState , & Data . second , " HTTPFormData " ) ;
// lua_pushlstring(a_LuaState, Data.second.Value.c_str(), Data.second.Value.size()); // Might contain binary data
2016-09-26 06:47:40 -04:00
lua_settable ( a_LuaState , top ) ;
2012-06-14 09:06:06 -04:00
}
return 1 ;
}
2015-12-25 12:50:25 -05:00
static int tolua_cUrlParser_GetDefaultPort ( lua_State * a_LuaState )
{
// API function signature:
// cUrlParser:GetDefaultPort("scheme") -> number
// Check params:
cLuaState L ( a_LuaState ) ;
if (
! L . CheckParamUserTable ( 1 , " cUrlParser " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Read params from Lua:
AString scheme ;
L . GetStackValue ( 2 , scheme ) ;
// Execute and push result:
L . Push ( cUrlParser : : GetDefaultPort ( scheme ) ) ;
return 1 ;
}
static int tolua_cUrlParser_IsKnownScheme ( lua_State * a_LuaState )
{
// API function signature:
// cUrlParser:IsKnownScheme("scheme") -> bool
// Check params:
cLuaState L ( a_LuaState ) ;
if (
! L . CheckParamUserTable ( 1 , " cUrlParser " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Read params from Lua:
AString scheme ;
L . GetStackValue ( 2 , scheme ) ;
// Execute and push result:
L . Push ( cUrlParser : : IsKnownScheme ( scheme ) ) ;
return 1 ;
}
static int tolua_cUrlParser_Parse ( lua_State * a_LuaState )
{
// API function signature:
// cUrlParser:Parse("url") -> "scheme", "user", "password", "host", portnum, "path", "query", "fragment"
// On error, returns nil and error message
// Check params:
cLuaState L ( a_LuaState ) ;
if (
! L . CheckParamUserTable ( 1 , " cUrlParser " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Read params from Lua:
AString url ;
L . GetStackValue ( 2 , url ) ;
// Execute and push result:
AString scheme , username , password , host , path , query , fragment ;
UInt16 port ;
auto res = cUrlParser : : Parse ( url , scheme , username , password , host , port , path , query , fragment ) ;
if ( ! res . first )
{
// Error, return nil and error msg:
2016-08-16 07:02:08 -04:00
L . Push ( cLuaState : : Nil , res . second ) ;
2015-12-25 12:50:25 -05:00
return 2 ;
}
2016-08-21 05:03:10 -04:00
L . Push ( scheme , username , password , host , port , path , query , fragment ) ;
2015-12-25 12:50:25 -05:00
return 8 ;
}
static int tolua_cUrlParser_ParseAuthorityPart ( lua_State * a_LuaState )
{
// API function signature:
// cUrlParser:ParseAuthorityPart("authority") -> "user", "password", "host", portnum
// On error, returns nil and error message
// Parts not specified in the "authority" are left empty / zero
// Check params:
cLuaState L ( a_LuaState ) ;
if (
! L . CheckParamUserTable ( 1 , " cUrlParser " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Read params from Lua:
AString authPart ;
L . GetStackValue ( 2 , authPart ) ;
// Execute and push result:
AString username , password , host ;
UInt16 port ;
auto res = cUrlParser : : ParseAuthorityPart ( authPart , username , password , host , port ) ;
if ( ! res . first )
{
// Error, return nil and error msg:
2016-08-16 07:02:08 -04:00
L . Push ( cLuaState : : Nil , res . second ) ;
2015-12-25 12:50:25 -05:00
return 2 ;
}
2016-08-21 05:03:10 -04:00
L . Push ( username , password , host , port ) ;
2015-12-25 12:50:25 -05:00
return 4 ;
}
2016-12-25 12:29:21 -05:00
static int tolua_cUrlParser_UrlDecode ( lua_State * tolua_S )
{
// Check the param types:
cLuaState S ( tolua_S ) ;
if (
// Don't care about the first param
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the parameters:
AString Input ;
S . GetStackValue ( 2 , Input ) ;
// Convert and return:
auto res = URLDecode ( Input ) ;
if ( res . first )
{
S . Push ( res . second ) ;
}
else
{
S . Push ( cLuaState : : Nil ) ;
}
return 1 ;
}
static int tolua_cUrlParser_UrlEncode ( lua_State * tolua_S )
{
// Check the param types:
cLuaState S ( tolua_S ) ;
if (
// Don't care about the first param
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the parameters:
AString Input ;
S . GetStackValue ( 2 , Input ) ;
// Convert and return:
S . Push ( URLEncode ( Input ) ) ;
return 1 ;
}
2016-03-02 04:05:10 -05:00
static int tolua_cWebAdmin_AddWebTab ( lua_State * tolua_S )
{
// Function signatures:
// cWebAdmin:AddWebTab(Title, UrlPath, CallbackFn)
// Check params:
cLuaState LuaState ( tolua_S ) ;
cPluginLua * self = cManualBindings : : GetLuaPlugin ( tolua_S ) ;
if ( self = = nullptr )
{
return 0 ;
}
if (
// Don't care whether the first param is a cWebAdmin instance or class
! LuaState . CheckParamString ( 2 , 3 ) | |
! LuaState . CheckParamFunction ( 4 ) | |
! LuaState . CheckParamEnd ( 5 )
)
{
return 0 ;
}
// Read the params:
AString title , urlPath ;
auto callback = std : : make_shared < cWebTabCallback > ( ) ;
if ( ! LuaState . GetStackValues ( 2 , title , urlPath , callback - > m_Callback ) )
{
LOGWARNING ( " cWebAdmin:AddWebTab(): Cannot read required parameters " ) ;
return 0 ;
}
cRoot : : Get ( ) - > GetWebAdmin ( ) - > AddWebTab ( title , urlPath , self - > GetName ( ) , callback ) ;
return 0 ;
}
static int tolua_cWebAdmin_GetAllWebTabs ( lua_State * tolua_S )
2016-03-02 04:05:10 -05:00
{
2016-03-02 04:05:10 -05:00
// Function signature:
// cWebAdmin:GetAllWebTabs() -> { {"PluginName", "UrlPath", "Title"}, {"PluginName", "UrlPath", "Title"}, ...}
2016-03-02 04:05:10 -05:00
2016-03-02 04:05:10 -05:00
// Don't care about params at all
2016-03-02 04:05:10 -05:00
2016-03-02 04:05:10 -05:00
auto webTabs = cRoot : : Get ( ) - > GetWebAdmin ( ) - > GetAllWebTabs ( ) ;
lua_createtable ( tolua_S , static_cast < int > ( webTabs . size ( ) ) , 0 ) ;
2013-07-28 20:37:59 -04:00
int newTable = lua_gettop ( tolua_S ) ;
int index = 1 ;
2016-03-02 04:05:10 -05:00
cLuaState L ( tolua_S ) ;
for ( const auto & wt : webTabs )
{
lua_createtable ( tolua_S , 0 , 3 ) ;
L . Push ( wt - > m_PluginName ) ;
lua_setfield ( tolua_S , - 2 , " PluginName " ) ;
L . Push ( wt - > m_UrlPath ) ;
lua_setfield ( tolua_S , - 2 , " UrlPath " ) ;
L . Push ( wt - > m_Title ) ;
lua_setfield ( tolua_S , - 2 , " Title " ) ;
2013-07-28 20:37:59 -04:00
lua_rawseti ( tolua_S , newTable , index ) ;
+ + index ;
}
return 1 ;
}
2016-03-02 04:05:10 -05:00
/** Binding for cWebAdmin::GetPage. */
static int tolua_cWebAdmin_GetPage ( lua_State * tolua_S )
{
/*
Function signature :
cWebAdmin : GetPage ( a_HTTPRequest ) - >
{
Content = " " , // Content generated by the plugin
ContentType = " " , // Content type generated by the plugin (default: "text/html")
UrlPath = " " , // URL path of the tab
TabTitle = " " , // Tab's title, as register via cWebAdmin:AddWebTab()
PluginName = " " , // Plugin's API name
PluginFolder = " " , // Plugin's folder name (display name)
}
*/
// Check the param types:
cLuaState S ( tolua_S ) ;
if (
// Don't care about first param, whether it's cWebAdmin instance or class
! S . CheckParamUserType ( 2 , " HTTPRequest " ) | |
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the parameters:
HTTPRequest * request = nullptr ;
if ( ! S . GetStackValue ( 2 , request ) )
{
LOGWARNING ( " cWebAdmin:GetPage(): Cannot read the HTTPRequest parameter. " ) ;
return 0 ;
}
// Generate the page and push the results as a dictionary-table:
auto page = cRoot : : Get ( ) - > GetWebAdmin ( ) - > GetPage ( * request ) ;
lua_createtable ( S , 0 , 6 ) ;
S . Push ( page . Content ) ;
lua_setfield ( S , - 2 , " Content " ) ;
S . Push ( page . ContentType ) ;
lua_setfield ( S , - 2 , " ContentType " ) ;
S . Push ( page . TabUrlPath ) ;
lua_setfield ( S , - 2 , " UrlPath " ) ;
S . Push ( page . TabTitle ) ;
lua_setfield ( S , - 2 , " TabTitle " ) ;
S . Push ( page . PluginName ) ;
lua_setfield ( S , - 2 , " PluginName " ) ;
S . Push ( cPluginManager : : Get ( ) - > GetPluginFolderName ( page . PluginName ) ) ;
lua_setfield ( S , - 2 , " PluginFolder " ) ;
return 1 ;
}
2016-12-25 12:29:21 -05:00
/** Binding for cWebAdmin::GetURLEncodedString. */
2016-03-02 04:05:10 -05:00
static int tolua_cWebAdmin_GetURLEncodedString ( lua_State * tolua_S )
{
2016-12-25 12:29:21 -05:00
// Emit the obsoletion warning:
2016-03-02 04:05:10 -05:00
cLuaState S ( tolua_S ) ;
2016-12-25 12:29:21 -05:00
LOGWARNING ( " cWebAdmin:GetURLEncodedString() is obsolete, use cUrlParser:UrlEncode() instead. " ) ;
S . LogStackTrace ( ) ;
2016-03-02 04:05:10 -05:00
2016-12-25 12:29:21 -05:00
return tolua_cUrlParser_UrlEncode ( tolua_S ) ;
2013-07-28 20:37:59 -04:00
}
2014-01-09 08:25:37 -05:00
static int tolua_cClientHandle_SendPluginMessage ( lua_State * L )
{
cLuaState S ( L ) ;
if (
2017-08-25 08:43:18 -04:00
! S . CheckParamSelf ( " cClientHandle " ) | |
2014-01-09 08:25:37 -05:00
! S . CheckParamString ( 2 , 3 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cClientHandle * Client = static_cast < cClientHandle * > ( tolua_tousertype ( L , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2017-08-27 17:10:20 -04:00
static int tolua_cClientHandle_GetForgeMods ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamSelf ( " cClientHandle " ) | |
! S . CheckParamEnd ( 2 )
)
{
return 0 ;
}
cClientHandle * Client ;
S . GetStackValue ( 1 , Client ) ;
S . Push ( Client - > GetForgeMods ( ) ) ;
return 1 ;
}
2017-08-25 08:43:18 -04:00
static int tolua_cClientHandle_GetUUID ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamSelf ( " cClientHandle " ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
// Get the params:
cClientHandle * Self ;
L . GetStackValue ( 1 , Self ) ;
// Return the UUID as a string:
L . Push ( Self - > GetUUID ( ) . ToShortString ( ) ) ;
return 1 ;
}
static int tolua_cClientHandle_GenerateOfflineUUID ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamStaticSelf ( " cClientHandle " ) | |
! L . CheckParamString ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the params:
AString Username ;
L . GetStackValue ( 2 , Username ) ;
// Return the UUID as a string:
L . Push ( cClientHandle : : GenerateOfflineUUID ( Username ) . ToShortString ( ) ) ;
return 1 ;
}
static int tolua_cClientHandle_IsUUIDOnline ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamStaticSelf ( " cClientHandle " ) | |
! L . CheckParamUUID ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
// Get the params:
cUUID UUID ;
L . GetStackValue ( 2 , UUID ) ;
// Return the result:
L . Push ( cClientHandle : : IsUUIDOnline ( UUID ) ) ;
return 1 ;
}
2018-07-26 17:24:36 -04:00
2017-08-25 08:43:18 -04:00
static int tolua_cMobHeadEntity_SetOwner ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamSelf ( " cMobHeadEntity " ) | |
! L . CheckParamUUID ( 2 ) | |
! L . CheckParamString ( 3 , 5 ) | |
! L . CheckParamEnd ( 6 )
)
{
return 0 ;
}
// Get the params:
cMobHeadEntity * Self ;
cUUID OwnerUUID ;
AString OwnerName , OwnerTexture , OwnerTextureSignature ;
L . GetStackValues ( 1 , Self , OwnerUUID , OwnerName , OwnerTexture , OwnerTextureSignature ) ;
// Set the owner:
Self - > SetOwner ( OwnerUUID , OwnerName , OwnerTexture , OwnerTextureSignature ) ;
return 0 ;
}
static int tolua_cMobHeadEntity_GetOwnerUUID ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamSelf ( " cMobHeadEntity " ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
// Get the params:
cMobHeadEntity * Self ;
L . GetStackValue ( 1 , Self ) ;
// Return the UUID as a string:
cUUID Owner = Self - > GetOwnerUUID ( ) ;
L . Push ( Owner . IsNil ( ) ? AString { } : Owner . ToShortString ( ) ) ;
return 1 ;
}
2014-08-03 15:32:20 -04:00
static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping ( lua_State * L )
{
cLuaState S ( L ) ;
if (
2017-08-25 08:43:18 -04:00
! S . CheckParamStaticSelf ( " cMojangAPI " ) | |
2014-08-03 15:32:20 -04:00
! S . CheckParamString ( 2 ) | |
2017-08-25 08:43:18 -04:00
! S . CheckParamUUID ( 3 ) | |
2014-08-03 15:32:20 -04:00
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2014-08-03 15:32:20 -04:00
// Retrieve the parameters:
2017-08-25 08:43:18 -04:00
AString PlayerName ;
cUUID UUID ;
S . GetStackValues ( 2 , PlayerName , UUID ) ;
2016-02-05 16:45:45 -05:00
2014-08-03 15:32:20 -04:00
// Store in the cache:
cRoot : : Get ( ) - > GetMojangAPI ( ) . AddPlayerNameToUUIDMapping ( PlayerName , UUID ) ;
return 0 ;
}
static int tolua_cMojangAPI_GetPlayerNameFromUUID ( lua_State * L )
{
cLuaState S ( L ) ;
if (
2017-08-25 08:43:18 -04:00
! S . CheckParamStaticSelf ( " cMojangAPI " ) | |
! S . CheckParamUUID ( 2 ) | |
2014-08-03 15:32:20 -04:00
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2017-08-25 08:43:18 -04:00
cUUID UUID ;
2014-08-03 15:32:20 -04:00
S . GetStackValue ( 2 , UUID ) ;
2016-02-05 16:45:45 -05:00
2014-08-03 15:32:20 -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 ) ;
}
// 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 (
2017-08-25 08:43:18 -04:00
! S . CheckParamStaticSelf ( " cMojangAPI " ) | |
2014-08-03 15:32:20 -04:00
! S . CheckParamString ( 2 ) | |
! S . CheckParamEnd ( 4 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2014-08-03 15:32:20 -04:00
AString PlayerName ;
S . GetStackValue ( 2 , PlayerName ) ;
2016-02-05 16:45:45 -05:00
2014-08-03 15:32:20 -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 ) ;
}
2017-08-25 08:43:18 -04:00
// Return the UUID as a string:
cUUID UUID = cRoot : : Get ( ) - > GetMojangAPI ( ) . GetUUIDFromPlayerName ( PlayerName , ShouldUseCacheOnly ) ;
S . Push ( UUID . IsNil ( ) ? AString { } : UUID . ToShortString ( ) ) ;
2014-08-03 15:32:20 -04:00
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 (
2017-08-25 08:43:18 -04:00
! S . CheckParamStaticSelf ( " 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 ;
}
2016-02-05 16:45:45 -05:00
2014-07-28 11:09:39 -04:00
// Convert the input table into AStringVector:
AStringVector PlayerNames ;
int NumNames = luaL_getn ( L , 2 ) ;
2015-05-19 10:25:18 -04:00
PlayerNames . reserve ( static_cast < size_t > ( NumNames ) ) ;
2014-07-28 11:09:39 -04:00
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 ) ;
}
2016-02-05 16:45:45 -05:00
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 ) ;
2016-02-05 16:45:45 -05:00
2014-07-28 11:09:39 -04:00
// Get the UUIDs:
2017-08-25 08:43:18 -04:00
auto 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 ;
}
2016-02-05 16:45:45 -05:00
2017-08-25 08:43:18 -04:00
// Convert to output table, PlayerName -> UUID string:
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
{
2017-08-25 08:43:18 -04:00
if ( UUIDs [ i ] . IsNil ( ) )
2014-07-28 11:09:39 -04:00
{
// No UUID was provided for PlayerName[i], skip it in the resulting table
continue ;
}
2017-08-25 08:43:18 -04:00
S . Push ( UUIDs [ i ] . ToShortString ( ) ) ;
2014-07-28 11:09:39 -04:00
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 )
{
2017-08-25 08:43:18 -04:00
// Function now non-existant but kept for API compatibility
2014-08-21 09:19:30 -04:00
// Check params:
cLuaState S ( L ) ;
if (
2017-08-25 08:43:18 -04:00
! S . CheckParamStaticSelf ( " cMojangAPI " ) | |
! S . CheckParamUUID ( 2 ) | |
2014-08-21 09:19:30 -04:00
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2014-08-21 09:19:30 -04:00
// Get the params:
2017-08-25 08:43:18 -04:00
cUUID UUID ;
2014-08-21 09:19:30 -04:00
S . GetStackValue ( 2 , UUID ) ;
// Push the result:
2017-08-25 08:43:18 -04:00
S . Push ( UUID . ToLongString ( ) ) ;
2014-08-21 09:19:30 -04:00
return 1 ;
}
static int tolua_cMojangAPI_MakeUUIDShort ( lua_State * L )
{
2017-08-25 08:43:18 -04:00
// Function now non-existant but kept for API compatibility
2014-08-21 09:19:30 -04:00
// Check params:
cLuaState S ( L ) ;
if (
! S . CheckParamUserTable ( 1 , " cMojangAPI " ) | |
2017-08-25 08:43:18 -04:00
! S . CheckParamUUID ( 2 ) | |
2014-08-21 09:19:30 -04:00
! S . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2016-02-05 16:45:45 -05:00
2014-08-21 09:19:30 -04:00
// Get the params:
2017-08-25 08:43:18 -04:00
cUUID UUID ;
2014-08-21 09:19:30 -04:00
S . GetStackValue ( 2 , UUID ) ;
// Push the result:
2017-08-25 08:43:18 -04:00
S . Push ( UUID . ToShortString ( ) ) ;
2014-08-21 09:19:30 -04:00
return 1 ;
}
2017-08-18 06:29:54 -04:00
static int tolua_get_cItem_m_LoreTable ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " const cItem " ) )
{
return 0 ;
}
// Get the params:
const cItem * Self = nullptr ;
L . GetStackValue ( 1 , Self ) ;
// Push the result:
L . Push ( Self - > m_LoreTable ) ;
return 1 ;
}
static int tolua_set_cItem_m_LoreTable ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamSelf ( " cItem " ) | |
! L . CheckParamTable ( 2 )
)
{
return 0 ;
}
// Get the params:
cItem * Self = nullptr ;
L . GetStackValue ( 1 , Self ) ;
// Set the value:
Self - > m_LoreTable . clear ( ) ;
if ( ! L . GetStackValue ( 2 , Self - > m_LoreTable ) )
{
return L . ApiParamError ( " cItem.m_LoreTable: Could not read value as an array of strings " ) ;
}
return 0 ;
}
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 ;
}
{
2018-05-02 03:50:36 -04:00
const cItemGrid * self = static_cast < const cItemGrid * > ( tolua_tousertype ( L , 1 , nullptr ) ) ;
2015-07-29 11:04:03 -04:00
int SlotNum = static_cast < 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 ) ;
2015-07-29 11:04:03 -04:00
tolua_pushnumber ( L , static_cast < lua_Number > ( X ) ) ;
tolua_pushnumber ( L , static_cast < lua_Number > ( Y ) ) ;
2013-04-10 17:25:26 -04:00
return 2 ;
2013-04-10 15:52:03 -04:00
}
2016-02-05 16:45:45 -05:00
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 ;
}
2015-07-31 10:49:10 -04:00
/** Provides interface between a Lua table of callbacks and the cBlockTracer::cCallbacks */
2013-08-07 08:34:00 -04:00
class cLuaBlockTracerCallbacks :
public cBlockTracer : : cCallbacks
{
public :
2016-07-06 14:52:04 -04:00
cLuaBlockTracerCallbacks ( cLuaState : : cTableRefPtr & & a_Callbacks ) :
m_Callbacks ( std : : move ( a_Callbacks ) )
2013-08-07 08:34:00 -04:00
{
}
2016-02-05 16:45:45 -05:00
2017-05-11 08:34:36 -04:00
virtual bool OnNextBlock ( int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta , eBlockFace a_EntryFace ) override
2013-08-07 08:34:00 -04:00
{
2014-01-11 16:51:10 -05:00
bool res = false ;
2016-07-06 14:52:04 -04:00
if ( ! m_Callbacks - > CallTableFn (
" OnNextBlock " ,
2014-01-11 16:51:10 -05:00
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 ;
}
2016-02-05 16:45:45 -05:00
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 ;
2016-07-06 14:52:04 -04:00
if ( ! m_Callbacks - > CallTableFn (
" OnNextBlockNoData " ,
2014-01-11 16:51:10 -05:00
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 ;
}
2016-02-05 16:45:45 -05:00
2013-08-07 08:34:00 -04:00
virtual bool OnOutOfWorld ( double a_BlockX , double a_BlockY , double a_BlockZ ) override
{
2014-01-11 16:51:10 -05:00
bool res = false ;
2016-07-06 14:52:04 -04:00
if ( ! m_Callbacks - > CallTableFn (
" OnOutOfWorld " ,
2014-01-11 16:51:10 -05:00
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 ;
}
2016-02-05 16:45:45 -05:00
2013-08-07 08:34:00 -04:00
virtual bool OnIntoWorld ( double a_BlockX , double a_BlockY , double a_BlockZ ) override
{
2014-01-11 16:51:10 -05:00
bool res = false ;
2016-07-06 14:52:04 -04:00
if ( ! m_Callbacks - > CallTableFn (
" OnIntoWorld " ,
2014-01-11 16:51:10 -05:00
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 ;
}
2016-02-05 16:45:45 -05:00
2013-08-07 08:34:00 -04:00
virtual void OnNoMoreHits ( void ) override
{
2016-07-06 14:52:04 -04:00
m_Callbacks - > CallTableFn ( " OnNoMoreHits " ) ;
2013-08-07 08:34:00 -04:00
}
2016-02-05 16:45:45 -05:00
2013-08-07 08:34:00 -04:00
virtual void OnNoChunk ( void ) override
{
2016-07-06 14:52:04 -04:00
m_Callbacks - > CallTableFn ( " OnNoChunk " ) ;
2013-08-07 08:34:00 -04:00
}
protected :
2016-07-06 14:52:04 -04:00
cLuaState : : cTableRefPtr m_Callbacks ;
2013-08-07 08:34:00 -04:00
} ;
2017-05-11 08:34:36 -04:00
static int tolua_cLineBlockTracer_FirstSolidHitTrace ( lua_State * tolua_S )
{
/* Supported function signatures:
cLineBlockTracer : FirstSolidHitTrace ( World , StartX , StartY , StartZ , EndX , EndY , EndZ ) - > bool , [ Vector3d , Vector3i , eBlockFace ] // Canonical
cLineBlockTracer : FirstSolidHitTrace ( World , Start , End ) - > bool , [ Vector3d , Vector3i , eBlockFace ] // Canonical
cLineBlockTracer . FirstSolidHitTrace ( World , StartX , StartY , StartZ , EndX , EndY , EndZ ) - > bool , [ Vector3d , Vector3i , eBlockFace ]
cLineBlockTracer . FirstSolidHitTrace ( World , Start , End ) - > bool , [ Vector3d , Vector3i , eBlockFace ]
*/
// 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:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( idx , " cWorld " )
)
{
return 0 ;
}
if ( L . IsParamNumber ( idx + 1 ) )
{
// This is the number variant of the call:
if (
! L . CheckParamNumber ( idx + 1 , idx + 6 ) | |
! L . CheckParamEnd ( idx + 7 )
)
{
return 0 ;
}
// Get the params:
cWorld * world ;
double startX , startY , startZ ;
double endX , endY , endZ ;
if ( ! L . GetStackValues ( idx , world , startX , startY , startZ , endX , endY , endZ ) )
{
LOGWARNING ( " cLineBlockTracer:FirstSolidHitTrace(): Cannot read parameters, aborting the trace. " ) ;
L . LogStackTrace ( ) ;
L . LogStackValues ( " Values on the stack " ) ;
return 0 ;
}
Vector3d hitCoords ;
Vector3i hitBlockCoords ;
eBlockFace hitBlockFace ;
auto isHit = cLineBlockTracer : : FirstSolidHitTrace ( * world , Vector3d ( startX , startY , startZ ) , Vector3d ( endX , endY , endZ ) , hitCoords , hitBlockCoords , hitBlockFace ) ;
L . Push ( isHit ) ;
if ( ! isHit )
{
return 1 ;
}
L . Push ( hitCoords ) ;
L . Push ( hitBlockCoords ) ;
L . Push ( hitBlockFace ) ;
return 4 ;
}
if ( L . IsParamUserType ( idx + 1 , " Vector3<double> " ) )
{
// This is the Vector3d-based variant of the call:
if (
! L . CheckParamUserType ( idx + 1 , " Vector3<double> " , idx + 2 ) | |
! L . CheckParamEnd ( idx + 3 )
)
{
return 0 ;
}
// Get the params:
cWorld * world ;
Vector3d * start ;
Vector3d * end ;
if ( ! L . GetStackValues ( idx , world , start , end ) )
{
LOGWARNING ( " cLineBlockTracer:FirstSolidHitTrace(): Cannot read parameters, aborting the trace. " ) ;
L . LogStackTrace ( ) ;
L . LogStackValues ( " Values on the stack " ) ;
return 0 ;
}
Vector3d hitCoords ;
Vector3i hitBlockCoords ;
eBlockFace hitBlockFace ;
2017-08-28 07:48:02 -04:00
auto isHit = cLineBlockTracer : : FirstSolidHitTrace ( * world , * start , * end , hitCoords , hitBlockCoords , hitBlockFace ) ;
2017-05-11 08:34:36 -04:00
L . Push ( isHit ) ;
if ( ! isHit )
{
return 1 ;
}
L . Push ( hitCoords ) ;
L . Push ( hitBlockCoords ) ;
L . Push ( hitBlockFace ) ;
return 4 ;
}
tolua_error ( L , " cLineBlockTracer:FirstSolidHitTrace(): Invalid parameters, expected either a set of coords, or two Vector3d's " , nullptr ) ;
return 0 ;
}
static int tolua_cLineBlockTracer_LineOfSightTrace ( lua_State * tolua_S )
{
/* Supported function signatures:
cLineBlockTracer : LineOfSightTrace ( World , StartX , StartY , StartZ , EndX , EndY , EndZ , Sight ) - > bool // Canonical
cLineBlockTracer : LineOfSightTrace ( World , Start , End , Sight ) - > bool // Canonical
cLineBlockTracer . LineOfSightTrace ( World , StartX , StartY , StartZ , EndX , EndY , EndZ , Sight ) - > bool
cLineBlockTracer . LineOfSightTrace ( World , Start , End , Sight ) - > bool
*/
// 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:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( idx , " cWorld " )
)
{
return 0 ;
}
if ( L . IsParamNumber ( idx + 1 ) )
{
// This is the number variant of the call:
if (
! L . CheckParamNumber ( idx + 1 , idx + 6 ) | |
// Optional param lineOfSight is not checked
! L . CheckParamEnd ( idx + 8 )
)
{
return 0 ;
}
// Get the params:
cWorld * world ;
double startX , startY , startZ ;
double endX , endY , endZ ;
if ( ! L . GetStackValues ( idx , world , startX , startY , startZ , endX , endY , endZ ) )
{
LOGWARNING ( " cLineBlockTracer:LineOfSightTrace(): Cannot read parameters, aborting the trace. " ) ;
L . LogStackTrace ( ) ;
L . LogStackValues ( " Values on the stack " ) ;
return 0 ;
}
int lineOfSight = cLineBlockTracer : : losAir | cLineBlockTracer : : losWater ;
L . GetStackValue ( idx + 7 , lineOfSight ) ;
L . Push ( cLineBlockTracer : : LineOfSightTrace ( * world , Vector3d ( startX , startY , startZ ) , Vector3d ( endX , endY , endZ ) , lineOfSight ) ) ;
return 1 ;
}
if ( L . IsParamUserType ( idx + 1 , " Vector3<double> " ) )
{
// This is the Vector3d-based variant of the call:
if (
! L . CheckParamUserType ( idx + 1 , " Vector3<double> " , idx + 2 ) | |
// Optional param lineOfSight is not checked
! L . CheckParamEnd ( idx + 4 )
)
{
return 0 ;
}
// Get the params:
cWorld * world ;
Vector3d * start ;
Vector3d * end ;
if ( ! L . GetStackValues ( idx , world , start , end ) )
{
LOGWARNING ( " cLineBlockTracer:LineOfSightTrace(): Cannot read parameters, aborting the trace. " ) ;
L . LogStackTrace ( ) ;
L . LogStackValues ( " Values on the stack " ) ;
return 0 ;
}
int lineOfSight = cLineBlockTracer : : losAirWater ;
L . GetStackValue ( idx + 7 , lineOfSight ) ;
2017-08-28 07:48:02 -04:00
L . Push ( cLineBlockTracer : : LineOfSightTrace ( * world , * start , * end , lineOfSight ) ) ;
2017-05-11 08:34:36 -04:00
return 1 ;
}
tolua_error ( L , " cLineBlockTracer:LineOfSightTrace(): Invalid parameters, expected either a set of coords, or two Vector3d's " , nullptr ) ;
return 0 ;
}
2013-08-07 08:34:00 -04:00
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 )
*/
2016-02-05 16:45:45 -05:00
2014-01-31 04:20:06 -05:00
// 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 ;
}
2016-02-05 16:45:45 -05:00
2014-01-31 04:20:06 -05:00
// 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 ;
}
2016-07-06 14:52:04 -04:00
// Get the params:
cWorld * world ;
double startX , startY , startZ ;
double endX , endY , endZ ;
cLuaState : : cTableRefPtr callbacks ;
if ( ! L . GetStackValues ( idx , world , callbacks , startX , startY , startZ , endX , endY , endZ ) )
{
LOGWARNING ( " cLineBlockTracer:Trace(): Cannot read parameters (starting at idx %d), aborting the trace. " , idx ) ;
L . LogStackTrace ( ) ;
L . LogStackValues ( " Values on the stack " ) ;
return 0 ;
}
2014-01-31 04:20:06 -05:00
// Trace:
2016-07-06 14:52:04 -04:00
cLuaBlockTracerCallbacks tracerCallbacks ( std : : move ( callbacks ) ) ;
bool res = cLineBlockTracer : : Trace ( * world , tracerCallbacks , startX , startY , startZ , endX , endY , endZ ) ;
2013-08-07 08:34:00 -04:00
tolua_pushboolean ( L , res ? 1 : 0 ) ;
return 1 ;
}
2016-06-10 15:30:07 -04:00
static int tolua_cLuaWindow_new ( lua_State * tolua_S )
{
// Function signature:
// cLuaWindow:new(type, slotsX, slotsY, title)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cLuaWindow " ) | |
! L . CheckParamNumber ( 2 , 4 ) | |
! L . CheckParamString ( 5 ) | |
! L . CheckParamEnd ( 6 )
)
{
return 0 ;
}
// Read params:
int windowType , slotsX , slotsY ;
AString title ;
if ( ! L . GetStackValues ( 2 , windowType , slotsX , slotsY , title ) )
{
LOGWARNING ( " %s: Cannot read Lua parameters " , __FUNCTION__ ) ;
L . LogStackValues ( ) ;
L . LogStackTrace ( ) ;
}
// Create the window and return it:
L . Push ( new cLuaWindow ( L , static_cast < cLuaWindow : : WindowType > ( windowType ) , slotsX , slotsY , title ) ) ;
return 1 ;
}
static int tolua_cLuaWindow_new_local ( lua_State * tolua_S )
{
// Function signature:
// cLuaWindow:new(type, slotsX, slotsY, title)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cLuaWindow " ) | |
! L . CheckParamNumber ( 2 , 4 ) | |
! L . CheckParamString ( 5 ) | |
! L . CheckParamEnd ( 6 )
)
{
return 0 ;
}
// Read params:
int windowType , slotsX , slotsY ;
AString title ;
if ( ! L . GetStackValues ( 2 , windowType , slotsX , slotsY , title ) )
{
LOGWARNING ( " %s: Cannot read Lua parameters " , __FUNCTION__ ) ;
L . LogStackValues ( ) ;
L . LogStackTrace ( ) ;
}
// Create the window, register it for GC and return it:
L . Push ( new cLuaWindow ( L , static_cast < cLuaWindow : : WindowType > ( windowType ) , slotsX , slotsY , title ) ) ;
tolua_register_gc ( tolua_S , lua_gettop ( tolua_S ) ) ;
return 1 ;
}
2017-08-25 08:43:18 -04:00
static int tolua_cRoot_DoWithPlayerByUUID ( lua_State * tolua_S )
{
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamSelf ( " cRoot " ) | |
! L . CheckParamUUID ( 2 ) | |
! L . CheckParamFunction ( 3 ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Get parameters:
cRoot * Self ;
cUUID PlayerUUID ;
2017-09-11 17:20:49 -04:00
cLuaState : : cRef FnRef ;
L . GetStackValues ( 1 , Self , PlayerUUID , FnRef ) ;
2017-08-25 08:43:18 -04:00
if ( PlayerUUID . IsNil ( ) )
{
return L . ApiParamError ( " Expected a non-nil UUID for parameter #1 " ) ;
}
2017-09-11 17:20:49 -04:00
if ( ! FnRef . IsValid ( ) )
2017-08-25 08:43:18 -04:00
{
return L . ApiParamError ( " Expected a valid callback function for parameter #2 " ) ;
}
// Call the function:
2017-09-11 17:20:49 -04:00
bool res = Self - > DoWithPlayerByUUID ( PlayerUUID , [ & ] ( cPlayer & a_Player )
{
bool ret = false ;
L . Call ( FnRef , & a_Player , cLuaState : : Return , ret ) ;
return ret ;
}
) ;
2017-08-25 08:43:18 -04:00
// Push the result as the return value:
L . Push ( res ) ;
return 1 ;
}
2015-06-05 04:34:13 -04:00
static int tolua_cRoot_GetBuildCommitID ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
L . Push ( BUILD_COMMIT_ID ) ;
return 1 ;
}
static int tolua_cRoot_GetBuildDateTime ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
L . Push ( BUILD_DATETIME ) ;
return 1 ;
}
static int tolua_cRoot_GetBuildID ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
L . Push ( BUILD_ID ) ;
return 1 ;
}
static int tolua_cRoot_GetBuildSeriesName ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
L . Push ( BUILD_SERIES_NAME ) ;
return 1 ;
}
2015-09-24 04:48:33 -04:00
static int tolua_cRoot_GetBrewingRecipe ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserTable ( 1 , " cRoot " ) | |
! L . CheckParamUserType ( 2 , " const cItem " ) | |
! L . CheckParamUserType ( 3 , " const cItem " ) | |
! L . CheckParamEnd ( 4 )
)
{
return 0 ;
}
// Check the bottle param:
cItem * Bottle = nullptr ;
L . GetStackValue ( 2 , Bottle ) ;
if ( Bottle = = nullptr )
{
LOGWARNING ( " cRoot:GetBrewingRecipe: the Bottle parameter is nil or missing. " ) ;
return 0 ;
}
cItem * Ingredient = nullptr ;
L . GetStackValue ( 3 , Ingredient ) ;
if ( Ingredient = = nullptr )
{
LOGWARNING ( " cRoot:GetBrewingRecipe: the Ingredient parameter is nil or missing. " ) ;
return 0 ;
}
// Get the recipe for the input
cBrewingRecipes * BR = cRoot : : Get ( ) - > GetBrewingRecipes ( ) ;
const cBrewingRecipes : : cRecipe * Recipe = BR - > GetRecipeFrom ( * Bottle , * Ingredient ) ;
if ( Recipe = = nullptr )
{
// There is no such brewing recipe for this bottle and ingredient, return no value
return 0 ;
}
// Push the output item
2017-05-28 14:08:23 -04:00
cItem & OutItem = const_cast < cItem & > ( Recipe - > Output ) ;
L . Push ( & OutItem ) ;
2015-09-24 04:48:33 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2013-11-22 06:26:06 -05:00
// Check the input param:
2015-06-05 04:34:13 -04:00
cItem * Input = nullptr ;
L . GetStackValue ( 2 , Input ) ;
2014-10-20 16:55:07 -04:00
if ( Input = = nullptr )
2013-11-22 06:26:06 -05:00
{
LOGWARNING ( " cRoot:GetFurnaceRecipe: the Input parameter is nil or missing. " ) ;
return 0 ;
}
2016-02-05 16:45:45 -05:00
2013-11-22 06:26:06 -05:00
// 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 ;
}
2016-02-05 16:45:45 -05:00
2013-11-22 06:26:06 -05:00
// Push the output, number of ticks and input as the three return values:
2016-08-21 05:03:10 -04:00
L . Push ( Recipe - > Out , Recipe - > CookTime , Recipe - > In ) ;
2013-11-22 06:26:06 -05:00
return 3 ;
}
2017-08-27 17:10:20 -04:00
static int tolua_cServer_RegisterForgeMod ( lua_State * a_LuaState )
{
cLuaState L ( a_LuaState ) ;
if (
! L . CheckParamSelf ( " cServer " ) | |
! L . CheckParamString ( 2 , 3 ) | |
! L . CheckParamNumber ( 4 ) | |
! L . CheckParamEnd ( 5 )
)
{
return 0 ;
}
cServer * Server ;
AString Name , Version ;
UInt32 Protocol ;
L . GetStackValues ( 1 , Server , Name , Version , Protocol ) ;
if ( ! Server - > RegisterForgeMod ( Name , Version , Protocol ) )
{
tolua_error ( L , " duplicate Forge mod name registration " , nullptr ) ;
return 0 ;
}
return 0 ;
}
2016-05-29 13:12:18 -04:00
static int tolua_cScoreboard_GetTeamNames ( lua_State * L )
{
cLuaState S ( L ) ;
if (
! S . CheckParamUserType ( 1 , " cScoreboard " ) | |
! S . CheckParamEnd ( 2 )
)
{
return 0 ;
}
// Get the groups:
2018-05-02 03:50:36 -04:00
cScoreboard * Scoreboard = static_cast < cScoreboard * > ( tolua_tousertype ( L , 1 , nullptr ) ) ;
2016-05-29 13:12:18 -04:00
AStringVector Teams = Scoreboard - > GetTeamNames ( ) ;
// Push the results:
S . Push ( Teams ) ;
return 1 ;
}
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
2016-02-05 16:45:45 -05:00
2013-10-23 06:09:11 -04:00
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cHopperEntity " ) | |
! L . CheckParamNumber ( 2 ) | |
! L . CheckParamEnd ( 3 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cHopperEntity * self = static_cast < cHopperEntity * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2015-07-29 11:04:03 -04:00
NIBBLETYPE a_BlockMeta = static_cast < NIBBLETYPE > ( tolua_tonumber ( tolua_S , 2 , 0 ) ) ;
2019-09-29 08:59:24 -04:00
auto res = self - > GetOutputBlockPos ( a_BlockMeta ) ;
tolua_pushboolean ( tolua_S , res . first ) ;
if ( res . first )
{
tolua_pushnumber ( tolua_S , static_cast < lua_Number > ( res . second . x ) ) ;
tolua_pushnumber ( tolua_S , static_cast < lua_Number > ( res . second . y ) ) ;
tolua_pushnumber ( tolua_S , static_cast < lua_Number > ( res . second . z ) ) ;
2013-10-23 06:09:11 -04:00
return 4 ;
}
return 1 ;
}
2016-06-05 12:23:16 -04:00
static int tolua_cBoundingBox_CalcLineIntersection ( lua_State * a_LuaState )
{
/* Function signatures:
bbox : CalcLineIntersection ( pt1 , pt2 ) - > bool , [ number , blockface ]
cBoundingBox : CalcLineIntersection ( min , max , pt1 , pt2 ) - > bool , [ number , blockface ]
*/
cLuaState L ( a_LuaState ) ;
const Vector3d * min ;
const Vector3d * max ;
const Vector3d * pt1 ;
const Vector3d * pt2 ;
double lineCoeff ;
eBlockFace blockFace ;
bool res ;
if ( L . GetStackValues ( 2 , min , max , pt1 , pt2 ) ) // Try the static signature first
{
2017-08-28 07:48:02 -04:00
res = cBoundingBox : : CalcLineIntersection ( * min , * max , * pt1 , * pt2 , lineCoeff , blockFace ) ;
2016-06-05 12:23:16 -04:00
}
else
{
const cBoundingBox * bbox ;
if ( ! L . GetStackValues ( 1 , bbox , pt1 , pt2 ) ) // Try the regular signature
{
2016-06-10 15:30:07 -04:00
L . LogStackValues ( ) ;
2016-06-05 12:23:16 -04:00
tolua_error ( a_LuaState , " Invalid function params. Expected either bbox:CalcLineIntersection(pt1, pt2) or cBoundingBox:CalcLineIntersection(min, max, pt1, pt2). " , nullptr ) ;
return 0 ;
}
2017-08-28 07:48:02 -04:00
res = bbox - > CalcLineIntersection ( * pt1 , * pt2 , lineCoeff , blockFace ) ;
2016-06-05 12:23:16 -04:00
}
L . Push ( res ) ;
if ( res )
{
2016-08-21 05:03:10 -04:00
L . Push ( lineCoeff , blockFace ) ;
2016-06-05 12:23:16 -04:00
return 3 ;
}
return 1 ;
}
static int tolua_cBoundingBox_Intersect ( lua_State * a_LuaState )
{
/* Function signature:
bbox : Intersect ( a_OtherBbox ) - > bool , cBoundingBox
*/
cLuaState L ( a_LuaState ) ;
const cBoundingBox * self ;
const cBoundingBox * other ;
if ( ! L . GetStackValues ( 1 , self , other ) )
{
2016-06-10 15:30:07 -04:00
L . LogStackValues ( ) ;
2016-06-05 12:23:16 -04:00
tolua_error ( a_LuaState , " Invalid function params. Expected bbox:Intersect(otherBbox). " , nullptr ) ;
return 0 ;
}
auto intersection = new cBoundingBox ( * self ) ;
auto res = self - > Intersect ( * other , * intersection ) ;
L . Push ( res ) ;
if ( ! res )
{
delete intersection ;
return 1 ;
}
L . Push ( intersection ) ;
tolua_register_gc ( L , lua_gettop ( L ) ) ; // Make Lua own the "intersection" object
return 2 ;
}
2016-06-30 13:35:00 -04:00
static int tolua_cChunkDesc_GetBlockTypeMeta ( lua_State * a_LuaState )
{
/* Function signature:
ChunkDesc : GetBlockTypeMeta ( RelX , RelY , RelZ ) - > BlockType , BlockMeta
*/
cLuaState L ( a_LuaState ) ;
const cChunkDesc * self ;
int relX , relY , relZ ;
if ( ! L . GetStackValues ( 1 , self , relX , relY , relZ ) )
{
L . LogStackValues ( ) ;
tolua_error ( a_LuaState , " Invalid function params. Expected chunkDesc:GetBlockTypeMeta(relX, relY, relZ) " , nullptr ) ;
return 0 ;
}
BLOCKTYPE blockType ;
NIBBLETYPE blockMeta ;
self - > GetBlockTypeMeta ( relX , relY , relZ , blockType , blockMeta ) ;
2016-08-21 05:03:10 -04:00
L . Push ( blockType , blockMeta ) ;
2016-06-30 13:35:00 -04:00
return 2 ;
}
2017-07-12 06:30:43 -04:00
static int tolua_cColor_GetColor ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
cColor * self ;
if ( ! L . CheckParamSelf ( " cColor " ) | | ! L . GetStackValue ( 1 , self ) )
{
return 0 ;
}
L . Push ( self - > GetRed ( ) , self - > GetGreen ( ) , self - > GetBlue ( ) ) ;
return 3 ;
}
2016-09-25 06:42:05 -04:00
static int tolua_cCompositeChat_new ( lua_State * a_LuaState )
{
/* Function signatures:
cCompositeChat ( )
cCompositeChat ( a_ParseText , a_MessageType )
*/
// Check if it's the no-param version:
cLuaState L ( a_LuaState ) ;
if ( lua_isnone ( a_LuaState , 2 ) )
{
auto * res = static_cast < cCompositeChat * > ( Mtolua_new ( cCompositeChat ( ) ) ) ;
L . Push ( res ) ;
return 1 ;
}
// Check the second signature:
AString parseText ;
if ( ! L . GetStackValue ( 2 , parseText ) )
{
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid ParseText parameter (1) in cCompositeChat constructor. " , & err ) ;
return 0 ;
}
int messageTypeInt = mtCustom ;
if ( ! lua_isnone ( a_LuaState , 3 ) )
{
if ( ! L . GetStackValue ( 3 , messageTypeInt ) )
{
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid type of the MessageType parameter (2) in cCompositeChat constructor. " , & err ) ;
return 0 ;
}
if ( ( messageTypeInt < 0 ) | | ( messageTypeInt > = mtMaxPlusOne ) )
{
tolua_Error err ;
tolua_error ( a_LuaState , " Invalid MessageType parameter (2) value in cCompositeChat constructor. " , & err ) ;
return 0 ;
}
}
L . Push ( static_cast < cCompositeChat * > ( Mtolua_new ( cCompositeChat ( parseText , static_cast < eMessageType > ( messageTypeInt ) ) ) ) ) ;
return 1 ;
}
static int tolua_cCompositeChat_new_local ( lua_State * a_LuaState )
{
// Use the same constructor as global, just register it for GC:
auto res = tolua_cCompositeChat_new ( a_LuaState ) ;
if ( res = = 1 )
{
tolua_register_gc ( a_LuaState , lua_gettop ( a_LuaState ) ) ;
}
return res ;
}
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)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Add the part:
2016-09-25 06:42:05 -04:00
AString Text , Command , Style = " u@a " ;
2014-03-04 16:17:23 -05:00
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Command ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddRunCommandPart ( Text , Command , Style ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// 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)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Add the part:
AString Text , Command , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Command ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddSuggestCommandPart ( Text , Command , Style ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// 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)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Add the part:
AString Text , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Style ) ;
self - > AddTextPart ( Text , Style ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// 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)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 , 3 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Add the part:
AString Text , Url , Style ;
L . GetStackValue ( 2 , Text ) ;
L . GetStackValue ( 3 , Url ) ;
L . GetStackValue ( 4 , Style ) ;
self - > AddUrlPart ( Text , Url , Style ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
2016-09-25 06:42:05 -04:00
static int tolua_cCompositeChat_Clear ( lua_State * tolua_S )
{
// function cCompositeChat:Clear()
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamEnd ( 2 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2016-09-25 06:42:05 -04:00
if ( self = = nullptr )
{
tolua_error ( tolua_S , " invalid 'self' in function 'cCompositeChat:ParseText' " , nullptr ) ;
return 0 ;
}
// Clear all the parts:
self - > Clear ( ) ;
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
2014-03-04 16:17:23 -05:00
static int tolua_cCompositeChat_ParseText ( lua_State * tolua_S )
{
// function cCompositeChat:ParseText(TextMessage)
// Exported manually to support call-chaining (return *this)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamString ( 2 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Parse the text:
AString Text ;
L . GetStackValue ( 2 , Text ) ;
self - > ParseText ( Text ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// 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)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if (
! L . CheckParamUserType ( 1 , " cCompositeChat " ) | |
! L . CheckParamNumber ( 2 )
)
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Set the type:
2014-05-30 16:41:47 -04:00
int MessageType = mtCustom ;
L . GetStackValue ( 2 , MessageType ) ;
2015-07-29 11:04:03 -04:00
self - > SetMessageType ( static_cast < eMessageType > ( MessageType ) ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// 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()
2016-09-25 06:42:05 -04:00
// Exported manually to support call-chaining (return self)
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Check params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamUserType ( 1 , " cCompositeChat " ) )
{
return 0 ;
}
2018-05-02 03:50:36 -04:00
cCompositeChat * self = static_cast < cCompositeChat * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2014-10-20 16:55:07 -04:00
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 ;
}
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Call the processing
self - > UnderlineUrls ( ) ;
2016-02-05 16:45:45 -05:00
2014-03-04 16:17:23 -05:00
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop ( L , 1 ) ;
return 1 ;
}
2019-08-08 21:13:15 -04:00
static int tolua_cCuboid_Assign ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cCuboid " ) )
{
return 0 ;
}
cCuboid * self = nullptr ;
L . GetStackValue ( 1 , self ) ;
// Check the old coord-based signature:
int x1 , y1 , z1 , x2 , y2 , z2 ;
if ( L . GetStackValues ( 2 , x1 , y1 , z1 , x2 , y2 , z2 ) )
{
LOGWARNING ( " cCuboid:Assign(x1, y1, z1, x2, y2, z2) is deprecated, use cCuboid:Assign(Vector3i, Vector3i) instead. " ) ;
L . LogStackTrace ( ) ;
self - > Assign ( { x1 , y1 , z1 } , { x2 , y2 , z2 } ) ;
return 0 ;
}
// Try the (cCuboid) param version:
cCuboid * other = nullptr ;
if ( L . GetStackValue ( 2 , other ) & & ( other ! = nullptr ) )
{
self - > Assign ( * other ) ;
return 0 ;
}
// Try the (Vector3i, Vector3i) param version:
Vector3i * pt1 = nullptr ;
Vector3i * pt2 = nullptr ;
if ( L . GetStackValues ( 2 , pt1 , pt2 ) & & ( pt1 ! = nullptr ) & & ( pt2 ! = nullptr ) )
{
self - > Assign ( * pt1 , * pt2 ) ;
return 0 ;
}
return L . ApiParamError ( " Invalid parameter, expected either a cCuboid or two Vector3i-s. " ) ;
}
static int tolua_cCuboid_IsInside ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cCuboid " ) )
{
return 0 ;
}
cCuboid * self = nullptr ;
L . GetStackValue ( 1 , self ) ;
// Check the old coord-based signature:
int x , y , z ;
if ( L . GetStackValues ( 2 , x , y , z ) )
{
LOGWARNING ( " cCuboid:IsInside(x, y, z) is deprecated, use cCuboid:IsInside(Vector3d) instead. " ) ;
L . LogStackTrace ( ) ;
self - > Move ( { x , y , z } ) ;
return 0 ;
}
// Try the (Vector3i) param version:
{
Vector3i * pt = nullptr ;
if ( L . GetStackValue ( 2 , pt ) & & ( pt ! = nullptr ) )
{
L . Push ( self - > IsInside ( * pt ) ) ;
return 1 ;
}
}
// Try the (Vector3d) param version:
{
Vector3d * pt = nullptr ;
if ( L . GetStackValue ( 2 , pt ) & & ( pt ! = nullptr ) )
{
L . Push ( self - > IsInside ( * pt ) ) ;
return 1 ;
}
}
return L . ApiParamError ( " Invalid parameter #2, expected a Vector3i or a Vector3d. " ) ;
}
static int tolua_cCuboid_Move ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cCuboid " ) )
{
return 0 ;
}
cCuboid * self = nullptr ;
L . GetStackValue ( 1 , self ) ;
// Check the old coord-based signature:
int x , y , z ;
if ( L . GetStackValues ( 2 , x , y , z ) )
{
LOGWARNING ( " cCuboid:Move(x, y, z) is deprecated, use cCuboid:Move(Vector3i) instead. " ) ;
L . LogStackTrace ( ) ;
self - > Move ( { x , y , z } ) ;
return 0 ;
}
Vector3i * offset = nullptr ;
if ( ! L . GetStackValue ( 2 , offset ) | | ( offset = = nullptr ) )
{
return L . ApiParamError ( " Invalid parameter #2, expected a Vector3i. " ) ;
}
self - > Move ( * offset ) ;
return 0 ;
}
2018-01-14 13:44:45 -05:00
static int tolua_cEntity_IsSubmerged ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cEntity " ) )
{
return 0 ;
}
// Get the params:
cEntity * self = nullptr ;
L . GetStackValue ( 1 , self ) ;
// API function deprecated:
LOGWARNING ( " cEntity:IsSubmerged() is deprecated. Use cEntity:IsHeadInWater() instead. " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
L . Push ( self - > IsHeadInWater ( ) ) ;
return 1 ;
}
static int tolua_cEntity_IsSwimming ( lua_State * tolua_S )
{
// Check the params:
cLuaState L ( tolua_S ) ;
if ( ! L . CheckParamSelf ( " cEntity " ) )
{
return 0 ;
}
// Get the params:
cEntity * self = nullptr ;
L . GetStackValue ( 1 , self ) ;
// API function deprecated
LOGWARNING ( " cEntity:IsSwimming() is deprecated. Use cEntity:IsInWater() instead. " ) ;
cLuaState : : LogStackTrace ( tolua_S ) ;
L . Push ( self - > IsInWater ( ) ) ;
return 1 ;
}
2016-12-07 15:15:30 -05:00
static int tolua_cEntity_GetPosition ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
// Get the params:
2018-05-02 03:50:36 -04:00
cEntity * self = static_cast < cEntity * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2016-12-07 15:15:30 -05:00
if ( self = = nullptr )
{
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , static_cast < void * > ( self ) ) ;
return 0 ;
}
L . Push ( Mtolua_new ( ( Vector3d ) ( self - > GetPosition ( ) ) ) ) ;
tolua_register_gc ( L , lua_gettop ( L ) ) ; // Make Lua own the object
return 1 ;
}
static int tolua_cEntity_GetSpeed ( lua_State * tolua_S )
{
cLuaState L ( tolua_S ) ;
// Get the params:
2018-05-02 03:50:36 -04:00
cEntity * self = static_cast < cEntity * > ( tolua_tousertype ( tolua_S , 1 , nullptr ) ) ;
2016-12-07 15:15:30 -05:00
if ( self = = nullptr )
{
LOGWARNING ( " %s: invalid self (%p) " , __FUNCTION__ , static_cast < void * > ( self ) ) ;
return 0 ;
}
L . Push ( Mtolua_new ( ( Vector3d ) ( self - > GetSpeed ( ) ) ) ) ;
tolua_register_gc ( L , lua_gettop ( L ) ) ; // Make Lua own the object
return 1 ;
}
2015-05-13 05:30:57 -04:00
void cManualBindings : : 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 " ) ;
2015-05-13 05:30:57 -04:00
tolua_usertype ( tolua_S , " cLineBlockTracer " ) ;
2015-02-23 06:53:02 -05:00
tolua_usertype ( tolua_S , " cStringCompression " ) ;
2015-12-25 12:50:25 -05:00
tolua_usertype ( tolua_S , " cUrlParser " ) ;
2015-05-13 05:30:57 -04:00
tolua_cclass ( tolua_S , " cCryptoHash " , " cCryptoHash " , " " , nullptr ) ;
tolua_cclass ( tolua_S , " cLineBlockTracer " , " cLineBlockTracer " , " " , nullptr ) ;
2015-02-23 06:53:02 -05:00
tolua_cclass ( tolua_S , " cStringCompression " , " cStringCompression " , " " , nullptr ) ;
2015-12-25 12:50:25 -05:00
tolua_cclass ( tolua_S , " cUrlParser " , " cUrlParser " , " " , 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
2015-05-13 05:30:57 -04:00
2016-06-05 12:23:16 -04:00
tolua_beginmodule ( tolua_S , " cBoundingBox " ) ;
tolua_function ( tolua_S , " CalcLineIntersection " , tolua_cBoundingBox_CalcLineIntersection ) ;
tolua_function ( tolua_S , " Intersect " , tolua_cBoundingBox_Intersect ) ;
tolua_endmodule ( tolua_S ) ;
2016-06-30 13:35:00 -04:00
tolua_beginmodule ( tolua_S , " cChunkDesc " ) ;
tolua_function ( tolua_S , " GetBlockTypeMeta " , tolua_cChunkDesc_GetBlockTypeMeta ) ;
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cClientHandle " ) ;
2017-08-25 08:43:18 -04:00
tolua_constant ( tolua_S , " MAX_VIEW_DISTANCE " , cClientHandle : : MAX_VIEW_DISTANCE ) ;
tolua_constant ( tolua_S , " MIN_VIEW_DISTANCE " , cClientHandle : : MIN_VIEW_DISTANCE ) ;
2017-08-27 17:10:20 -04:00
tolua_function ( tolua_S , " GetForgeMods " , tolua_cClientHandle_GetForgeMods ) ;
2017-08-25 08:43:18 -04:00
tolua_function ( tolua_S , " SendPluginMessage " , tolua_cClientHandle_SendPluginMessage ) ;
tolua_function ( tolua_S , " GetUUID " , tolua_cClientHandle_GetUUID ) ;
tolua_function ( tolua_S , " GenerateOfflineUUID " , tolua_cClientHandle_GenerateOfflineUUID ) ;
tolua_function ( tolua_S , " IsUUIDOnline " , tolua_cClientHandle_IsUUIDOnline ) ;
2015-05-13 05:30:57 -04:00
tolua_endmodule ( tolua_S ) ;
2017-07-12 06:30:43 -04:00
tolua_beginmodule ( tolua_S , " cColor " ) ;
tolua_function ( tolua_S , " GetColor " , tolua_cColor_GetColor ) ;
tolua_endmodule ( tolua_S ) ;
2014-03-04 16:17:23 -05:00
tolua_beginmodule ( tolua_S , " cCompositeChat " ) ;
2016-09-25 06:42:05 -04:00
tolua_function ( tolua_S , " new " , tolua_cCompositeChat_new ) ;
tolua_function ( tolua_S , " new_local " , tolua_cCompositeChat_new_local ) ;
tolua_function ( tolua_S , " .call " , tolua_cCompositeChat_new_local ) ;
2014-03-04 16:17:23 -05:00
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 ) ;
2016-09-25 06:42:05 -04:00
tolua_function ( tolua_S , " Clear " , tolua_cCompositeChat_Clear ) ;
2014-03-04 16:17:23 -05:00
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 ) ;
2015-05-13 05:30:57 -04: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 ) ;
2019-08-08 21:13:15 -04:00
tolua_beginmodule ( tolua_S , " cCuboid " ) ;
tolua_function ( tolua_S , " Assign " , tolua_cCuboid_Assign ) ;
tolua_function ( tolua_S , " IsInside " , tolua_cCuboid_IsInside ) ;
tolua_function ( tolua_S , " Move " , tolua_cCuboid_Move ) ;
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cEntity " ) ;
tolua_constant ( tolua_S , " INVALID_ID " , cEntity : : INVALID_ID ) ;
2018-01-14 13:44:45 -05:00
tolua_function ( tolua_S , " IsSubmerged " , tolua_cEntity_IsSubmerged ) ;
tolua_function ( tolua_S , " IsSwimming " , tolua_cEntity_IsSwimming ) ;
2016-12-07 15:15:30 -05:00
tolua_function ( tolua_S , " GetPosition " , tolua_cEntity_GetPosition ) ;
tolua_function ( tolua_S , " GetSpeed " , tolua_cEntity_GetSpeed ) ;
2015-05-13 05:30:57 -04:00
tolua_endmodule ( tolua_S ) ;
tolua_beginmodule ( tolua_S , " cFile " ) ;
2015-09-26 16:54:18 -04:00
tolua_function ( tolua_S , " ChangeFileExt " , tolua_cFile_ChangeFileExt ) ;
tolua_function ( tolua_S , " Copy " , tolua_cFile_Copy ) ;
tolua_function ( tolua_S , " CreateFolder " , tolua_cFile_CreateFolder ) ;
tolua_function ( tolua_S , " CreateFolderRecursive " , tolua_cFile_CreateFolderRecursive ) ;
tolua_function ( tolua_S , " Delete " , tolua_cFile_Delete ) ;
tolua_function ( tolua_S , " DeleteFile " , tolua_cFile_DeleteFile ) ;
tolua_function ( tolua_S , " DeleteFolder " , tolua_cFile_DeleteFolder ) ;
tolua_function ( tolua_S , " DeleteFolderContents " , tolua_cFile_DeleteFolderContents ) ;
tolua_function ( tolua_S , " Exists " , tolua_cFile_Exists ) ;
tolua_function ( tolua_S , " GetFolderContents " , tolua_cFile_GetFolderContents ) ;
tolua_function ( tolua_S , " GetLastModificationTime " , tolua_cFile_GetLastModificationTime ) ;
tolua_function ( tolua_S , " GetSize " , tolua_cFile_GetSize ) ;
tolua_function ( tolua_S , " IsFile " , tolua_cFile_IsFile ) ;
tolua_function ( tolua_S , " IsFolder " , tolua_cFile_IsFolder ) ;
tolua_function ( tolua_S , " ReadWholeFile " , tolua_cFile_ReadWholeFile ) ;
tolua_function ( tolua_S , " Rename " , tolua_cFile_Rename ) ;
2015-05-13 05:30:57 -04:00
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 ) ;
2015-05-13 05:30:57 -04:00
2017-08-18 06:29:54 -04:00
tolua_beginmodule ( tolua_S , " cItem " ) ;
tolua_variable ( tolua_S , " m_LoreTable " , tolua_get_cItem_m_LoreTable , tolua_set_cItem_m_LoreTable ) ;
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cItemGrid " ) ;
tolua_function ( tolua_S , " GetSlotCoords " , Lua_ItemGrid_GetSlotCoords ) ;
tolua_endmodule ( tolua_S ) ;
2013-08-07 08:34:00 -04:00
tolua_beginmodule ( tolua_S , " cLineBlockTracer " ) ;
2017-05-11 08:34:36 -04:00
tolua_function ( tolua_S , " FirstSolidHitTrace " , tolua_cLineBlockTracer_FirstSolidHitTrace ) ;
tolua_function ( tolua_S , " LineOfSightTrace " , tolua_cLineBlockTracer_LineOfSightTrace ) ;
tolua_function ( tolua_S , " Trace " , tolua_cLineBlockTracer_Trace ) ;
tolua_constant ( tolua_S , " losAir " , cLineBlockTracer : : losAir ) ;
tolua_constant ( tolua_S , " losWater " , cLineBlockTracer : : losWater ) ;
tolua_constant ( tolua_S , " losLava " , cLineBlockTracer : : losLava ) ;
2013-08-07 08:34:00 -04:00
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cLuaWindow " ) ;
2016-06-10 15:30:07 -04:00
tolua_function ( tolua_S , " new " , tolua_cLuaWindow_new ) ;
tolua_function ( tolua_S , " new_local " , tolua_cLuaWindow_new_local ) ;
tolua_function ( tolua_S , " .call " , tolua_cLuaWindow_new_local ) ;
2017-08-17 10:27:43 -04:00
tolua_function ( tolua_S , " SetOnClicked " , tolua_SetObjectCallback < cLuaWindow , & cLuaWindow : : SetOnClicked > ) ;
2015-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " SetOnClosing " , tolua_SetObjectCallback < cLuaWindow , & cLuaWindow : : SetOnClosing > ) ;
tolua_function ( tolua_S , " SetOnSlotChanged " , tolua_SetObjectCallback < cLuaWindow , & cLuaWindow : : SetOnSlotChanged > ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
2014-02-23 06:25:02 -05:00
tolua_beginmodule ( tolua_S , " cMapManager " ) ;
2015-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " DoWithMap " , DoWithID < cMapManager , cMap , & cMapManager : : DoWithMap > ) ;
2014-02-23 06:25:02 -05:00
tolua_endmodule ( tolua_S ) ;
2014-03-01 07:03:16 -05:00
2017-08-25 08:43:18 -04:00
tolua_beginmodule ( tolua_S , " cMobHeadEntity " ) ;
tolua_function ( tolua_S , " SetOwner " , tolua_cMobHeadEntity_SetOwner ) ;
tolua_function ( tolua_S , " GetOwnerUUID " , tolua_cMobHeadEntity_GetOwnerUUID ) ;
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cMojangAPI " ) ;
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 ) ;
tolua_function ( tolua_S , " MakeUUIDDashed " , tolua_cMojangAPI_MakeUUIDDashed ) ;
tolua_function ( tolua_S , " MakeUUIDShort " , tolua_cMojangAPI_MakeUUIDShort ) ;
2014-03-01 07:03:16 -05:00
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cPlayer " ) ;
tolua_function ( tolua_S , " GetPermissions " , tolua_cPlayer_GetPermissions ) ;
tolua_function ( tolua_S , " GetRestrictions " , tolua_cPlayer_GetRestrictions ) ;
tolua_function ( tolua_S , " PermissionMatches " , tolua_cPlayer_PermissionMatches ) ;
2017-08-25 08:43:18 -04:00
tolua_function ( tolua_S , " GetUUID " , tolua_cPlayer_GetUUID ) ;
2015-05-13 05:30:57 -04:00
tolua_endmodule ( tolua_S ) ;
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 ) ;
2016-02-05 16:45:45 -05:00
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cPluginLua " ) ;
tolua_function ( tolua_S , " AddWebTab " , tolua_cPluginLua_AddWebTab ) ;
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-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " DoWithPlugin " , StaticDoWith < cPluginManager , cPlugin , & cPluginManager : : DoWithPlugin > ) ;
2015-05-10 16:51:16 -04:00
tolua_function ( tolua_S , " ExecuteConsoleCommand " , tolua_cPluginManager_ExecuteConsoleCommand ) ;
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-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " ForEachPlugin " , 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 ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cRoot " ) ;
2017-08-25 08:43:18 -04:00
tolua_function ( tolua_S , " DoWithPlayerByUUID " , tolua_cRoot_DoWithPlayerByUUID ) ;
2015-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " FindAndDoWithPlayer " , DoWith < cRoot , cPlayer , & cRoot : : FindAndDoWithPlayer > ) ;
tolua_function ( tolua_S , " ForEachPlayer " , ForEach < cRoot , cPlayer , & cRoot : : ForEachPlayer > ) ;
tolua_function ( tolua_S , " ForEachWorld " , ForEach < cRoot , cWorld , & cRoot : : ForEachWorld > ) ;
2015-09-24 04:48:33 -04:00
tolua_function ( tolua_S , " GetBrewingRecipe " , tolua_cRoot_GetBrewingRecipe ) ;
2015-06-05 04:34:13 -04:00
tolua_function ( tolua_S , " GetBuildCommitID " , tolua_cRoot_GetBuildCommitID ) ;
tolua_function ( tolua_S , " GetBuildDateTime " , tolua_cRoot_GetBuildDateTime ) ;
tolua_function ( tolua_S , " GetBuildID " , tolua_cRoot_GetBuildID ) ;
tolua_function ( tolua_S , " GetBuildSeriesName " , tolua_cRoot_GetBuildSeriesName ) ;
2015-05-13 05:30:57 -04:00
tolua_function ( tolua_S , " GetFurnaceRecipe " , tolua_cRoot_GetFurnaceRecipe ) ;
2013-05-30 16:40:43 -04:00
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " cScoreboard " ) ;
tolua_function ( tolua_S , " ForEachObjective " , ForEach < cScoreboard , cObjective , & cScoreboard : : ForEachObjective > ) ;
tolua_function ( tolua_S , " ForEachTeam " , ForEach < cScoreboard , cTeam , & cScoreboard : : ForEachTeam > ) ;
2016-05-29 13:12:18 -04:00
tolua_function ( tolua_S , " GetTeamNames " , tolua_cScoreboard_GetTeamNames ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2017-08-27 17:10:20 -04:00
tolua_beginmodule ( tolua_S , " cServer " ) ;
tolua_function ( tolua_S , " RegisterForgeMod " , tolua_cServer_RegisterForgeMod ) ;
tolua_endmodule ( tolua_S ) ;
2015-05-13 05:30:57 -04: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 ) ;
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
2013-07-28 20:37:59 -04:00
2015-12-25 12:50:25 -05:00
tolua_beginmodule ( tolua_S , " cUrlParser " ) ;
tolua_function ( tolua_S , " GetDefaultPort " , tolua_cUrlParser_GetDefaultPort ) ;
tolua_function ( tolua_S , " IsKnownScheme " , tolua_cUrlParser_IsKnownScheme ) ;
tolua_function ( tolua_S , " Parse " , tolua_cUrlParser_Parse ) ;
tolua_function ( tolua_S , " ParseAuthorityPart " , tolua_cUrlParser_ParseAuthorityPart ) ;
2016-12-25 12:29:21 -05:00
tolua_function ( tolua_S , " UrlDecode " , tolua_cUrlParser_UrlDecode ) ;
tolua_function ( tolua_S , " UrlEncode " , tolua_cUrlParser_UrlEncode ) ;
2015-12-25 12:50:25 -05:00
tolua_endmodule ( tolua_S ) ;
2013-07-28 20:37:59 -04:00
tolua_beginmodule ( tolua_S , " cWebAdmin " ) ;
2016-03-02 04:05:10 -05:00
tolua_function ( tolua_S , " AddWebTab " , tolua_cWebAdmin_AddWebTab ) ;
tolua_function ( tolua_S , " GetAllWebTabs " , tolua_cWebAdmin_GetAllWebTabs ) ;
tolua_function ( tolua_S , " GetPage " , tolua_cWebAdmin_GetPage ) ;
tolua_function ( tolua_S , " GetURLEncodedString " , tolua_cWebAdmin_GetURLEncodedString ) ;
2013-07-28 20:37:59 -04:00
tolua_endmodule ( tolua_S ) ;
2012-06-14 09:06:06 -04:00
2015-05-13 05:30:57 -04:00
tolua_beginmodule ( tolua_S , " HTTPRequest " ) ;
tolua_variable ( tolua_S , " FormData " , tolua_get_HTTPRequest_FormData , nullptr ) ;
tolua_variable ( tolua_S , " Params " , tolua_get_HTTPRequest_Params , nullptr ) ;
tolua_variable ( tolua_S , " PostParams " , tolua_get_HTTPRequest_PostParams , nullptr ) ;
2013-04-10 15:52:03 -04:00
tolua_endmodule ( tolua_S ) ;
2015-01-28 09:14:05 -05:00
BindNetwork ( tolua_S ) ;
2015-05-13 05:30:57 -04:00
BindRankManager ( tolua_S ) ;
BindWorld ( tolua_S ) ;
2017-06-24 05:58:06 -04:00
BindBlockArea ( tolua_S ) ;
2015-03-21 10:18:17 -04:00
2012-06-14 09:06:06 -04:00
tolua_endmodule ( tolua_S ) ;
}