mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 12:17:17 -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)
|
print(k..'='..v)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local count = 1
|
local count = 0
|
||||||
for _, expr in ipairs(args) do
|
for _, expr in ipairs(args) do
|
||||||
local k, v = string.match(expr, "(.-)=(.*)")
|
local k, v = string.match(expr, "(.-)=(.*)")
|
||||||
if v then
|
if v then
|
||||||
os.setenv(k, v)
|
os.setenv(k, v)
|
||||||
else
|
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
|
count = count + 1
|
||||||
|
os.setenv(count, expr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -25,7 +25,9 @@ function os.exit(code)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function os.getenv(varname)
|
function os.getenv(varname)
|
||||||
if varname ~= nil then
|
if varname == '#' then
|
||||||
|
return #env
|
||||||
|
elseif varname ~= nil then
|
||||||
return env[varname]
|
return env[varname]
|
||||||
else
|
else
|
||||||
return env
|
return env
|
||||||
@ -33,9 +35,14 @@ function os.getenv(varname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function os.setenv(varname, value)
|
function os.setenv(varname, value)
|
||||||
checkArg(1, varname, "string")
|
checkArg(1, varname, "string", "number")
|
||||||
env[varname] = value
|
local success, val = pcall(tostring, value)
|
||||||
|
if success then
|
||||||
|
env[varname] = val
|
||||||
return env[varname]
|
return env[varname]
|
||||||
|
else
|
||||||
|
return nil, val
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function os.remove(...)
|
function os.remove(...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user