* Preserve the environment table so that it must only be regenerated after a game restart, after a computer is restarted, and at the tiem of the initialization of a computer. * Replace the current meta-based userdata mechanisms with a global `ram` variable within the environment, as the preservation of the environment itself causes its global variables to be preserved as well * Make `get_attr` convert meta to a table before accessing the requested key in order to ensure that the meta can be correctly accessed even if it is not a string * Initialize output_editable meta on node place
54 lines
1.4 KiB
Lua
54 lines
1.4 KiB
Lua
-- cmd: help --
|
|
|
|
local params = ...
|
|
local param = params[1]
|
|
local bin = ram.bin
|
|
|
|
--[local function] Sort the help list alphabetically
|
|
local function sort(list)
|
|
-- Order map
|
|
local map = {["0"] = 1, ["1"] = 2, ["2"] = 3, ["3"] = 4, ["4"] = 5, ["5"] = 6, ["6"] = 7,
|
|
["7"] = 8, ["8"] = 9, ["9"] = 10, a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17,
|
|
h = 18, i = 19, j = 20, k = 21, l = 22, m = 23, n = 24, o = 25, p = 26, q = 27, r = 28,
|
|
s = 29, t = 30, u = 31, v = 32, w = 33, x = 34, y = 35, z = 36}
|
|
|
|
local keys = {}
|
|
for k in pairs(list) do keys[#keys + 1] = k end
|
|
|
|
-- Detect sort order and sort using custom comparison functions
|
|
table.sort(keys, function(a, b) return map[a:sub(1, 1):lower()] < map[b:sub(1, 1):lower()] end)
|
|
|
|
-- Return iterator function
|
|
local i = 0
|
|
return function()
|
|
i = i + 1
|
|
if keys[i] then
|
|
return keys[i], list[keys[i]]
|
|
end
|
|
end
|
|
end
|
|
|
|
-- [local function] Print help
|
|
local function print_h(name, info)
|
|
local cparams = ""
|
|
if info.params then
|
|
cparams = " "..info.params
|
|
end
|
|
|
|
print(name..cparams..": "..info.description)
|
|
end
|
|
|
|
if param == "all" then
|
|
for name, info in sort(bin) do
|
|
print_h(name, info)
|
|
end
|
|
elseif not param or param == "" then
|
|
print("Specify a command to get help for or use help all to view help for all commands.")
|
|
else
|
|
if bin[param] then
|
|
print_h(param, bin[param])
|
|
else
|
|
print(param..": command not found")
|
|
end
|
|
end
|