[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: strict.lua
- From: steve donovan <steve.j.donovan@...>
- Date: Fri, 30 Mar 2012 10:05:12 +0200
On Thu, Mar 29, 2012 at 9:56 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> Obviously it failed to find strict.lua, but now I have a list
> of places to put strict.lua once I download it. I decided to put it
> in /usr/local/share/lua/5.1/.
Here's a useful little script to have on your path; it copies a Lua
file to the first absolute path on the package path, providing the
simplest possible Lua module installer:
$ sudo linstall ~/lua/lua-5.1.4/etc/strict.lua
$ lua -lstrict
> print(bonzo)
stdin:1: variable 'bonzo' is not declared
(save as ~/bin/linit or some such)
#!/usr/bin/env lua
-- linstall
-- Copy a Lua file onto the Lua package path
function exists(file)
local f = io.open(file)
if not f then return false
else f:close(); return true
end
end
local filename = arg[1]
if not filename or not exists(filename) then
return print 'provide an existing Lua file!'
end
-- find the first absolute path on the Lua package path
local path
for p in package.path:gmatch('[^;]+') do
if p:match '^/' then -- absolute!
-- get the path with trailiing slash
path = p:match ('[^?]+')
break
end
end
-- get the name part of our file...
local mod = filename:match('[%w__]+%.lua$')
-- and do the copy
local res = os.execute(('cp %s %s%s'):format(filename,path,mod))
-- Lua 5.1/5.2 compatible check
if res == nil or res ~= 0 then
print 'you have to be sudo for this to work!'
end
------------------
A criticism is that it should really check that '/share/' is in the
path, since distros get picky about where you should put things
steve d.