Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Delegates in AngelScript


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
26 replies to this topic

#21 Andreas Jonsson   Moderators   -  Reputation: 3442

Like
0Likes
Like

Posted 19 January 2013 - 01:28 PM

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.


Edited by Andreas Jonsson, 19 January 2013 - 01:52 PM.

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

Sponsor:

#22 Jake Albano   Members   -  Reputation: 649

Like
0Likes
Like

Posted 19 January 2013 - 01:48 PM

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

 

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



#23 Andreas Jonsson   Moderators   -  Reputation: 3442

Like
0Likes
Like

Posted 19 January 2013 - 01:51 PM

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

#24 vroad   Members   -  Reputation: 131

Like
0Likes
Like

Posted 26 March 2013 - 09:19 AM

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



#25 Andreas Jonsson   Moderators   -  Reputation: 3442

Like
0Likes
Like

Posted 26 March 2013 - 04:32 PM

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

#26 vroad   Members   -  Reputation: 131

Like
0Likes
Like

Posted 27 March 2013 - 08:47 AM

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/



#27 Andreas Jonsson   Moderators   -  Reputation: 3442

Like
1Likes
Like

Posted 14 July 2013 - 03:37 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS