From de293999872346271cdfb5dbecbad7f77362b83b Mon Sep 17 00:00:00 2001 From: faketruth Date: Fri, 27 Jan 2012 23:47:32 +0000 Subject: Converted entire Core plugin including WebAdmin interface to new plugin method/system/thingy and sexyfied it. Made some changes to WebAdmin to make the new plugins work Old plugins still work like they're supposed to Not all hooks have been programmed for the new plugins yet, this still needs to be done git-svn-id: http://mc-server.googlecode.com/svn/trunk@182 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlugin_NewLua.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'source/cPlugin_NewLua.cpp') diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp index 81e629ce4..fd5a23772 100644 --- a/source/cPlugin_NewLua.cpp +++ b/source/cPlugin_NewLua.cpp @@ -1,6 +1,7 @@ #define LUA_USE_POSIX #include "cPlugin_NewLua.h" #include "cMCLogger.h" +#include "cWebPlugin_Lua.h" extern "C" { @@ -11,10 +12,10 @@ extern "C" #include "Bindings.h" #include "ManualBindings.h" -#ifdef _WIN32 -#include "wdirent.h" -#else -#include +#ifdef _WIN32 +#include "wdirent.h" +#else +#include #endif extern bool report_errors(lua_State* lua, int status); @@ -27,6 +28,12 @@ cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName ) cPlugin_NewLua::~cPlugin_NewLua() { + for( WebPluginList::iterator itr = m_WebPlugins.begin(); itr != m_WebPlugins.end(); ++itr ) + { + delete *itr; + } + m_WebPlugins.clear(); + if( m_LuaState ) { lua_close( m_LuaState ); @@ -49,9 +56,9 @@ bool cPlugin_NewLua::Initialize() // Load all files for this plugin, and execute them DIR* dp; struct dirent *entry; - if(dp = opendir( PluginPath.c_str() )) - { - while(entry = readdir(dp)) + if(dp = opendir( PluginPath.c_str() )) + { + while(entry = readdir(dp)) { std::string FileName = entry->d_name; if( FileName.find(".lua") != std::string::npos ) @@ -76,6 +83,7 @@ bool cPlugin_NewLua::Initialize() } } } + closedir( dp ); } @@ -177,7 +185,19 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer ) return bRetVal; } +cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState) +{ + if( a_LuaState != m_LuaState ) + { + LOGERROR("Not allowed to create a WebPlugin from another plugin but your own!"); + return 0; + } + cWebPlugin_Lua* WebPlugin = new cWebPlugin_Lua( this ); + m_WebPlugins.push_back( WebPlugin ); + + return WebPlugin; +} // Helper functions -- cgit v1.2.3