Advertisement

Config groups and object property accessors

Started by December 27, 2012 02:24 PM
3 comments, last by zppz 11 years, 10 months ago

After creating an object type with RegisterObjectType, I want to let the users of my program dynamically add and remove properties for the object type, and also let them access the properties with the convenient .xxx style of coding.

So I use RegisterObjectMethod to create the necessary get_xxx and set_xxx functions, and everything works great. To make this easily reversible later, I enclose it in a BeginConfigGroup/EndConfigGroup.

The trouble is, using RemoveConfigGroup after this does not seem to remove these object methods. No errors or other problems occur, but the get_xxx/set_xxx functions remain as if they had not been removed, and can happily be used still.

The same RegisterObjectMethod procedure can then be repeated, also with no errors, but this seems to cause a duplicate of the functions to be registered, so that scripts fail to compile with the message "Found multiple get accessors for property 'xxx'"

Just wondering if this is the expected behavior. And if so, is there a better way to do what I'm trying to do... thanks!

It's currently not possible to register only part of an object type in a separate configuration group. Methods, properties, and behaviours will be placed in the same group that was used when RegisterObjectType() was called. To do what you want you need to put the full object type in the configuration group, and then re-register it as a whole when exchanging the properties.

Unfortunately this is not clear in the manual. I'll have to update the manual to make this clear.

I'll also add to my to-do list to investigate the possibility to add the support for registering parts of types in different modules.

When registering methods AngelScript checks for duplicates. The problem here is that you're registering the virtual property with a different type, so it will be seen as a method overload rather than a duplicate method. The get_ method should have given an error though, as it is not possible to overload a method with just a difference in the return type.

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

Advertisement

Thanks Andreas.

After a while I came to realize that I need separate script engines. Many object types refer to each other so they need to be in the same config group, which cascaded into basically replacing everything anyway. Another reason is that I want to keep these property settings separate for different documents in the workspace, even when the object type names are the same. For example the user could have two documents open, and in one of them the 'body' class could be given a 'xxx' property, without giving that property to the 'body' class in the other document.

Plus, coding-wise it was somewhat easier and less error-prone to simply drop everything and create it afresh. Luckily I don't need to keep any persistent state (global variables etc) in the script engine itself, so I could do this :)

Keep up the good work!

Have you looked in to access masks?

With these you'll be able to use a single engine instance and expose different interfaces to different scripts. I'm not sure this is exactly what you're trying to do, but if you haven't seen this feature yet, it may be worth looking in to.

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

I did notice the access mask feature, but I did not look into them much because using separate engines worked ok and did not require any managing of masks for each document that the user might open.

This topic is closed to new replies.

Advertisement