allow using the system Lua package path

upstream-master
rolandlo 5 years ago committed by Roland Lötscher
parent 5d3d746612
commit 00a96c1888
  1. 5
      plugins/MigrateFontSizes/main.lua
  2. 13
      src/plugin/Plugin.cpp

@ -3,9 +3,6 @@ function initUi()
app.registerUi({["menu"] = "Migrate font sizes with factor displayDPI / 72", ["callback"] = "migrate"});
app.registerUi({["menu"] = "Show font size migration dialog", ["callback"] = "showDialog"});
lgiInstallPaths = "/usr/share/lua/5.3/?.lua; /usr/local/share/lua/5.3/?.lua" -- change this if your lgi.lua file is located in a different directory
package.path = package.path .. ";../?.lua;" .. lgiInstallPaths
sourcePath = debug.getinfo(1).source:match("@?(.*/)")
end
@ -25,7 +22,7 @@ local currDpi
function showDialog()
local hasLgi, lgi = pcall(require, "lgi")
if not hasLgi then
app.msgbox("You need to have the Lua lgi-module installed in order to use the GUI for migrating font sizes. \n\n Also check the lgi module install paths in the file \n\n " .. sourcePath .. "main.lua \n\n Currently \n\n" .. lgiInstallPaths .. "\n\n is specified", {[1]="OK"})
app.msgbox("You need to have the Lua lgi-module installed and included in your Lua package path in order to use the GUI for migrating font sizes. \n\n", {[1]="OK"})
return
end

@ -166,17 +166,18 @@ void Plugin::addPluginToLuaPath() {
// get field "path" from table at top of stack (-1)
lua_getfield(lua.get(), -1, "path");
// For now: limit the include path to the current plugin folder, for security and compatibility reasons
// grab path string from top of stack
// std::string curPath = lua_tostring(lua, -1);
// curPath.append(";");
auto curPath = path / "?.lua";
std::string luaPath = lua_tostring(lua.get(), -1);
// get rid of the std::string on the stack we just pushed on line 5
// prepend the path of the current plugin
auto curPath = this->path / "?.lua";
std::string combinedPath = curPath.string() + ";" + luaPath;
// get rid of the std::string on the stack we just pushed
lua_pop(lua.get(), 1);
// push the new one
lua_pushstring(lua.get(), curPath.string().c_str());
lua_pushstring(lua.get(), combinedPath.c_str());
// set the field "path" in table at -2 with value at top of stack
lua_setfield(lua.get(), -2, "path");

Loading…
Cancel
Save