<commit_before>/*
 * ArcScript Scripts for Arcemu MMORPG Server
 * Copyright (C) 2008-2009 Arcemu Team
 * Copyright (C) 2007 Moon++ <http://www.moonplusplus.com/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "LUAEngine.h"
#include <ScriptSetup.h>

#ifdef WIN32
#pragma warning(disable:4129)
#pragma warning(disable:4244)
#endif

#if PLATFORM != PLATFORM_WIN32
#include <dirent.h>
#endif

ScriptMgr * m_scriptMgr = NULL;
Arcemu::Utility::TLSObject<PLUA_INSTANCE> lua_instance;
PLUA_INSTANCE LUA_COMPILER = NULL;

//static data initialization for our classes
const char * ScriptManager::mt = "LOADED_SCRIPTS";
const char * ReferenceHandler::refTable = "OBJECT_REFERENCES";

lua_engine::LuaScriptData lua_engine::compiled_scripts;
lua_engine::hooked_dummySpells lua_engine::_hooked_dummies;
lua_engine::ActiveStates lua_engine::activeStates;
FastMutex lua_engine::activestates_lock;
FastMutex lua_engine::scriptLock;


extern "C"
{
	 SCRIPT_DECL uint32 _exp_get_script_type()
	{ 
		return SCRIPT_TYPE_SCRIPT_ENGINE;
	}
	SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
	{
		m_scriptMgr = mgr;
		lua_engine::startupEngine();
	}

	SCRIPT_DECL void _exp_engine_unload(){
		LOG_DETAIL( "exp_engine_unload was called." );
	}

	SCRIPT_DECL void _export_engine_reload()
	{
		lua_engine::restartEngine();
	}
};

void lua_engine::report( lua_State * L ){
	int count = lua_gettop( L );

	while( count > 0 ){
		const char *msg= lua_tostring( L, -1 );
		LOG_ERROR( msg );
		lua_pop( L, 1 );
		count--;
	}
}<commit_msg>FIXED: Memory leaks in luabridge caused by never deleting compiled scripts.<commit_after>/*
 * ArcScript Scripts for Arcemu MMORPG Server
 * Copyright (C) 2008-2009 Arcemu Team
 * Copyright (C) 2007 Moon++ <http://www.moonplusplus.com/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "LUAEngine.h"
#include <ScriptSetup.h>

#ifdef WIN32
#pragma warning(disable:4129)
#pragma warning(disable:4244)
#endif

#if PLATFORM != PLATFORM_WIN32
#include <dirent.h>
#endif

ScriptMgr * m_scriptMgr = NULL;
Arcemu::Utility::TLSObject<PLUA_INSTANCE> lua_instance;
PLUA_INSTANCE LUA_COMPILER = NULL;

//static data initialization for our classes
const char * ScriptManager::mt = "LOADED_SCRIPTS";
const char * ReferenceHandler::refTable = "OBJECT_REFERENCES";

lua_engine::LuaScriptData lua_engine::compiled_scripts;
lua_engine::hooked_dummySpells lua_engine::_hooked_dummies;
lua_engine::ActiveStates lua_engine::activeStates;
FastMutex lua_engine::activestates_lock;
FastMutex lua_engine::scriptLock;


extern "C"
{
	 SCRIPT_DECL uint32 _exp_get_script_type()
	{ 
		return SCRIPT_TYPE_SCRIPT_ENGINE;
	}
	SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
	{
		m_scriptMgr = mgr;
		lua_engine::startupEngine();
	}

	SCRIPT_DECL void _exp_engine_unload(){
		le::scriptLock.Acquire();
		//delete the scripts shared between the Lua instances
		for(le::LuaScriptData::iterator itr = le::compiled_scripts.begin(); itr != le::compiled_scripts.end(); ++itr)
			delete itr->second;
		le::compiled_scripts.clear();
		le::scriptLock.Release();
	}

	SCRIPT_DECL void _export_engine_reload()
	{
		lua_engine::restartEngine();
	}
};

void lua_engine::report( lua_State * L ){
	int count = lua_gettop( L );

	while( count > 0 ){
		const char *msg= lua_tostring( L, -1 );
		LOG_ERROR( msg );
		lua_pop( L, 1 );
		count--;
	}
}
{'fraction_non_alphanumeric': 0.1015521064301552, 'fraction_numerical': 0.013303769401330377, 'mean_word_length': 5.046916890080429, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4818268', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1472, 'n_words': 445}