lua-users home
lua-l archive

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


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:

	module(...)

to pick up the name the requiring script is using (in fact, I just did it
right now 'org.conman.cc' [1][2]).  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
it as:

		x = require "com.example.external.cc" -- [3]

  I *can't* do the same for the module it requires, "org.conman.tcc" [4],
since it's written in C and thus, it *needs* to reside in
"/usr/local/lib/5.1/org/conman/tcc.so".

  I'm surprised that Lua doesn't look for just 

		luaopen()

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 [5] so as a fall-back, just calling luaopen() would seem to be
obvious [6].  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" [7] to another location.

  -spc (Just curious ... )

[1]	https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.lua

[2]	I copied the file to another directory, renamed it 'fluffy.lua',
	modified the module() line, and was able to load it just fine.

[3]	Don't question why I would do this; it's enough that I can.

[4]	https://github.com/spc476/lua-conmanorg/blob/master/src/tcc.c

[5]	Years ago I wrote a program that would load modules at run time, and
	each module exports the same symbol.  

[6]	Your method of actually appending the module name was actually
	surprising to me when I first started looking into it.

[7]	https://github.com/spc476/lua-conmanorg/blob/master/src/env.c