[Solved] Serializing HUMP.Vector with bitser
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 6
- Joined: Sat Sep 17, 2016 9:50 am
[Solved] Serializing HUMP.Vector with bitser
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.
Re: Serializing HUMP.Vector with bitser
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:
(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)
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
-
- Prole
- Posts: 6
- Joined: Sat Sep 17, 2016 9:50 am
Re: Serializing HUMP.Vector with bitser
Thank you for your answer. I tried SECL deserializer and "__index" as a classkey, but it still doesn’t work.
Re: Serializing HUMP.Vector with bitser
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.
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Serializing HUMP.Vector with bitser
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):
Where 'vector' is your vector constructor, so if you use a different name, update that line too.
Code: Select all
bitser.registerClass("hump.vector", getmetatable(vector()), nil, setmetatable)
-
- Prole
- Posts: 6
- Joined: Sat Sep 17, 2016 9:50 am
Re: Serializing HUMP.Vector with bitser
It works! Thanks a lot, bartbes!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests