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 Dibyendu Majumdar once stated:
> >
> > I didn't even realize that Lua supported require 'a.b.c' and that this
> > is translated to a filesystem path, maybe because I haven't seen it
> > being used.
> >
> > Will certainly make sure that all modules in the Ravi distro follow a
> > supplier.modue (e.g. torch.paths) pattern - can't imagine why people
> > don't do this. It is a no brainer to me.
> 
> Maybe there is one problem - the require function also loads shared
> libraries. Having these in multiple locations could be a problem as
> these need to be in the path.

  It depends upon what you mean.  For example, my syslog module [1] is a
C-based module.  When you do:

	local syslog = require "org.conman.syslog"

Lua will replace the dots with the file separator (in my case '/'):

	org/conman/syslog

and for each component in package.cpath (broken out for easier reading):

	/home/spc/.luarocks/lib/lua/5.1/?.so
	./?.so
	/usr/local/lib/lua/5.1/?.so
	/usr/local/lib/lua/5.1/loadall.so

will replace the '?' with the modified module name:

	/home/spc/.luarocks/lib/lua/5.1/org/conman/syslog.so
	./org/conman/syslog.so
	/usr/local/lib/lua/5.1/org/conman/syslog.so
	/usr/local/lib/lua/5.1/loadall.so

and will attempt to load each .so file in turn.  Further more, to illustrate
a potentinal problem, I installed org.conman.syslog twice, once manually and
once via LuaRocks.  

	[spc]lucy:~>luawhich org.conman.syslog # [2]
	/home/spc/.luarocks/lib/lua/5.1/org/conman/syslog.so
	/usr/local/lib/lua/5.1/org/conman/syslog.so

  In this case, Lua will load "/home/spc/.luarocks/lib/lua/5.1/org/conman/syslog.so" since it is found
first by Lua.

  -spc

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

[2]	A Lua script that prints out the location of a module given its
	name.