I've been trying some things, but I noticed I still have one ownership problem:
That of the asIscriptFunction object.
If I only weak-ref the OBJECT, the "binding" of a script function bound for this object will still exist in the application even when the delegate goes out of scope in script.
With the delegate out of scope, the scripter might assume that this binding is now broken.
The same problem occurs when the user passes a simpel global function callback. In this case, I have no object to ref, and only the function to hold.
Again, reffing the function object would move control over the callback from scripter to application, adding the necessity for some other application interface to break the callback binding. Not reffing the object would cause me to call it when the function object is already gone, which I assume, is a bad thing.
This can ofcourse be prevented if I can weak-ref the asIScriptFunction as well (but this is currently not possible is it?, The CScriptWeakRef needs an object type?). As a matter of fact, if I could just weak-ref the asIScriptFunction, I don't need to destinguish between an object delegate or a normal callback, since if the delegate object is destroyed, the object ref will be freed as expected, and the func ref will be as well, and the object will not be destroyed as long as the delegate exists, since it refs it.
Couldn't the script delegate weak-ref the object and fallback to a no-op if the object is destroyed before the delegate is called?
In that case, the control of both the lifetime of the object, and the lifetime of the delegate remain in the hands of the scripter, that is, if the application can weakref the asIScriptFunction*
I've read different posts about the subject and understand this is a difficult problem However I can explain a scripter that the delegate will ref the object for as long as it exists, but it is kind of strange that a script callback or delegate stops existing when the object funcdef object goes out of scope, but not when a global function callback is passed to the application (only when it's a delegate).
Any thoughts on this?