Description: Make the lua loaders use a relative path from LuaGlobal.lua
Author: Craig Small <csmall@debian.org>
Last-Update: 2011-08-22
--- a/src/TLuaInterpreter.cpp
+++ b/src/TLuaInterpreter.cpp
@@ -13234,7 +13234,7 @@
 #if defined(Q_OS_MAC)
     QString path = QCoreApplication::applicationDirPath() + "/../Resources/mudlet-lua/lua/LuaGlobal.lua";
 #else
-    QString path = "../src/mudlet-lua/lua/LuaGlobal.lua";
+    QString path = "/usr/share/games/mudlet/lua/LuaGlobal.lua";
     // Additional "../src/" allows location of lua code when object code is in a
     // directory alongside src directory as occurs using Qt Creator "Shadow Builds"
 #endif
--- a/src/mudlet-lua/lua/LuaGlobal.lua
+++ b/src/mudlet-lua/lua/LuaGlobal.lua
@@ -2,6 +2,7 @@
 --- Mudlet Lua packages loader
 ----------------------------------------------------------------------------------
 
+local LUA_DIR = "/usr/share/games/mudlet/lua/"
 
 if package.loaded["rex_pcre"] then rex = require "rex_pcre" end
 if package.loaded["lpeg"] then lpeg = require "lpeg" end
@@ -118,39 +119,11 @@
 	"GMCP.lua",
 }
 
--- on windows LuaGlobal gets loaded with the current directory set to mudlet.exe's location
--- on Mac, it's set to LuaGlobals location - or the Applications folder, or something else...
--- So work out where to load Lua files from using some heuristics
--- Addition of "../src/" to front of first path allows things to work when "Shadow Building"
--- option of Qt Creator is used (separates object code from source code in directories
--- beside the latter, allowing parallel builds against different Qt Library versions
--- or {Release|Debug} types).
--- TODO: extend to support common Lua code being placed in system shared directory
--- tree as ought to happen for *nix install builds.
-local prefixes = {"../src/mudlet-lua/lua/", "../Resources/mudlet-lua/lua/",
-    "mudlet.app/Contents/Resources/mudlet-lua/lua/", "mudlet-lua/lua"}
-
-local prefix
-for i = 1, #prefixes do
-    if lfs.attributes(prefixes[i]) then
-        prefix = prefixes[i]
-        break
-    end
-end
-
--- For some reason on windows, mudlet-lua/lua/ does not register as a directory with the above strategy.
--- Thus, if chosen we need to append a slash.
-if prefix == "mudlet-lua/lua" then
-	prefix = prefix .. "/"
-end
-
-if not prefix then
-        echo("Error locating Lua files from LuaGlobal - we're looking from '"..lfs.currentdir().."'.\n")
-	return
-end
+-- On Debian systems, LuaGlobal is loaded from LUA_DIR which is a system
+-- directory
 
 for _, package in ipairs(packages) do
-        local result, msg = pcall(dofile, prefix .. package)
+        local result, msg = pcall(dofile, LUA_DIR .. package)
 	if not result then echo("Error attempting to load file: " .. package .. ": "..msg.."\n") end
 end
 
