summaryrefslogtreecommitdiffstats
path: root/source/cPlugin_NewLua.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-26 23:21:23 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-26 23:21:23 +0100
commit507d9d57a93536a633d8ac9a5b0c95b4a5b48009 (patch)
tree38ef3c2429d14d7b09760b7f49f3c576e111ccca /source/cPlugin_NewLua.cpp
parentWorking on a new plugin design with Lua. While retaining backwards compatibility of course... (diff)
downloadcuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar.gz
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar.bz2
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar.lz
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar.xz
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.tar.zst
cuberite-507d9d57a93536a633d8ac9a5b0c95b4a5b48009.zip
Diffstat (limited to '')
-rw-r--r--source/cPlugin_NewLua.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp
index 90647e011..f81f2e95e 100644
--- a/source/cPlugin_NewLua.cpp
+++ b/source/cPlugin_NewLua.cpp
@@ -11,6 +11,12 @@ extern "C"
#include "Bindings.h"
#include "ManualBindings.h"
+#ifdef _WIN32
+#include "wdirent.h"
+#else
+#include <dirent.h>
+#endif
+
extern bool report_errors(lua_State* lua, int status);
cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName )
@@ -38,29 +44,37 @@ bool cPlugin_NewLua::Initialize()
ManualBindings::Bind( m_LuaState );
}
- std::string PluginFiles[] = { std::string("Plugins/") + m_Directory + "/tick.lua"
- ,std::string("Plugins/") + m_Directory + "/main.lua" };
-
+ std::string PluginPath = std::string("Plugins/") + m_Directory + "/";
// Load all files for this plugin, and execute them
- for( int i = 0; i < 2; ++i )
- {
- int s = luaL_loadfile(m_LuaState, PluginFiles[i].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(), PluginFiles[i].c_str() );
- lua_close( m_LuaState );
- m_LuaState = 0;
- return false;
- }
-
- s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0);
- if( report_errors( m_LuaState, s ) )
+ DIR* dp;
+ struct dirent *entry;
+ if(dp = opendir( PluginPath.c_str() ))
+ {
+ while(entry = readdir(dp))
{
- LOGERROR("Error in plugin %s in file %s", m_Directory.c_str(), PluginFiles[i].c_str() );
- lua_close( m_LuaState );
- m_LuaState = 0;
- return false;
+ std::string FileName = entry->d_name;
+ if( FileName.find(".lua") != std::string::npos )
+ {
+ std::string Path = PluginPath + FileName;
+ 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() );
+ lua_close( m_LuaState );
+ m_LuaState = 0;
+ return false;
+ }
+
+ 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() );
+ lua_close( m_LuaState );
+ m_LuaState = 0;
+ return false;
+ }
+ }
}
}