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 Soni They/Them L. once stated:
> On 2018-02-25 01:26 AM, Sean Conner wrote:

> >It was thus said that the Great Soni They/Them L. once stated:
> >>On 2018-02-24 07:19 PM, Sean Conner wrote:
> >>>It was thus said that the Great Soni They/Them L. once stated:
> >>>>Why does nobody support renaming modules, it's 2018 :(
> >>>   Please rename a module written in C and get it to run, without
> >>>recompilation.  Then report your findings back here.
> >>>
> >>>   -spc
> >>>
> >>>
> >>Am I allowed to recompile Lua, or monkeypatch require? The default
> >>behaviour is very much crap for C modules and I've been talking about it
> >>for months now.
> >   Why can't you just rename the modules?
> >
> >   Hint:  the thread starting here: 
> >   http://lua-users.org/lists/lua-l/2013-06/msg00464.html
> >
> >   -spc (You have?)
> >
> >
> >
> >
> 
> Yes, Lua likes to hardcode C module names and doesn't call them with 
> their modname + path.

  I don't think Roberto "likes to hardcode C module names":

> Modules are not always linked dynamically (see, for instance, the
> standard Lua libraries). With a single name, one would not be able to
> statically link a set of modules to a program.
> 
> (Moreover, I am not sure your experience number [5] is portable. IIRC,
> we had problems in the past with some systems that signalled name
> conflicts even with dynamic libraries.)
> 
> -- Roberto

and the footnote:

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

  And if you read the documentation under "package.searchers":

> My idea is for a module loading system that looks for "luaopen_" symbol. 
> then "luaopen_submod" and so on.
> 
> When requiring something that leads to an .so, it looks for "luaopen_" 
> if the full path matched, "luaopen_submod" if it only matched up to the 
> last, and so on.
> 
> And then I'd give it the modname and the path to SO, and maybe also the 
> partial modname used to find the SO.
>
> It would be a much better system that Lua doesn't support. 

  I direct you to the documentation to package.searchers:

	When looking for a module, require calls each of these searchers in
	ascending order, with the module name (the argument given to
	require) as its sole parameter.

	...

	The fourth searcher tries an all-in-one loader. It searches the C
	path for a library for the root name of the given module. For
	instance, when requiring a.b.c, it will search for a C library for
	a. If found, it looks into it for an open function for the
	submodule; in our example, that would be luaopen_a_b_c. With this
	facility, a package can pack several C submodules into one single
	library, with each submodule keeping its original open function.

  It does appear that Lua 5.3 also passes in the path (as the second Lua
parameter) to each searcher, so either the documenation is wrong, or it's an
undocumted feature.

  -spc