From e8ea34fa314e247714ff4c811b92f7276d05574e Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 7 Jun 2024 23:14:16 +0300 Subject: [PATCH] add console.log(...) --- res/layouts/console.xml.lua | 7 +------ res/scripts/stdlib.lua | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index 31314ca5..f71920ce 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -38,12 +38,7 @@ function submit(text) document.log.caret = -1 local status, result = pcall(function() return console.execute(text) end) if result ~= nil then - local prevtext = document.log.text - if #prevtext == 0 then - document.log:paste(tostring(result)) - else - document.log:paste('\n'..tostring(result)) - end + console.log(result) end document.prompt.text = "" document.prompt.focused = true diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 877d38a4..1873dd3e 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -203,6 +203,24 @@ function time.post_runnable(runnable) table.insert(__post_runnables, runnable) end +local log_element = Document.new("core:console").log +function console.log(...) + local args = {...} + local text = '' + for i,v in ipairs(args) do + if i ~= 1 then + text = text..' '..v + else + text = text..v + end + end + log_element.caret = -1 + if log_element.caret > 0 then + text = '\n'..text + end + log_element:paste(text) +end + function gui.template(name, params) local text = file.read(file.find("layouts/templates/"..name..".xml")) for k,v in pairs(params) do