Hey guys I was wondering how I would execute a function and then save it's outputs.
Not the return but the actual prints and writes. The drawing and clearing of terminal is not needed.
Thanks
5 replies to this topic
#1
Posted 20 January 2015 - 04:34 PM
#2
Posted 20 January 2015 - 04:53 PM
well, override print and write to save their passed arguments in a string you can later access, run the function which outputs to "capture", restore the functions and you are good to go. write for code examples
#3
Posted 20 January 2015 - 04:53 PM
As far as I know, you can't just read what is on a specific part of the screen without re-writing the "write" or "print" function.
Getting what you tell print to output should be really easy though
Getting what you tell print to output should be really easy though
local oldPrint = print
function print(...)
local tab = {...}
for i=1, #tab do
tab[i] = tostring(tab[i])
end
toReturn = table.concat(tab)
oldPrint(toReturn)
return toReturn
end
This would do what I *think* you want, but I can't exactly tell what you want to get.
Edited by civilwargeeky, 20 January 2015 - 04:54 PM.
#4
Posted 20 January 2015 - 05:05 PM
civilwargeeky, on 20 January 2015 - 04:53 PM, said:
As far as I know, you can't just read what is on a specific part of the screen without re-writing the "write" or "print" function.
oldPrint(toReturn) return toReturn
this would change the behaviour of the program, as print has it's own return values (number of linebreaks made)
I think he/she is looking for something like this:
local output = ""
--override
local oldPrint = print
print = function(...)
local args = {...}
for k,v in ipairs(args) do
local e,m = pcall(tostring, v)
if(not e) then
error(m, 2)
end
output = output..m
end
output = output.."\n"
return oldPrint(...)
end
--call
yourFunc()
--restore
print = oldPrint
--analyze
-- here you can use output, which contains the
-- text printed by yourFunc, without cursor position changes though
#5
Posted 20 January 2015 - 05:07 PM
civilwargeeky, on 20 January 2015 - 04:53 PM, said:
As far as I know, you can't just read what is on a specific part of the screen without re-writing the "write" or "print" function.
Getting what you tell print to output should be really easy though
Getting what you tell print to output should be really easy though
local oldPrint = print
function print(...)
local tab = {...}
for i=1, #tab do
tab[i] = tostring(tab[i])
end
toReturn = table.concat(tab)
oldPrint(toReturn)
return toReturn
end
This would do what I *think* you want, but I can't exactly tell what you want to get.Yep that's it thanks
InDieTasten, on 20 January 2015 - 05:05 PM, said:
civilwargeeky, on 20 January 2015 - 04:53 PM, said:
As far as I know, you can't just read what is on a specific part of the screen without re-writing the "write" or "print" function.
oldPrint(toReturn) return toReturn
this would change the behaviour of the program, as print has it's own return values (number of linebreaks made)
I think he/she is looking for something like this:
local output = ""
--override
local oldPrint = print
print = function(...)
local args = {...}
for k,v in ipairs(args) do
local e,m = pcall(tostring, v)
if(not e) then
error(m, 2)
end
output = output..m
end
output = output.."\n"
return oldPrint(...)
end
--call
yourFunc()
--restore
print = oldPrint
--analyze
-- here you can use output, which contains the
-- text printed by yourFunc, without cursor position changes though
Nice thanks
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











