lua-users home
lua-l archive

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


Perhaps there is another list where I should direct my question.  If
so, let me know.

Why in lua socket is there a totally different way to require modules
than the usual require("ftp")?  I've just downloaded the 2.0 beta and
it has this following chunk:

-- finds a lua library and returns the entrypoint
local function find(lib)
    local path = LUA_PATH or os.getenv("LUA_PATH") or "?;?.lua"
    local f, e1
    for p in string.gfind(path, "[^;]+") do
      local n = string.gsub(p, "%?", lib)
      f, e1 = loadfile(n)
      if f then break end
    end
    return f, e1
end

-- new "require" function
function require(name)
    if not _LOADED[name] then
        local f = assert(find(name))
        local m = {}
        setmetatable(m, {__index = _G})
        setfenv(f, m)
        f()
        _LOADED[name] = m
    end
    return _LOADED[name]
end


that has to be executed to properly "require" something like ftp.  Is
there a reason for this?  It seems overly complex when a simple
module("ftp") would suffice inside the ftp.lua script.

wes