From f9b2929a64144bc106ff0e0a68ef9f34a2a1e763 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 8 Mar 2021 10:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8TABLE.reIndex=E6=95=B4?= =?UTF-8?q?=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/app_cmd.lua | 67 +++++++++++----------------------------- parts/scenes/dict.lua | 2 +- 2 files changed, 19 insertions(+), 50 deletions(-) diff --git a/parts/scenes/app_cmd.lua b/parts/scenes/app_cmd.lua index 483de2f2..b3a04ce6 100644 --- a/parts/scenes/app_cmd.lua +++ b/parts/scenes/app_cmd.lua @@ -15,7 +15,8 @@ local function log(str) end --Environment for user's function -local userEnv={ +local userG={ + _VERSION=VERSION_CODE, assert=assert,error=error, tonumber=tonumber,tostring=tostring, select=select,next=next, @@ -32,19 +33,19 @@ local userEnv={ table={}, string={}, coroutine={}, - bit32={}, + bit={}, + debug={"No way."}, package={"No way."}, io={"No way."}, os={"No way."}, - _VERSION=VERSION_CODE, -}userEnv._G=userEnv -TABLE.complete(math, userEnv.math) -TABLE.complete(table, userEnv.table) -TABLE.complete(string, userEnv.string) -TABLE.complete(coroutine, userEnv.coroutine) -TABLE.complete(bit, userEnv.bit) - +}userG._G=userG +TABLE.complete(math, userG.math) +TABLE.complete(string, userG.string) +userG.string.dump=nil +TABLE.complete(table, userG.table) +TABLE.complete(bit, userG.bit) +TABLE.complete(coroutine, userG.coroutine) --Puzzle box local first_key={} local fleg={ @@ -63,8 +64,8 @@ local function first_box(k,f) log"You lose." return fleg end -userEnv.the_key=first_key -userEnv.the_box=first_box +userG.the_key=first_key +userG.the_box=first_box @@ -93,19 +94,7 @@ do--commands.help(arg) "help [command_name]", }, }, - ["?"]={ - description="Display help messages.", - details={ - "Display help messages.", - "", - "Aliases: help ?", - "", - "Usage:", - "help", - "help [page]", - "help [command_name]", - }, - }, + ["?"]="help", ["#"]={ description="Run arbitrary Lua code.", details={ @@ -129,28 +118,8 @@ do--commands.help(arg) "exit", }, }, - quit={ - description="Return to the previous menu.", - 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", - }, - }, + quit="exit", + bye="exit", echo={ description="Print a message to this window.", details={ @@ -257,7 +226,7 @@ do--commands.help(arg) "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 -- table elements turn up in the loop is not quite ideal. Doing this manually @@ -422,7 +391,7 @@ function scene.keyDown(k) --Execute code local code,err=loadstring(input:sub(2)) if code then - setfenv(code,userEnv) + setfenv(code,userG) code,err=pcall(code) if not code then log("[ERR] "..err) diff --git a/parts/scenes/dict.lua b/parts/scenes/dict.lua index ceb82846..17478d29 100644 --- a/parts/scenes/dict.lua +++ b/parts/scenes/dict.lua @@ -55,7 +55,7 @@ local eggInput={ drp=goScene"app_dropper", calc=goScene"app_calc", 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 input=inputBox.value if eggInput[input]then