[Solved] Serializing HUMP.Vector with bitser

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

[Solved] Serializing HUMP.Vector with bitser

Post by bloodcraft »

Hi. I wonder what is the correct way to serialize HUMP Vectors using bitser. How should I use bitser.register or bitser.registerClass in this particular case? Currently I am getting errors when I try to do arithmetic with deserialized vectors. It seems that they forgot their metamethods. Can anyone help me? Thanks.
Last edited by bloodcraft on Sat Jul 08, 2017 11:02 am, edited 1 time in total.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Serializing HUMP.Vector with bitser

Post by erasio »

bitser supports a variety of class libraries or plain values.

hump.vector is neither. It's a standalone thing with it's own new() function to create new instances and a standard setmetatable. No class implementation used.

Serialization should work fine but when deserializing it recognizes this is a class but it doesn't find a deserializer from its internal implementation.

You can provide one when using "registerClass". That functions takes the following parameters:

* name
* class
* classkey
* deserializer

I haven't tried it but you might be able to use the same deserializer as is used for SECL:

Code: Select all

local function deserialize_SECL(instance, class)
	return setmetatable(instance, getmetatable(class))
end
(You just need to provide it manually since this implementation doesn't have an index it's searching for in an attempt to recognize SECL)
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

Re: Serializing HUMP.Vector with bitser

Post by bloodcraft »

Thank you for your answer. I tried SECL deserializer and "__index" as a classkey, but it still doesn’t work.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Serializing HUMP.Vector with bitser

Post by erasio »

Classkey is something different. You try to recreate your object. Aka deserialize. As I mentioned in my first comment you need to provide a deserializer.

Also the specific one you need to provide is a guess on my part. You might need something different.

I would suggest looking at the actual implementation and do some more precise debugging as to what exactly isn't working so you can look at why.
If you do not understand the module implementation and can't get it running maybe look for another one or write your own.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Serializing HUMP.Vector with bitser

Post by bartbes »

I did some testing, and the solution turns out to be fairly simple. Just call the following code at the start (or at least before attempting to serialise or deserialise):

Code: Select all

bitser.registerClass("hump.vector", getmetatable(vector()), nil, setmetatable)
Where 'vector' is your vector constructor, so if you use a different name, update that line too.
bloodcraft
Prole
Posts: 6
Joined: Sat Sep 17, 2016 9:50 am

Re: Serializing HUMP.Vector with bitser

Post by bloodcraft »

It works! Thanks a lot, bartbes!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests