[英]Is there a way to catch the output in lua?
我正在嘗試捕獲例如的輸出:print('Hello') 並將其存儲在變量/表中。
請讓我知道這是否可能。 如果不是感謝您的回答。
不能直接截取標准輸出,但是可以改變全局print
功能:
local outputs = {}
local function storeOutputs(...)
table.insert(outputs, {...})
end
local oldPrint = print
function print(...)
storeOutputs(...)
oldPrint(...)
end
我不確定是否有辦法處理io.write
調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.