lua-users home
lua-l archive

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


> However, it seems that this minor issue has hijacked Diegos
> original agenda, namely; the best way to manage (and mask) the
> difference between static and dynamically loaded libraries.
> Unload support would be a nice addition but is not critical.

Since the unloading seems to be an area of less agreement, I started
with the original problem. So far, I have an implementation of
"requirelib", just like Tiago Dionizio's "requireso", which is a better
way of doing things than my previous approach. ("lib" seemed more
appropriate since other systems don't know what "so" is).

The only difference is that just like "require" uses the _LOADED table,
"requirelib" uses the _LOADEDLIB table to cache.  I made both  _LOADED
and _LOADEDLIB be weak tables to allow for garbage collection.  The
function uses the LUA_PATHLIB environment variable for a search path.

Whenever a C library is loaded, it should set it's return value in the
_LOADEDLIB table. That way, if it  linked static and a user calls
"requirelib", the function will work as expected. The same applies for
"require": Lua modules should set their return value also in the _LOADED
lib, in case they are loaded static (precompiled).

This seems to solve the "dynamic vs. static" issue, but I agree it's
somewhat artificial. Any suggestions?

The interfaces are similar, but I am not sure requirelib and require
should be unified. Maybe it's good to know when a library is C, and when
it's Lua...