lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


That depends on how you plan to use the DLL.  Perhaps you will never call
the DLL.  After all once you load a DLL it's code is free to do anything it
"wants" as part of your process (such as spawn a thread and keep running).

It's amazingly simple to write your own library loading system for Lua if
you so choose, and I have to admit that I'm not a loadlib expert because I
wrote my own system (originally using Lua 4.1).  However, that gave me a
certain perspective when I discovered loadlib.

I, like you, was surprised by the lack of an unload (i.e. a GC) mechanism.
Personally, I assumed that a library load operation should return a table of
functions available from the library and so loadlib returning "whatever"
surprised me a bit.  This also brought up, for me, the issue that tables do
not get to process a GC event.  Userdata's do, but tables don't.

The "solution" to this problem is extremely simple.  It is up to the library
author to handle the issue.  How?  The library returns whatever value makes
sense for that particular library.  If that happens to be a "table" of
callable functions then it can return that table.  If the library should be
"Freed" when no longer needed then it should return a userdata whose __gc
metamethod handles all of the clean up details.  To associate a table of
functions with such a userdata simply make a table of functions and then set
it as the __index metamethod for the userdata (or use a function to do the
lookup in C).

At least that is my understanding of the situation.  I hope this helps.

Minor Warning:  I've never tried calling FreeLibrary from inside the code
for the DLL itself so I don't <actually> know that a DLL CAN clean up after
itself inside a GC event handler.



-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Jose Marin
Sent: Tuesday, January 13, 2004 12:29 PM
To: Lua list
Subject: loadlib question


Hello.

loadlib uses Window's LoadLibrary to load the lib's
dll, but doesn't perform any FreeLibrary.

Is this a problem?


______________________________________________________________________

Conheça a nova central de informações anti-spam do Yahoo! Mail:
http://www.yahoo.com.br/antispam