<commit_before>
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "ManualBindings.h"
#include "tolua++.h"

#include "Root.h"
#include "World.h"
#include "Plugin.h"
#include "PluginLua.h"
#include "PluginManager.h"
#include "Entities/Player.h"
#include "WebAdmin.h"
#include "ClientHandle.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/DispenserEntity.h"
#include "BlockEntities/DropperEntity.h"
#include "BlockEntities/FurnaceEntity.h"
#include "BlockEntities/HopperEntity.h"
#include "md5/md5.h"
#include "LuaWindow.h"
#include "LineBlockTracer.h"





/****************************
 * Better error reporting for Lua
 **/
int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaError)
{
	// Retrieve current function name
	lua_Debug entry;
	VERIFY(lua_getstack(L, 0, &entry));
	VERIFY(lua_getinfo(L, "n", &entry));

	// 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;
}





int lua_do_error(lua_State* L, const char * a_pFormat, ...)
{
	// Retrieve current function name
	lua_Debug entry;
	VERIFY(lua_getstack(L, 0, &entry));
	VERIFY(lua_getinfo(L, "n", &entry));

	// Insert function name into error msg
	AString msg(a_pFormat);
	ReplaceString(msg, "#funcname#", entry.name?entry.name:"?");

	// Copied from luaL_error and modified
	va_list argp;
	va_start(argp, a_pFormat);
	luaL_where(L, 1);
	lua_pushvfstring(L, msg.c_str(), argp);
	va_end(argp);
	lua_concat(L, 2);
	return lua_error(L);
}





/****************************
 * Lua bound functions with special return types
 **/

static int tolua_StringSplit(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	std::string str   = (std::string)tolua_tocppstring(LuaState, 1, 0);
	std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);

	AStringVector Split = StringSplit(str, delim);
	LuaState.Push(Split);
	return 1;
}





static int tolua_StringSplitAndTrim(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	std::string str   = (std::string)tolua_tocppstring(LuaState, 1, 0);
	std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);

	AStringVector Split = StringSplitAndTrim(str, delim);
	LuaState.Push(Split);
	return 1;
}





static int tolua_LOG(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 0 );
	return 0;
}





static int tolua_LOGINFO(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 1 );
	return 0;
}





static int tolua_LOGWARN(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 2 );
	return 0;
}





static int tolua_LOGERROR(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 3 );
	return 0;
}





cPluginLua * GetLuaPlugin(lua_State * L)
{
	// Get the plugin identification out of LuaState:
	lua_getglobal(L, LUA_PLUGIN_INSTANCE_VAR_NAME);
	if (!lua_islightuserdata(L, -1))
	{
		LOGWARNING("%s: cannot get plugin instance, what have you done to my Lua state?", __FUNCTION__);
		lua_pop(L, 1);
		return NULL;
	}
	cPluginLua * Plugin = (cPluginLua *)lua_topointer(L, -1);
	lua_pop(L, 1);
	
	return Plugin;
}





static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	if (
		!LuaState.CheckParamUserTable(1, "cFile") ||
		!LuaState.CheckParamString   (2) ||
		!LuaState.CheckParamEnd      (3)
	)
	{
		return 0;
	}
	
	AString Folder = (AString)tolua_tocppstring(LuaState, 1, 0);

	AStringVector Contents = cFile::GetFolderContents(Folder);
	LuaState.Push(Contents);
	return 1;
}





template<
	class Ty1,
	class Ty2,<commit_msg>Fixed Lua bindings for cFile:GetFolderContents().<commit_after>
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "ManualBindings.h"
#include "tolua++.h"

#include "Root.h"
#include "World.h"
#include "Plugin.h"
#include "PluginLua.h"
#include "PluginManager.h"
#include "Entities/Player.h"
#include "WebAdmin.h"
#include "ClientHandle.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/DispenserEntity.h"
#include "BlockEntities/DropperEntity.h"
#include "BlockEntities/FurnaceEntity.h"
#include "BlockEntities/HopperEntity.h"
#include "md5/md5.h"
#include "LuaWindow.h"
#include "LineBlockTracer.h"





/****************************
 * Better error reporting for Lua
 **/
int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaError)
{
	// Retrieve current function name
	lua_Debug entry;
	VERIFY(lua_getstack(L, 0, &entry));
	VERIFY(lua_getinfo(L, "n", &entry));

	// 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;
}





int lua_do_error(lua_State* L, const char * a_pFormat, ...)
{
	// Retrieve current function name
	lua_Debug entry;
	VERIFY(lua_getstack(L, 0, &entry));
	VERIFY(lua_getinfo(L, "n", &entry));

	// Insert function name into error msg
	AString msg(a_pFormat);
	ReplaceString(msg, "#funcname#", entry.name?entry.name:"?");

	// Copied from luaL_error and modified
	va_list argp;
	va_start(argp, a_pFormat);
	luaL_where(L, 1);
	lua_pushvfstring(L, msg.c_str(), argp);
	va_end(argp);
	lua_concat(L, 2);
	return lua_error(L);
}





/****************************
 * Lua bound functions with special return types
 **/

static int tolua_StringSplit(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	std::string str   = (std::string)tolua_tocppstring(LuaState, 1, 0);
	std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);

	AStringVector Split = StringSplit(str, delim);
	LuaState.Push(Split);
	return 1;
}





static int tolua_StringSplitAndTrim(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	std::string str   = (std::string)tolua_tocppstring(LuaState, 1, 0);
	std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);

	AStringVector Split = StringSplitAndTrim(str, delim);
	LuaState.Push(Split);
	return 1;
}





static int tolua_LOG(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 0 );
	return 0;
}





static int tolua_LOGINFO(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 1 );
	return 0;
}





static int tolua_LOGWARN(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 2 );
	return 0;
}





static int tolua_LOGERROR(lua_State* tolua_S)
{
	const char* str = tolua_tocppstring(tolua_S,1,0);
	cMCLogger::GetInstance()->LogSimple( str, 3 );
	return 0;
}





cPluginLua * GetLuaPlugin(lua_State * L)
{
	// Get the plugin identification out of LuaState:
	lua_getglobal(L, LUA_PLUGIN_INSTANCE_VAR_NAME);
	if (!lua_islightuserdata(L, -1))
	{
		LOGWARNING("%s: cannot get plugin instance, what have you done to my Lua state?", __FUNCTION__);
		lua_pop(L, 1);
		return NULL;
	}
	cPluginLua * Plugin = (cPluginLua *)lua_topointer(L, -1);
	lua_pop(L, 1);
	
	return Plugin;
}





static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
	cLuaState LuaState(tolua_S);
	if (
		!LuaState.CheckParamUserTable(1, "cFile") ||
		!LuaState.CheckParamString   (2) ||
		!LuaState.CheckParamEnd      (3)
	)
	{
		return 0;
	}
	
	AString Folder = (AString)tolua_tocppstring(LuaState, 2, 0);

	AStringVector Contents = cFile::GetFolderContents(Folder);
	LuaState.Push(Contents);
	return 1;
}





template<
	class Ty1,
	class Ty2,
{'fraction_non_alphanumeric': 0.1496546431312356, 'fraction_numerical': 0.0117677155282681, 'mean_word_length': 5.225318471337579, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6927846', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3047, 'n_words': 651}