🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Serializing Angelscript classes

Started by
2 comments, last by WitchLord 10 years, 4 months ago

Hi!

How would I go about serializing and deserializing Angelscript classes into a human readable format (preferably XML)? I've looked at the boost:serialization library, and it seems to require that functions be written specially for serializing each class. Is it possible to automatically serialize and deserialize classes without already knowing specifically what the members of each class are? If it requires a little diving into the source code I'm down for that, but I'd like to have the most elegant solution possible.

Thanks in advance,

Will

Edit:

I've come up with an idea for how to achieve this, though it wouldn't really be serialization in the strictest sense, but close enough for what I need. I'll report back if I get something working.

Advertisement

The API provides interfaces that will let you enumerate class properties and obtain all the information you need.

Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Awesome, thank you very much!

Oh, I forgot to mention how you might go about to deserialize a script object from an XML file.

To deserialize the object you first need to create the object instance while bypassing the class constructor (so that it doesn't cause any unwanted side-effects). You can do this by calling the engine's CreateUninitializedScriptObject method. Once you've done that you use the methods from the Reflection article mentioned before to enumerate and set the value of each of the object's properties.

The biggest problem you'll face when implementing the serialization is to determine how to deal with reference to other objects, e.g. should the other object also be fully serialized, or should you just serialize a token that will let you find the same reference when deserializing? That will depend very much on the structure of your application, so it can't be answered uniquely.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement