Advertisement

Delegates in AngelScript

Started by September 17, 2012 05:04 PM
25 comments, last by WitchLord 11 years, 4 months ago

1. Correct. Holding a pointer to the method will need to increase the reference count of the object to guarantee the object is alive when the method is actually called.

2. Yes, the delegate will hold a pointer to both the object and the method.

3. That is the dilemma. For now I will not bother with weak references, so a delegate will initially hold a hard reference to the object. The garbage collector is already capable of resolving circular references that may arise, so this shouldn't be a major problem.

The difficulty with weak references is more a design issue than the actual implementation. The weak references must be generic so the script compiler can build the code for them, but they must also not add a performance penalty where they are not used. I'm toying with several different ideas for this, but so far I'm not ready to start implementing weak references in AngelScript.

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

but so far I'm ready to start implementing weak references in AngelScript.

Was this a typo? It seems you meant not ready.

Advertisement

Indeed. Thanks for pointing it out.

I've corrected the original text.

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 tried to implement weak reference in AngelScript first.

This modification seems working, but sample crashes when I use this test addon in script.

https://gist.github.com/vroad/6f9961e5cd635b1e28c2

Thanks for the contribution. I'll review it carefully when I can and see if it is something I can commit to the svn.

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

Oops, I made some mistakes in code.

I successfully fixed some problems in weakref addon code.

I posted new revision of the patch to gist.

Is this best way to implement weak reference? I heard about the technique called "reference counted boolean" for the first time in Thiago Macieira's blog.

Continue using QPointer » Thiago Macieira's blog

http://www.macieira.org/blog/2012/07/continue-using-qpointer/

Advertisement

Hi vroad,

It took a while but I've finally reviewed your contribution carefully and I decided to include it with only a few minor adjustments to suit my own style. I've checked in the changes in revision 1666. I still have a few more changes to do, but I'm happy to say that weak references are now supported by AngelScript.

Thanks a lot for the contribution.

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

This topic is closed to new replies.

Advertisement