[PATCH] Fix for when lua is installed to a non-standard PREFIX

2 views
Skip to first unread message

dcurtis

unread,
Mar 5, 2009, 4:43:15 PM3/5/09
to wmii...@googlegroups.com

I had a problem using wmiirc-lua when I installed it on a machine which I don't
manage myself. It ended up that in the wmii.lua file the plugin_path variable
is generated with hard-coded directories which assume installation to "/usr/*"
or "/usr/local". This patch just generates the plugin paths based on the
package.path variable.

As a side note, it also stores each path in a table rather than as one long
string. This way they don't have to be re-split everytime a plugin is loaded.

dcurtis

unread,
Mar 5, 2009, 4:43:16 PM3/5/09
to wmii...@googlegroups.com, Donald E Curtis
From: Donald E Curtis <dcu...@l-lnx107.divms.uiowa.edu>

---
core/wmii.lua | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/core/wmii.lua b/core/wmii.lua
index ef5bb1d..a295f0e 100644
--- a/core/wmii.lua
+++ b/core/wmii.lua
@@ -143,12 +143,24 @@ local prog_hist = history.new (20)
local action_hist = history.new(10)

-- where to find plugins
-plugin_path = os.getenv("HOME") .. "/.wmii-lua/plugins/?.so;"
- .. os.getenv("HOME") .. "/.wmii-lua/plugins/?.lua;"
- .. "/usr/local/lib/lua/5.1/wmii/?.so;"
- .. "/usr/local/share/lua/5.1/wmii/?.lua;"
- .. "/usr/lib/lua/5.1/wmii/?.so;"
- .. "/usr/share/lua/5.1/wmii/?.lua"
+plugin_paths = {}
+
+table.insert(plugin_paths, os.getenv("HOME") .. "/.wmii-lua/plugins/?.so")
+table.insert(plugin_paths, os.getenv("HOME") .. "/.wmii-lua/plugins/?.lua")
+
+for path in string.gmatch(package.path, "[^;]+") do
+ if not path:find("^./") and not path:find("core") and not path:find("plugins") then
+ local path = path:gsub("%?", "wmii/?")
+ table.insert(plugin_paths, path)
+ end
+end
+
+for path in string.gmatch(package.cpath, "[^;]+") do
+ if not path:find("^./") and not path:find("core") and not path:find("plugins") and not path:find("loadall.so") then
+ local path = path:gsub("%?", "wmii/?")
+ table.insert(plugin_paths, path)
+ end
+end

-- where to find wmiirc (see find_wmiirc())
wmiirc_path = os.getenv("HOME") .. "/.wmii-lua/wmiirc.lua;"
@@ -1681,7 +1693,7 @@ function load_plugin(name, vars)

-- first find the plugin file
local s, path_match, full_name, file
- for s in string.gmatch(plugin_path, "[^;]+") do
+ for i,s in pairs(plugin_paths) do
-- try to locate the files locally
local fn = s:gsub("%?", name)
file = io.open(fn, "r")
--
1.5.5.1

Bart Trojanowski

unread,
Mar 17, 2009, 10:12:23 PM3/17/09
to wmii...@googlegroups.com, Donald E Curtis
* dcurtis <dcu...@cs.uiowa.edu> [090305 15:43]:

> I had a problem using wmiirc-lua when I installed it on a machine which I don't
> manage myself. It ended up that in the wmii.lua file the plugin_path variable
> is generated with hard-coded directories which assume installation to "/usr/*"
> or "/usr/local". This patch just generates the plugin paths based on the
> package.path variable.

Do you use 'make install-user' ?

Since it installs everything in $HOME_WMII (.wmii-3.5, or now .wmii-lua)
I don't see how that would fail.

However, I do like the change since it's more future proof wrt the
version of the lua installed. Hard coding is inherently bad, thanks for
fixing the code.

> As a side note, it also stores each path in a table rather than as one long
> string. This way they don't have to be re-split everytime a plugin is loaded.

That's great -- I like it. Since you're on a roll, could you check if
you can share this path with the wmiirc ?

Maybe instead of:

> +plugin_paths = {}

do something like this before the module() line:

local plugin_paths = plugin_paths

and then after it do:

plugin_paths = plugin_paths ? plugin_paths : {}

Next...

> +for path in string.gmatch(package.path, "[^;]+") do
> + if not path:find("^./") and not path:find("core") and not path:find("plugins") then

It's not outside the realm of possibility to have 'core' or 'plugins' in
the path name leading up to the lua library location.

Maybe the check could be for the presence of a wmii directory in the
filesystem since that's what you're adding to the plugin_paths, how
about:

for path in string.gmatch(package.path, "[^;]+") do

local wmiidir = path:gsub("%?.*$", "wmii")
local stat = posix.stat(wmiidir)
if stat and stat.type == "directory" then


local path = path:gsub("%?", "wmii/?")

table.insert(plugin_paths, path)
end
end

The above is untested, but should be close to something workable :)

Cheers,

-Bart

--
WebSig: http://www.jukie.net/~bart/sig/

Reply all
Reply to author
Forward
0 new messages