[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: gtk+2 and Lua - first sample
- From: Eero Pajarre <epajarre@...>
- Date: Thu, 17 Feb 2005 00:31:47 +0200
Luiz Henrique de Figueiredo wrote:
I see one possible major problem with a simple implemetation of the
level one API. Does it enable crashing the application?
No if it's done carefully. See my libraries for examples. It's easy, really:
you just wrap pointers as userdata and set them to NULL when they're GC'd or
destroyed and check for NULL when they're handed to C.
I agree this is how it should be, but I am not sure how easy it is in
all cases. For example in a (not quite hypothetical) GUI library
destroying a container window will also delete all the child windows, so
every reference to child windows should also be NULLed for the Lua side.
Or in the CAD system I mentioned, it was possible to get "handles" to
selected objects in the scene, but these handles could be invalidated
by other operations, and I had reason to suspect that using an invalid
handle would be fatal to the program.
Of course all of these problems also existed in te C/C++ side, I
"just" wanted to make it safe with Lua.
On the other hand, I've found that it's simpler to bind destroy functions
to __gc methods instead of exporting them to Lua.
Related also to Asko's comment -- for a GUI library a real destroy is
also needed so that the program doesn't run out of other resources
before GC starts its operation.
Still I have been a happy user of the wxWindows Lua binding, and I have
not crashed it for some time. I cannot say if this is because the
binding is fool/bullet proof, or is it partly because I have not done
really dangerous things.