[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bugs.. ?
- From: Kaos <kaos@...>
- Date: Thu, 29 Jan 2004 10:14:36 +0100
Thatcher Ulrich wrote:
[snip]
As far as namespaces go, we have been using a single-level namespace.
Modules are certainly not prohibited from defining their own
sub-namespaces, but cheia.load() and the like don't understand
hierarchies themselves. E.g.:
cheia.load("std") -- OK
cheia.load("std.bit") -- not understood in a meaningful way
[snip]
When loading lua files (e.g. with require) you could take the approach
mentioned in Roberto's book: to have a specific file as the last entry
in LUA_PATH, so all required modules not found will run this named file,
which in turn could inspect the global _REQUIREDNAME to do the actual
loading.
I don't know about your previous headaches vs. gains, but this wouls
work for dyn libs as well, taken that there is a table defined that maps
the lib with a name and what else is needed to require it.
I'm not sure if what I just said is understandable, so I provide a small
example:
(note: I have no prior experience with loadlib, so I'm just tossing
about to make my point somewhat clear, if possible)
LUA_PATH="?;?.lua;/usr/local/lua/cust_require.lua" -- example lua path
-- lib_defs.lua
libraries = {
{ "name" = "rex", "libname" = "/.../lib_rex.so", "func" = "open_rex" },
{ "name" = "std.foo.bit", "libname" = "/.../std/foo/bit.so", "func" =
"open_bit" }
}
-- EOF lib_defs
-- cust_require.lua
-- check for library
for lib in ipairs( libraries ) do
if lib.name == _REQUIREDNAME then
-- load library with some func
return loadlib( lib.libname, lib.func )
end
end
-- not a dyn lib, check for lua file
-- some searching in ordinary ways..
-- EOF cust_require
Only make sure that the libraries table is defined, and the cust_require
is in LUA_PATH.
Not sure what headaches comes with this, and might not be worth it, or
even something you've already tried.. I've had fun writing it (not
tested) any how ;)
Comments?
//Andreas