Add support for ref-counted system which uses 0 as initial ref count?
Recently I have to add scripting support for an old project,this project uses a ref-counted system which uses 0 as the initial ref count instead of 1,just like COM, this causes crash in AngelScript by the wrong ref count, could you add some support for this kind of ref-counted system?
Thanks a lot.
As far as i know, the only place where Angelscript needs to know the ref count is when using the asBEHAVE_GETREFCOUNT behavior. Simply adding 1 when returning this value should suffice, unless i'm missing something.
Solokiller is correct. Besides asBEHAVE_GETREFCOUNT AngelScript doesn't need to know the actual value of the refcount.
The only thing the application must make sure is that when it returns a handle to the script the refcount for the returned handle is accounted for, as AngelScript will release that handle afterwards when it is done with it. This can either be done manually or automatically using the auto-handles @+.
Whether your refcount starts at 0 or 1 has no importance to AngelScript, as long as you implement the release behavior accordingly, i.e. if it starts at 0, you'll want to destroy the object when the refcount becomes negative rather than when it reaches 0.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game