使用TABLE.reIndex整理代码

This commit is contained in:
MrZ626
2021-03-08 10:51:03 +08:00
parent 22b4924b63
commit f9b2929a64
2 changed files with 19 additions and 50 deletions

View File

@@ -15,7 +15,8 @@ local function log(str)
end end
--Environment for user's function --Environment for user's function
local userEnv={ local userG={
_VERSION=VERSION_CODE,
assert=assert,error=error, assert=assert,error=error,
tonumber=tonumber,tostring=tostring, tonumber=tonumber,tostring=tostring,
select=select,next=next, select=select,next=next,
@@ -32,19 +33,19 @@ local userEnv={
table={}, table={},
string={}, string={},
coroutine={}, coroutine={},
bit32={}, bit={},
debug={"No way."}, debug={"No way."},
package={"No way."}, package={"No way."},
io={"No way."}, io={"No way."},
os={"No way."}, os={"No way."},
_VERSION=VERSION_CODE, }userG._G=userG
}userEnv._G=userEnv TABLE.complete(math, userG.math)
TABLE.complete(math, userEnv.math) TABLE.complete(string, userG.string)
TABLE.complete(table, userEnv.table) userG.string.dump=nil
TABLE.complete(string, userEnv.string) TABLE.complete(table, userG.table)
TABLE.complete(coroutine, userEnv.coroutine) TABLE.complete(bit, userG.bit)
TABLE.complete(bit, userEnv.bit) TABLE.complete(coroutine, userG.coroutine)
--Puzzle box --Puzzle box
local first_key={} local first_key={}
local fleg={ local fleg={
@@ -63,8 +64,8 @@ local function first_box(k,f)
log"You lose." log"You lose."
return fleg return fleg
end end
userEnv.the_key=first_key userG.the_key=first_key
userEnv.the_box=first_box userG.the_box=first_box
@@ -93,19 +94,7 @@ do--commands.help(arg)
"help [command_name]", "help [command_name]",
}, },
}, },
["?"]={ ["?"]="help",
description="Display help messages.",
details={
"Display help messages.",
"",
"Aliases: help ?",
"",
"Usage:",
"help",
"help [page]",
"help [command_name]",
},
},
["#"]={ ["#"]={
description="Run arbitrary Lua code.", description="Run arbitrary Lua code.",
details={ details={
@@ -129,28 +118,8 @@ do--commands.help(arg)
"exit", "exit",
}, },
}, },
quit={ quit="exit",
description="Return to the previous menu.", bye="exit",
details={
"Return to the previous menu.",
"",
"Aliases: exit quit bye",
"",
"Usage:",
"exit",
},
},
bye={
description="Return to the previous menu.",
details={
"Return to the previous menu.",
"",
"Aliases: exit quit bye",
"",
"Usage:",
"exit",
},
},
echo={ echo={
description="Print a message to this window.", description="Print a message to this window.",
details={ details={
@@ -257,7 +226,7 @@ do--commands.help(arg)
"classic|xmas|sprfes|zday", "classic|xmas|sprfes|zday",
}, },
}, },
} }TABLE.reIndex(command_help_messages)
-- while I could have used a for loop to get this... the order at which the -- while I could have used a for loop to get this... the order at which the
-- table elements turn up in the loop is not quite ideal. Doing this manually -- table elements turn up in the loop is not quite ideal. Doing this manually
@@ -422,7 +391,7 @@ function scene.keyDown(k)
--Execute code --Execute code
local code,err=loadstring(input:sub(2)) local code,err=loadstring(input:sub(2))
if code then if code then
setfenv(code,userEnv) setfenv(code,userG)
code,err=pcall(code) code,err=pcall(code)
if not code then if not code then
log("[ERR] "..err) log("[ERR] "..err)

View File

@@ -55,7 +55,7 @@ local eggInput={
drp=goScene"app_dropper", drp=goScene"app_dropper",
calc=goScene"app_calc", calc=goScene"app_calc",
cmd=goScene"app_cmd", cmd=goScene"app_cmd",
}for k,v in next,eggInput do if type(v)=="string"then eggInput[k]=eggInput[v]end end }TABLE.reIndex(eggInput)
local function search() local function search()
local input=inputBox.value local input=inputBox.value
if eggInput[input]then if eggInput[input]then