openbsd-ports/lang/lua/files/init.lua
pedro e18b21c32d introduce a simple package management facility for lua, by permitting
each package to have an initialization file, and keeping a table of
'<package> = <file>' entries in a known place. these files are loaded
upon lua's activation, and should normally be small, quick pieces of
code responsible for preparing the environment (luapath, cpath) for
the packages they represent.

also, make it possible for every user to have her/his own lua
initialization routines under ~/.lua/init.lua, so that the system-wide
mechanism described above can be replicated to user-specific cases.

prodding, all sorts of ports tutoring and ok jolan@
2004-12-16 13:04:07 +00:00

26 lines
796 B
Lua

-- $OpenBSD: init.lua,v 1.1 2004/12/16 13:04:07 pedro Exp $
-- Written by Pedro Martelletto <pedro@openbsd.org> in 2004. Public domain.
-- adds an entry to a path list
function lua_addpath(path, entry)
return (path or "") .. ((path and ";") or "") .. entry
end
-- get the package table
f = assert(loadfile("@pkgconf@"))
setfenv(f, {}) f() pt = getfenv(f).installed_packages
-- iterate over the table, loading each package
for i, v in pt do
local f, e = loadfile(v)
if not f then
print(string.format("Failed to load package %s, %s", i, e))
else f() end -- load the package
end
-- finally, run user's initialization file, if it exists
local f = loadfile((os.getenv("HOME") or "") .. "/.lua/init.lua")
if f then f() end
LUA_PATH = lua_addpath(LUA_PATH, "?;?.lua") -- set the default path