[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: On Lua and C Modules (was Re: [ANN] luafaq.org source on GitHub)
- From: Sean Conner <sean@...>
- Date: Fri, 28 Jun 2013 17:00:13 -0400
It was thus said that the Great Roberto Ierusalimschy once stated:
> > module(name) is not considered evil, but module(name,package.seeall) is.
> > (I'm assuming that Lua 5.2 is usually built in compatibility mode)
> I tend to consider 'module(name)' evil nowadays. It is is so easy
> to write a module without 'module', and the result is so less magic...
On that note ...
Yes, it's easy enough to do:
to pick up the name the requiring script is using (in fact, I just did it
right now 'org.conman.cc' ). But for a module written in C, it's a
lot harder to "move" the modules, because of how the initialization function
needs to be called. So, while I can take the module "org.conman.cc", copy
the file into "/usr/local/lib/lua/5.1/com/example/external/cc.lua" and load
x = require "com.example.external.cc" -- 
I *can't* do the same for the module it requires, "org.conman.tcc" ,
since it's written in C and thus, it *needs* to reside in
I'm surprised that Lua doesn't look for just
as part of the search mechanism. It's a dynamic library---there is no
problem what-so-ever in loading multiple shared libs with functions of the
same name  so as a fall-back, just calling luaopen() would seem to be
obvious . I'm just curious as to why that wasn't done. If it had, then
it would be easy to move, say, "org.conman.env"  to another location.
-spc (Just curious ... )
 I copied the file to another directory, renamed it 'fluffy.lua',
modified the module() line, and was able to load it just fine.
 Don't question why I would do this; it's enough that I can.
 Years ago I wrote a program that would load modules at run time, and
each module exports the same symbol.
 Your method of actually appending the module name was actually
surprising to me when I first started looking into it.