Howto:Troubleshooting Nasal Callbacks: Difference between revisions

Jump to navigation Jump to search
Line 2: Line 2:
{{FGCquote
{{FGCquote
|1= Someone recently pointed out that the setlistener() / removelistener() API makes it easy to leak resources. So I wondered about making an alternate API where the return value from setlistener '''must''' be kept, or the listener is removed. I can imagine this with a helper object
|1= Someone recently pointed out that the setlistener() / removelistener() API makes it easy to leak resources. So I wondered about making an alternate API where the return value from setlistener '''must''' be kept, or the listener is removed. I can imagine this with a helper object
<syntaxhighlight lang="nasal">
var myL = setlistener2("some/prop", func { ... }} )
var myL = setlistener2("some/prop", func { ... }} )


Line 7: Line 8:


myL.addprop("yet/another/prop");
myL.addprop("yet/another/prop");
</syntaxhighlight>
Now you need to retain a ref to myL or the listeners on all the props are removed. I don't think we can retro-fit this to the existing API, because I suspect many places just ignore the return value and would break with this change.
Now you need to retain a ref to myL or the listeners on all the props are removed. I don't think we can retro-fit this to the existing API, because I suspect many places just ignore the return value and would break with this change.
(Or even pass a vec of property names to setlistener2, to avoid all the discrete calls to 'addprop', that's a seperate detail really)
(Or even pass a vec of property names to setlistener2, to avoid all the discrete calls to 'addprop', that's a seperate detail really)

Navigation menu