From 41ba1a7642105ac21b67f4febac3eceef6a39f0a Mon Sep 17 00:00:00 2001 From: faketruth Date: Sat, 13 Oct 2012 23:34:47 +0000 Subject: Completely removed support for old style Lua plugins (can use both Plugin and NewPlugin in settings.ini for now) Removed cPlugin_Lua, obviously cPluginManager stores plugins by their (folder)name cPluginManager now scans the Plugins folder for potential plugins and adds them as non-loaded plugins Added a DisablePlugin and LoadPlugin to disable and load plugins on a per-plugin basis instead of all at once cPluginManager::FindPlugins refreshes the plugin list by removing non-existing plugins and adding new plugins Made it incredibly easy to use new plugins from the WebAdmin Exposed some food/hunger related functions in cPlayer to Lua git-svn-id: http://mc-server.googlecode.com/svn/trunk@959 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Plugin_NewLua.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'source/Plugin_NewLua.cpp') diff --git a/source/Plugin_NewLua.cpp b/source/Plugin_NewLua.cpp index 866239b3a..55a04a88c 100644 --- a/source/Plugin_NewLua.cpp +++ b/source/Plugin_NewLua.cpp @@ -31,11 +31,11 @@ extern bool report_errors(lua_State* lua, int status); -cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName ) +cPlugin_NewLua::cPlugin_NewLua( const AString & a_PluginDirectory ) : m_LuaState( 0 ) , cWebPlugin() + , cPlugin( a_PluginDirectory ) { - m_Directory = a_PluginName; } @@ -82,7 +82,7 @@ bool cPlugin_NewLua::Initialize() int s = luaL_loadfile(m_LuaState, Path.c_str() ); if( report_errors( m_LuaState, s ) ) { - LOGERROR("Can't load plugin %s because of an error in file %s", m_Directory.c_str(), Path.c_str() ); + LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; @@ -91,7 +91,7 @@ bool cPlugin_NewLua::Initialize() s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0); if( report_errors( m_LuaState, s ) ) { - LOGERROR("Error in plugin %s in file %s", m_Directory.c_str(), Path.c_str() ); + LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; @@ -117,7 +117,7 @@ bool cPlugin_NewLua::Initialize() if( !lua_isboolean( m_LuaState, -1 ) ) { - LOGWARN("Error in plugin %s Initialize() must return a boolean value!", m_Directory.c_str() ); + LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() ); lua_close( m_LuaState ); m_LuaState = 0; return false; @@ -131,15 +131,6 @@ bool cPlugin_NewLua::Initialize() -AString cPlugin_NewLua::GetLocalDirectory(void) const -{ - return std::string("Plugins/") + m_Directory; -} - - - - - void cPlugin_NewLua::OnDisable() { cCSLock Lock( m_CriticalSection ); @@ -699,7 +690,7 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use cPlugin_NewLua * cPlugin_NewLua::CreateWebPlugin(lua_State * a_LuaState) { LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now. (plugin \"%s\" in folder \"%s\")", - cPlugin::GetName().c_str(), m_Directory.c_str() + cPlugin::GetName().c_str(), GetLocalDirectory().c_str() ); return this; } @@ -797,7 +788,7 @@ bool cPlugin_NewLua::PushFunction( const char* a_FunctionName, bool a_bLogError { if( a_bLogError ) { - LOGWARN("Error in plugin %s: Could not find function %s()", m_Directory.c_str(), a_FunctionName ); + LOGWARN("Error in plugin %s: Could not find function %s()", GetLocalDirectory().c_str(), a_FunctionName ); } lua_pop(m_LuaState,1); return false; @@ -810,7 +801,7 @@ bool cPlugin_NewLua::CallFunction( int a_NumArgs, int a_NumResults, const char* int s = lua_pcall(m_LuaState, a_NumArgs, a_NumResults, 0); if( report_errors( m_LuaState, s ) ) { - LOGWARN("Error in plugin %s calling function %s()", m_Directory.c_str(), a_FunctionName ); + LOGWARN("Error in plugin %s calling function %s()", GetLocalDirectory().c_str(), a_FunctionName ); return false; } return true; -- cgit v1.2.3