inventory script, modules
This commit is contained in:
+10
-63
@@ -53,6 +53,16 @@ function load_script(path, nocache)
|
||||
return result
|
||||
end
|
||||
|
||||
function require(path)
|
||||
local prefix, file = parse_path(path)
|
||||
return load_script(prefix..":modules/"..file..".lua")
|
||||
end
|
||||
|
||||
function __reset_scripts_cache()
|
||||
__cached_scripts = {}
|
||||
__cached_results = {}
|
||||
end
|
||||
|
||||
function sleep(timesec)
|
||||
local start = time.uptime()
|
||||
while time.uptime() - start < timesec do
|
||||
@@ -78,69 +88,6 @@ function dofile(path)
|
||||
return _dofile(path)
|
||||
end
|
||||
|
||||
toml = {}
|
||||
|
||||
-- Convert table to TOML
|
||||
function toml.from_table(tb, isinner)
|
||||
local text = ""
|
||||
for k, v in pairs(tb) do
|
||||
local tp = type(v)
|
||||
if tp ~= "table" then
|
||||
text = text..k.." = "
|
||||
if tp == "string" then
|
||||
text = text..string.format("%q", v)
|
||||
else
|
||||
text = text..tostring(v)
|
||||
end
|
||||
text = text.."\n"
|
||||
end
|
||||
end
|
||||
for k, v in pairs(tb) do
|
||||
local tp = type(v)
|
||||
if tp == "table" then
|
||||
if isinner then
|
||||
error("only one level of subtables supported")
|
||||
end
|
||||
text = text.."["..k.."]\n"..toml.from_table(v).."\n"
|
||||
end
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
-- Parse TOML to new table
|
||||
function toml.parse(s)
|
||||
local output = {}
|
||||
local current = output
|
||||
local lines = {}
|
||||
for line in string.gmatch(s, "[^\r\n]+") do
|
||||
line = string.gsub(line, "%s+", "")
|
||||
table.insert(lines, line)
|
||||
end
|
||||
for i = 1,#lines do
|
||||
local s = lines[i]
|
||||
if string.sub(s, 1, 1) == "[" then
|
||||
local section = s.sub(s, 2, #s-1)
|
||||
current = {}
|
||||
output[section] = current
|
||||
else
|
||||
for k, v in string.gmatch(s, "(%w+)=(.+)" ) do
|
||||
v = string.gsub(v, "%s+", "")
|
||||
if v.sub(v, 1, 1) == "\"" then
|
||||
current[k] = v.sub(v, 2, #v-1)
|
||||
elseif v == "true" or v == "false" then
|
||||
current[k] = v == "true"
|
||||
end
|
||||
|
||||
local num = tonumber(v)
|
||||
if num ~= nil then
|
||||
current[k] = num
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
function pack.is_installed(packid)
|
||||
return file.isfile(packid..":package.json")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user