diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:15:34 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:15:34 -0500 |
| commit | e379656333caefe28914c6bc0cdfe9a80b1ecd0e (patch) | |
| tree | dbc8ebef215d90b4d6285530a31dc1bd4ae0f15f /.mbs/bin/lua.lua | |
| parent | a405ec93546b95c2369ec9069b3616944d785198 (diff) | |
| download | bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.tar.gz bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.tar.bz2 bits-UI-e379656333caefe28914c6bc0cdfe9a80b1ecd0e.zip | |
Updated MBS
Diffstat (limited to '.mbs/bin/lua.lua')
| -rw-r--r-- | .mbs/bin/lua.lua | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/.mbs/bin/lua.lua b/.mbs/bin/lua.lua index eed7aa9..cdbdbed 100644 --- a/.mbs/bin/lua.lua +++ b/.mbs/bin/lua.lua @@ -263,7 +263,7 @@ local function pretty(t, n) local width, height = term.getSize() local fit_height = settings.get("mbs.lua.pretty_height", true) if type(fit_height) == "number" then height = fit_height - elseif fit_height == false then height = 1/0 end + elseif fit_height == false then height = 1 / 0 end return pretty_impl(t, {}, width, height - 2, "", n) end @@ -272,6 +272,7 @@ local history = {} local counter = 1 local output = {} + local environment = setmetatable({ exit = setmetatable({}, { __tostring = function() return "Call exit() to exit" end, @@ -283,6 +284,42 @@ local environment = setmetatable({ out = output, }, { __index = _ENV }) + +local function process_auto_run_file(folderPath, file) + if string.sub( file, 1, 1 ) == "." then return end + + local path = fs.combine(folderPath, file) + if fs.isDir( path ) then return end + + local func, err = loadfile(path, nil, _ENV) + if not func then + printError(err) + return + end + + local ok, result + if settings.get("mbs.lua.traceback", true) then + ok, result = stack_trace.xpcall_with(func) + else + ok, result = pcall(func) + end + if not ok then + printError(result) + end +end + +local function load_auto_run_folder(folderPath) + if fs.exists( folderPath ) and fs.isDir( folderPath ) then + local files = fs.list( folderPath ) + for _, file in ipairs( files ) do + process_auto_run_file(folderPath, file) + end + end +end + +load_auto_run_folder("/rom/lua_autorun") +load_auto_run_folder("/lua_autorun") + local autocomplete = nil if not settings or settings.get("lua.autocomplete") then autocomplete = function(line) |
