diff options
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 1 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 26 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 3 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 8 | ||||
-rw-r--r-- | src/Bindings/PluginManager.cpp | 2 | ||||
-rw-r--r-- | src/Bindings/PluginManager.h | 4 |
6 files changed, 43 insertions, 1 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..6c295102f 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -70,6 +70,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" +$cfile "../CompositeChat.h" diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index c6be7be3c..ca7f6b255 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -173,6 +173,31 @@ void cLuaState::Detach(void) +void cLuaState::AddPackagePath(const AString & a_PathVariable, const AString & a_Path) +{ + // Get the current path: + lua_getfield(m_LuaState, LUA_GLOBALSINDEX, "package"); // Stk: <package> + lua_getfield(m_LuaState, -1, a_PathVariable.c_str()); // Stk: <package> <package.path> + size_t len = 0; + const char * PackagePath = lua_tolstring(m_LuaState, -1, &len); + + // Append the new path: + AString NewPackagePath(PackagePath, len); + NewPackagePath.append(LUA_PATHSEP); + NewPackagePath.append(a_Path); + + // Set the new path to the environment: + lua_pop(m_LuaState, 1); // Stk: <package> + lua_pushlstring(m_LuaState, NewPackagePath.c_str(), NewPackagePath.length()); // Stk: <package> <NewPackagePath> + lua_setfield(m_LuaState, -2, a_PathVariable.c_str()); // Stk: <package> + lua_pop(m_LuaState, 1); + lua_pop(m_LuaState, 1); // Stk: - +} + + + + + bool cLuaState::LoadFile(const AString & a_FileName) { ASSERT(IsValid()); @@ -1251,6 +1276,7 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) case LUA_TLIGHTUSERDATA: Printf(Value, "%p", lua_touserdata(a_LuaState, i)); break; case LUA_TNUMBER: Printf(Value, "%f", (double)lua_tonumber(a_LuaState, i)); break; case LUA_TSTRING: Printf(Value, "%s", lua_tostring(a_LuaState, i)); break; + case LUA_TTABLE: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break; default: break; } LOGD(" Idx %d: type %d (%s) %s", i, Type, lua_typename(a_LuaState, Type), Value.c_str()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index b9bf10142..dcb660c3f 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -154,6 +154,9 @@ public: /** Returns true if the m_LuaState is valid */ bool IsValid(void) const { return (m_LuaState != NULL); } + /** Adds the specified path to package.<a_PathVariable> */ + void AddPackagePath(const AString & a_PathVariable, const AString & a_Path); + /** Loads the specified file Returns false and logs a warning to the console if not successful (but the LuaState is kept open). m_SubsystemName is displayed in the warning log message. diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 773d522c4..45c8216be 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -82,6 +82,14 @@ bool cPluginLua::Initialize(void) lua_pushstring(m_LuaState, GetName().c_str()); lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME); + // Add the plugin's folder to the package.path and package.cpath variables (#693): + m_LuaState.AddPackagePath("path", FILE_IO_PREFIX + GetLocalFolder() + "/?.lua"); + #ifdef _WIN32 + m_LuaState.AddPackagePath("cpath", GetLocalFolder() + "\\?.dll"); + #else + m_LuaState.AddPackagePath("cpath", FILE_IO_PREFIX + GetLocalFolder() + "/?.so"); + #endif + tolua_pushusertype(m_LuaState, this, "cPluginLua"); lua_setglobal(m_LuaState, "g_Plugin"); } diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c6c8c081e..c7df6357e 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -56,7 +56,7 @@ void cPluginManager::ReloadPlugins(void) void cPluginManager::FindPlugins(void) { - AString PluginsPath = FILE_IO_PREFIX + AString( "Plugins/" ); + AString PluginsPath = GetPluginsPath() + "/"; // First get a clean list of only the currently running plugins, we don't want to mess those up for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();) diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index c78bceda1..44bc5a8d7 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -266,6 +266,10 @@ public: // tolua_export Returns false if plugin not found, and the value that the callback has returned otherwise. */ bool DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback); + /** Returns the path where individual plugins' folders are expected. + The path doesn't end in a slash. */ + static AString GetPluginsPath(void) { return FILE_IO_PREFIX + AString("Plugins"); } // tolua_export + private: friend class cRoot; |