module name inference (1) 'mod/init.lua' is 'mod' (2) either M or _M are used as default alias values for 'new-style' modules

This commit is contained in:
steve donovan 2011-06-16 16:44:46 +02:00
parent ad2a350806
commit 98b0617d34
3 changed files with 8 additions and 6 deletions

View File

@ -168,11 +168,13 @@ end
local quit = utils.quit local quit = utils.quit
-- parses a Lua file, looking for ldoc comments. These are like LuaDoc comments; -- parses a Lua or C file, looking for ldoc comments. These are like LuaDoc comments;
-- they start with multiple '-'. If they don't define a name tag, then by default -- they start with multiple '-'. (Block commments are allowed)
-- If they don't define a name tag, then by default
-- it is assumed that a function definition follows. If it is the first comment -- it is assumed that a function definition follows. If it is the first comment
-- encountered, then ldoc looks for a call to module() to find the name of the -- encountered, then ldoc looks for a call to module() to find the name of the
-- module. -- module if there isn't an explicit module name specified.
local function parse_file(fname,lang) local function parse_file(fname,lang)
local line,f = 1 local line,f = 1
local F = File(fname) local F = File(fname)

View File

@ -134,7 +134,8 @@ function File:finish()
--item:warning(item.name .. ' is declared in global scope') --item:warning(item.name .. ' is declared in global scope')
end end
-- the function may be qualified with a module alias... -- the function may be qualified with a module alias...
if this_mod.tags.alias and mod == this_mod.tags.alias then local alias = this_mod.tags.alias
if (alias and mod == alias) or mod == 'M' or mod == '_M' then
mod = this_mod.mod_name mod = this_mod.mod_name
end end
-- if that's the mod_name, then we want to only use 'foo' -- if that's the mod_name, then we want to only use 'foo'

View File

@ -188,7 +188,6 @@ end
function M.this_module_name (basename,fname) function M.this_module_name (basename,fname)
local ext local ext
if basename == '' then if basename == '' then
--quit("module(...) needs package basename")
return M.name_of(fname) return M.name_of(fname)
end end
basename = path.abspath(basename) basename = path.abspath(basename)
@ -198,7 +197,7 @@ function M.this_module_name (basename,fname)
local lpath,cnt = fname:gsub('^'..utils.escape(basename),'') local lpath,cnt = fname:gsub('^'..utils.escape(basename),'')
if cnt ~= 1 then quit("module(...) name deduction failed: base "..basename.." "..fname) end if cnt ~= 1 then quit("module(...) name deduction failed: base "..basename.." "..fname) end
lpath = lpath:gsub(path.sep,'.') lpath = lpath:gsub(path.sep,'.')
return M.name_of(lpath) return M.name_of(lpath):gsub('%.init$','')
end end
function M.find_existing_module (name, searchfn) function M.find_existing_module (name, searchfn)