mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Added positional parameters
This commit is contained in:
parent
6b1ddeb629
commit
c7bd5fa05e
@ -5,14 +5,19 @@ if #args < 1 then
|
||||
print(k..'='..v)
|
||||
end
|
||||
else
|
||||
local count = 1
|
||||
local count = 0
|
||||
for _, expr in ipairs(args) do
|
||||
local k, v = string.match(expr, "(.-)=(.*)")
|
||||
if v then
|
||||
os.setenv(k, v)
|
||||
else
|
||||
os.setenv(tostring(count), k)
|
||||
if count == 0 then
|
||||
for i = 1, os.getenv('#') do
|
||||
os.setenv(i, nil)
|
||||
end
|
||||
end
|
||||
count = count + 1
|
||||
os.setenv(count, expr)
|
||||
end
|
||||
end
|
||||
end
|
@ -25,7 +25,9 @@ function os.exit(code)
|
||||
end
|
||||
|
||||
function os.getenv(varname)
|
||||
if varname ~= nil then
|
||||
if varname == '#' then
|
||||
return #env
|
||||
elseif varname ~= nil then
|
||||
return env[varname]
|
||||
else
|
||||
return env
|
||||
@ -33,9 +35,14 @@ function os.getenv(varname)
|
||||
end
|
||||
|
||||
function os.setenv(varname, value)
|
||||
checkArg(1, varname, "string")
|
||||
env[varname] = value
|
||||
checkArg(1, varname, "string", "number")
|
||||
local success, val = pcall(tostring, value)
|
||||
if success then
|
||||
env[varname] = val
|
||||
return env[varname]
|
||||
else
|
||||
return nil, val
|
||||
end
|
||||
end
|
||||
|
||||
function os.remove(...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user