lua-users home
lua-l archive

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


Diego Nehab wrote:
>> Unless you manually write something in package.loaded["socket"],
>> require("socket.core") won't, and so any call of the form
>> require("socket") will at least call the init function of socket
>> module (ie. socket.lua). That does not mean that things will be ok,
>> but at least the module system won't get in the way.
> 
> socket.core calls luaL_openlib("socket", func, 0). Won't this create
> a module table and put it in package.loaded["socket"]? 

It will, and in that case you cannot load socket after socket.core. That
should be straightforward to fix. You just have register it in
"socket.core", and at the top of socket.lua do something like:

module("socket")
local core = require("socket.core")
for k,v in pairs(core) do
    _M[k] = v
end

I think that shows it's a good habit to use the string passed to the
module init function as the module name instead of a hard coded string.
You never know how people will use (and sometime rename) your modules
(even private submodules as in that case).