summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2022-01-07 16:29:37 -0600
committercheapie <no-email-for-you@example.com>2022-01-07 16:29:37 -0600
commit52ce5b622f9242264d140e88f89a883dd6c0ade5 (patch)
tree25997df8ec07e5fb6ead8d23ab3aa0da87bec39b
parente8998e0fab52ea825596a741f2650ad8e1e95d72 (diff)
downloadmesecons-52ce5b622f9242264d140e88f89a883dd6c0ade5.tar
mesecons-52ce5b622f9242264d140e88f89a883dd6c0ade5.tar.gz
mesecons-52ce5b622f9242264d140e88f89a883dd6c0ade5.tar.bz2
mesecons-52ce5b622f9242264d140e88f89a883dd6c0ade5.tar.xz
mesecons-52ce5b622f9242264d140e88f89a883dd6c0ade5.zip
Luacontroller terminal improvementsHEADmaster
* Adds a second argument to print() - if true, no line feed is prepended * Adds a clearterm() function in the Luacontroller environment to clear the terminal screen
-rw-r--r--mesecons_luacontroller/init.lua24
1 files changed, 18 insertions, 6 deletions
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua
index 4b7d43b..aab222d 100644
--- a/mesecons_luacontroller/init.lua
+++ b/mesecons_luacontroller/init.lua
@@ -276,28 +276,39 @@ end
-- Parsing and running --
-------------------------
-local function terminal_write(pos,text)
+local function terminal_write(pos,text,nolf)
local meta = minetest.get_meta(pos)
local oldtext = meta:get_string("terminal_text")
- local delim = string.len(oldtext) > 0 and "\n" or ""
+ local delim = (string.len(oldtext) > 0 and not nolf) and "\n" or ""
local newtext = string.sub(oldtext..delim..text,-100000,-1)
meta:set_string("terminal_text",newtext)
end
+local function terminal_clear(pos)
+ minetest.get_meta(pos):set_string("terminal_text","")
+end
+
local function get_safe_print(pos)
- return function (param)
+ return function (param,nolf)
local string_meta = getmetatable("")
local sandbox = string_meta.__index
string_meta.__index = string -- Leave string sandbox temporarily
+ if param == nil then param = "" end
if type(param) == "string" then
- terminal_write(pos,param)
+ terminal_write(pos,param,nolf)
else
- terminal_write(pos,dump(param))
+ terminal_write(pos,dump(param),nolf)
end
string_meta.__index = sandbox -- Restore string sandbox
end
end
+local function get_clear(pos)
+ return function()
+ terminal_clear(pos)
+ end
+end
+
local function safe_date()
return(os.date("*t",os.time()))
end
@@ -625,6 +636,7 @@ local function create_environment(pos, mem, event, itbl, send_warning)
heat = mesecon.get_heat(pos),
heat_max = mesecon.setting("overheat_max", 20),
print = get_safe_print(pos),
+ clearterm = get_clear(pos),
interrupt = get_interrupt(pos, itbl, send_warning),
digiline_send = get_digiline_send(pos, itbl, send_warning),
string = {
@@ -975,7 +987,7 @@ local function on_receive_fields(pos, form_name, fields, sender)
return
end
if fields.terminal_clear then
- meta:set_string("terminal_text","")
+ terminal_clear(pos)
update_formspec(pos)
return
end