This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sebra's profile picture

[1.41] texutils API bug

Started by Sebra, 19 August 2012 - 03:21 PM
Sebra #1
Posted 19 August 2012 - 05:21 PM
line 154 of texutils API should be
error( "Cannot serialize type "..sType )
instead of
local sType = type(t)
-- ... --
error( "Cannot serialize type "..t )
because it gives out wrong error.

Also can anyone explain why environment cleared in the process of unserialization?

function unserialize( s )
local func, e = loadstring( "return "..s, "serialize" )
  if not func then
	return s
  else
     setfenv( func, {} )
	return func()
  end
end
Graypup #2
Posted 19 August 2012 - 06:18 PM
The env is being changed because it needs to make unserialize return properly, probably… I'm tired of looking at the ref. manual. Find out what the call does: http://www.lua.org/manual/5.1/manual.html#pdf-setfenv
The type(sType) call is perfectly logical, because ofc, it can't serialize a function, nor print it, either.
Sebra #3
Posted 20 August 2012 - 04:38 PM
Doubt it needed to work properly. It looks like some protection.

Try to serialize function. It will give you wrong error about concatenating string and function.
Also it is possible to serialize function. This API just refuse to do it. I did it succesfully with proper binary input/output. Can Dan200 do it right?
Cloudy #4
Posted 24 August 2012 - 10:35 AM
It isn't designed to serialise functions. If you want to do that there's nothing stopping you doing that yourself.
Sebra #5
Posted 24 August 2012 - 10:48 AM
It was designed to give message it cannot serialize functions. But it give message "Cannot concatenate string and function". That is a BUG!.
It's easy to add serialization of function but bad binary file IO hinder it (is it right word?).
Environment clearing prevent me from adding vector (and other known "classes") serialization to this API. Why it was added? Is it really needed?
Cloudy #6
Posted 24 August 2012 - 07:08 PM
It was designed to give message it cannot serialize functions. But it give message "Cannot concatenate string and function". That is a BUG!.
It's easy to add serialization of function but bad binary file IO hinder it (is it right word?).
Environment clearing prevent me from adding vector (and other known "classes") serialization to this API. Why it was added? Is it really needed?

It was added to serialise most normal Lua types. If you don't like it, use your own solution. I'll fix the small bug (although in reality it will just replace one error with another, but whatever :D/>/>)
FuzzyPurp #7
Posted 01 September 2012 - 04:31 PM
You can try immibis's Proper Serialization here on the forums.
Sebra #8
Posted 15 September 2012 - 09:44 AM
It was added to serialise most normal Lua types. If you don't like it, use your own solution. I'll fix the small bug (although in reality it will just replace one error with another, but whatever :)/>/>)
Thanks for fixing. I want standard utils to be bug-free.
Question about environment clearing still not answered. :D/>/>
You can try immibis's Proper Serialization here on the forums.
I can but standard serialization results can be read by eyes too :P/>/>