🎉 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!

Application defined structs

Started by
1 comment, last by Rain Dog 18 years, 11 months ago
I've always wondered: Do structs need to have asBEHAVE_CONSTRUCT and asBEHAVE_DESTRUCT registered for structures in order for them to be declared in script? Also, what about references? do they need addref/release behaviours also?
Advertisement
If a type is registered without the asBEHAVE_CONSTRUCT, the script engine will allocate the memory, but will not initialize it. Thus, any pointers, complex members, or the virtual function table, will be invalid. If the C++ type doesn't contain any of these, then asBEHAVE_CONSTRUCT is not necessary.

Likewise, if asBEHAVE_DESTRUCT is not registered then the destructor will never be called by the script engine. It will still free the memory, but any pointers or complex members in the structure will not be properlies treated. If the asBEHAVE_RELEASE behaviour is registered, then the memory will be freed by that behaviour, thus the library will never call any registered destructor.

Any type that do not register the asBEHAVE_ADDREF/asBEHAVE_RELEASE behaviours can still be used by the script engine, but the types won't allow object handles to be used.

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

Ok, thanks, that clears things up for me now.

This topic is closed to new replies.

Advertisement