957 posts
Location
Web Development
Posted 25 October 2015 - 09:09 PM
So I'm remaking this code:
http://pastebin.com/9n34bACkHere's what I have so far:
http://pastebin.com/iqxsiBm4In the new version, when it sets the function's environment (when creating the coroutine), it passes a modified version of the term API that saves pixels to a buffer, so that the 'pause program' can draw over the screen, then redraw the original program's interface.
In other words, when you pause the program, it needs to know what the screen looked like when it was paused. And to do that, I've modified term.write() to add its text to a buffer, then write to the screen.
That works fine, but the program I'm testing with (my File Manager) has a call to paintutils. And for some reason, paintutils still has access to the original term functions.
I don't really want to pass a completely rewritten paintutils API (but I assume that would fix the problem, with paintutils anyway. Other APIs could have the same problem too)
Any ideas?
Edited on 25 October 2015 - 08:38 PM
3057 posts
Location
United States of America
Posted 25 October 2015 - 09:35 PM
I'm not seeing where you modify the term API. Perhaps you could post that part?
957 posts
Location
Web Development
Posted 25 October 2015 - 09:39 PM
I'm not seeing where you modify the term API. Perhaps you could post that part?
Right, the code I had posted is the proof of concept.
Added my current code
Edited on 25 October 2015 - 08:39 PM
3057 posts
Location
United States of America
Posted 25 October 2015 - 11:01 PM
Well, the problem is paintutils still has a pointer to the old term table. If you overwrote the original term functions (after backing them up!!), you could add checks to see if the sandboxed coroutine is calling the function or not.
Ex:
local tArgs = {...}
local oldTerm = {}
for k, v in pairs( term ) do
oldTerm[ k ] = v
end
local program = coroutine.create( loadfile( tArgs[ 1 ] )
--#example of term.write
term.write = function( text )
local x,y = term.getCursorPos()
oldTerm.write(text)
if coroutine.status( program ) == "running" then --#hey, our coroutine is running now, we should record the screen!!!
for i = 1, #text do
buffer[x+i-1][y] = {textCol = term.getTextColor(), backCol = term.getBackgroundColor(), text = text:sub(i,i)}
end
end
end
957 posts
Location
Web Development
Posted 26 October 2015 - 12:18 AM
I accidentally defined 'program' after redefining 'term.write'.
Don't do that. It doesn't work.
But after correcting that, it works flawlessly, thank you :)/>
3057 posts
Location
United States of America
Posted 26 October 2015 - 12:31 AM
You're welcome, glad to hear it works ;)/> (That was the first time I've found a use for coroutine.status equaling running :D/>)
7083 posts
Location
Tasmania (AU)
Posted 26 October 2015 - 03:33 AM
You're setting yourself up for further problems by re-writing term. You'd be better off using term.current() to get the actual display object, creating a new version of that, then term.redirect()'ing to the result.
957 posts
Location
Web Development
Posted 26 October 2015 - 10:49 PM
You're setting yourself up for further problems by re-writing term. You'd be better off using term.current() to get the actual display object, creating a new version of that, then term.redirect()'ing to the result.
Well, using your method wasn't hard to set up, so I suppose I'll use that.
But what kind of problems are you referring to?
7083 posts
Location
Tasmania (AU)
Posted 27 October 2015 - 01:42 AM
Let's say someone tried to used your script through any multitasking OS - eg multishell, the one running on all advanced systems. Partway through execution, they switch tabs. Suddenly you'll be recording a different script.
957 posts
Location
Web Development
Posted 27 October 2015 - 01:51 AM
Let's say someone tried to used your script through any multitasking OS - eg multishell, the one running on all advanced systems. Partway through execution, they switch tabs. Suddenly you'll be recording a different script.
That explains one of the issues I encountered, though I didn't realize exactly what the problem was at the time ;)/>
Edited on 27 October 2015 - 12:51 AM