You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
850 B
Lua

local getmetatable, setmetatable = getmetatable, setmetatable
local rawget, rawset, type = rawget, rawset, type
local getenv, setenv, unsetenv = os.getenv, os.setenv, os.unsetenv
local mt = getmetatable(os)
if not mt then
mt = {}
setmetatable(os, mt)
end
module "os"
-- metatable for os
function mt:__index(k)
if k == "environ" then
local environ = {}
-- This function needs to be written in C.
for k,v in getenvs() do
e[k] = v
end
rawset(os, "environ", environ)
end
end
-- metatable for os.environ
mt = {}
function mt:__newindex(name, value)
if type(name) ~= "string" then
error("Expected a string key", 2)
end
if value == nil then
unsetenv(name)
elseif typeof(value) == "string" then
setenv(name, value, true)
else
error("Expected a string value", 2)
end
rawset(self,name,value)
end
environ = setmetatable({}, e)