Posted 21 May 2016 - 06:26 PM
Hey all, I am getting a weird error when trying to use textutils.unserialize(table) in my program.
I am beginning to make an OS, and to get around the screen blinking issues that come with redrawing the screen every time, I am programming in a video buffer of sorts, so that it only draws the few pixels that are actually updated (if you're curious, I have a table that holds the information for the last drawn frame, and when it goes to the render function, it checks against that frame to see if anything is different; if it is, then redraw the changed pixels).
I ran into a slight problem with the programming (things were refreshing when they shouldn't have been), and as part of that, I threw in this line of code (for debugging purposes):
The above code throws an error, "textutils:295: attempt to concatenate string and table"
If I print out frameBuffer by itself, it prints just fine, and if I test it in type() it returns string, so that shouldn't be an issue. Here's the kicker, though: if I run this code, it returns a table:
Even more shocking to me, if I change the original code to this, the error goes away:
For your ease, here is the pertinent code in textutils:
So my question is, why does it error out on only that given variable name? (For the record, that phrasing has worked everywhere else in my program.) I would be happy to provide more code if needed. Thank you for your help!
I am beginning to make an OS, and to get around the screen blinking issues that come with redrawing the screen every time, I am programming in a video buffer of sorts, so that it only draws the few pixels that are actually updated (if you're curious, I have a table that holds the information for the last drawn frame, and when it goes to the render function, it checks against that frame to see if anything is different; if it is, then redraw the changed pixels).
I ran into a slight problem with the programming (things were refreshing when they shouldn't have been), and as part of that, I threw in this line of code (for debugging purposes):
--frameBuffer is defined in _G and resolves to a string if printed or tested with type()
frameBuffer = textutils.unserialize(frameBuffer);
The above code throws an error, "textutils:295: attempt to concatenate string and table"
If I print out frameBuffer by itself, it prints just fine, and if I test it in type() it returns string, so that shouldn't be an issue. Here's the kicker, though: if I run this code, it returns a table:
--this returns a table
print(textutils.unserialize(frameBuffer));
Even more shocking to me, if I change the original code to this, the error goes away:
--original, error
--frameBuffer = textutils.unserialize(frameBuffer);
--modified, no error
tframeBuffer = textutils.unserialize(frameBuffer);
For your ease, here is the pertinent code in textutils:
--textutils 294 through 303
function unserialize( s )
local func = load( "return "..s, "unserialize", "t", {} )
if func then
local ok, result = pcall( func )
if ok then
return result
end
end
return nil
end
So my question is, why does it error out on only that given variable name? (For the record, that phrasing has worked everywhere else in my program.) I would be happy to provide more code if needed. Thank you for your help!