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

Class Constructors

Started by
11 comments, last by WitchLord 19 years, 2 months ago
Great! It works! Thank you.
Advertisement
Quote: Original post by WitchLord
There are times when AngelScript needs to be able to create a default object (implicitly) without copying another. When passing an object to a parameter marked as &out, is one such situation. Thus AngelScript will not work correctly if the default constructor isn't registered.

Of course, I could have the compiler make an error in this case, and it might even be the best thing to do. But then the application will have to register a default constructor for all objects it registers (unless it really shouldn't have one).

If the object type is registered with a size of zero, then the script cannot use any constructor to declare the object locally. It could be used to prevent the use of the default constructor, but then it would have to be manipulated through handles, and factory functions would be needed to create the objects and return their handles.


I see where you're coming from.. forcing such a rule would solve the problem but at the cost of more ground work by the developers. The alternative would be to have default behaviour, such as bitwise copy for objects that have no assignment and copy constructors registered. So what's the current default behaviour for contructing objects with no default constructor.. is the allocated memory cleared to zeroes?
tIDE Tile Map Editorhttp://tide.codeplex.com
The default constructor doesn't do anything.

The default copy/assignment operator does a bitwise copy of the memory.

Maybe it is just safer to force the application writer to register all methods, and if not registered have the compiler emit an error. It would certainly be safer like that, although would require a little more work from the application writer.

I think I'll do it like this: When calling RegisterObjectType() a new parameter will tell AngelScript it can use a default behaviours, if they are not registered. This will give the application writer better options as to how the type will work.

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