prepare for luacompat, don't leak variables to the user environment

This commit is contained in:
pedro 2005-04-19 14:31:27 +00:00
parent 84e36e6362
commit 4b5c32f20d
3 changed files with 38 additions and 8 deletions

View File

@ -1,3 +1,3 @@
-- $OpenBSD: init.lua,v 1.1.1.1 2004/12/16 21:21:14 pedro Exp $
-- $OpenBSD: init.lua,v 1.2 2005/04/19 14:31:27 pedro Exp $
-- luaposix's initialization steps
LUA_PATH = lua_addpath(LUA_PATH, "@posixpath@")
lua_addpath("@posixpath@")

View File

@ -1,11 +1,36 @@
-- $OpenBSD: init.lua,v 1.1 2004/12/16 13:04:07 pedro Exp $
-- $OpenBSD: init.lua,v 1.2 2005/04/19 14:31:27 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)
-- add an entry to a path list
local function
addpath(path, entry)
return (path or "") .. ((path and ";") or "") .. entry
end
-- add an entry to the lua path
function
lua_addpath(entry)
if package then
-- if we are using luacompat, add the entry to package.path
package.path = addpath(package.path, entry)
else
-- otherwise, add it to the normal 'lua_path'
LUA_PATH = addpath(LUA_PATH, entry)
end
end
-- add an entry to the lua c path
function
lua_addcpath(entry)
if package then
-- if we are using luacompat, add the entry to package.cpath
package.cpath = addpath(package.cpath, entry)
else
-- otherwise, add it to the normal 'lua_cpath'
LUA_CPATH = addpath(LUA_CPATH, entry)
end
end
-- get the package table
f = assert(loadfile("@pkgconf@"))
setfenv(f, {}) f() pt = getfenv(f).installed_packages
@ -21,5 +46,10 @@ 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
f = nil
LUA_PATH = lua_addpath(LUA_PATH, "?;?.lua") -- set the default path
lua_addpath("?;?.lua") -- set the default path
-- nuke exported functions
lua_addpath = nil
lua_addcpath = nil

View File

@ -1,4 +1,4 @@
-- $OpenBSD: init.lua,v 1.1.1.1 2004/12/16 13:38:12 pedro Exp $
-- $OpenBSD: init.lua,v 1.2 2005/04/19 14:31:27 pedro Exp $
-- luasocket's initialization steps
LUA_PATH = lua_addpath(LUA_PATH, "@socketpath@")
lua_addpath("@socketpath@")
require("lua")