2011-06-19 17:52:02 +02:00
|
|
|
-------
|
|
|
|
-- global functions and tables
|
|
|
|
local tools = require 'ldoc.tools'
|
2011-09-19 14:42:54 +02:00
|
|
|
local globals = {}
|
2012-03-13 09:37:07 +01:00
|
|
|
local lua52 = _VERSION:match '5.2'
|
2011-06-19 17:52:02 +02:00
|
|
|
|
|
|
|
|
2011-09-19 14:42:54 +02:00
|
|
|
globals.functions = {
|
2011-06-19 17:52:02 +02:00
|
|
|
assert = true,
|
|
|
|
collectgarbage = true,
|
|
|
|
dofile = true,
|
|
|
|
getmetatable = true,
|
|
|
|
setmetatable = true,
|
|
|
|
pairs = true,
|
|
|
|
ipairs = true,
|
|
|
|
load = true,
|
|
|
|
loadfile = true,
|
|
|
|
loadstring = true,
|
|
|
|
next = true,
|
|
|
|
pcall = true,
|
|
|
|
print = true,
|
|
|
|
rawequal = true,
|
|
|
|
rawget = true,
|
|
|
|
rawset = true,
|
|
|
|
select = true,
|
|
|
|
tonumber = true,
|
|
|
|
tostring = true,
|
|
|
|
type = true,
|
|
|
|
xpcall = true,
|
|
|
|
module = true,
|
|
|
|
require = true,
|
|
|
|
}
|
2011-09-19 14:42:54 +02:00
|
|
|
local functions = globals.functions
|
2011-06-19 17:52:02 +02:00
|
|
|
|
2012-03-13 09:37:07 +01:00
|
|
|
if not lua52 then
|
|
|
|
functions.setfenv = true
|
|
|
|
functions.getfenv = true
|
|
|
|
functions.unpack = true
|
|
|
|
else
|
|
|
|
functions.rawlen = true
|
|
|
|
end
|
2011-09-19 14:42:54 +02:00
|
|
|
|
|
|
|
local manual, fun_ref
|
2011-06-19 17:52:02 +02:00
|
|
|
|
2011-09-19 14:42:54 +02:00
|
|
|
function globals.set_manual_url(url)
|
2012-03-13 09:37:07 +01:00
|
|
|
manual = url .. '#'
|
|
|
|
fun_ref = manual..'pdf-'
|
2011-09-19 14:42:54 +02:00
|
|
|
end
|
2012-03-13 09:37:07 +01:00
|
|
|
|
|
|
|
if lua52 then
|
|
|
|
globals.tables = {
|
|
|
|
io = '6.8',
|
|
|
|
package = '6.3',
|
|
|
|
math = '6.6',
|
|
|
|
os = '6.9',
|
|
|
|
string = '6.4',
|
|
|
|
table = '6.5',
|
|
|
|
coroutine = '6.2',
|
|
|
|
debug = '6.10'
|
|
|
|
}
|
|
|
|
globals.set_manual_url 'http://www.lua.org/manual/5.2/manual.html'
|
|
|
|
else
|
|
|
|
globals.tables = {
|
|
|
|
io = '5.7',
|
|
|
|
package = '5.3',
|
|
|
|
math = '5.6',
|
|
|
|
os = '5.8',
|
|
|
|
string = '5.4',
|
|
|
|
table = '5.5',
|
|
|
|
coroutine = '5.2',
|
|
|
|
debug = '5.9'
|
|
|
|
}
|
|
|
|
globals.set_manual_url 'http://www.lua.org/manual/5.1/manual.html'
|
|
|
|
end
|
|
|
|
|
2014-04-23 13:38:58 +02:00
|
|
|
local file_methods = {
|
|
|
|
close = true,
|
|
|
|
flush = true,
|
|
|
|
lines = true,
|
|
|
|
read = true,
|
|
|
|
seek = true,
|
|
|
|
setvbuf = true,
|
|
|
|
write = true,
|
|
|
|
}
|
|
|
|
|
2013-08-21 14:52:09 +02:00
|
|
|
-- external libs tracked by LDoc using LDoc style
|
|
|
|
local xlibs = {
|
|
|
|
lfs='lfs.html', lpeg='lpeg.html',
|
|
|
|
}
|
|
|
|
local xlib_url = 'http://stevedonovan.github.io/lua-stdlibs/modules/'
|
|
|
|
|
2012-03-13 09:37:07 +01:00
|
|
|
local tables = globals.tables
|
2011-06-19 17:52:02 +02:00
|
|
|
|
2013-08-21 14:52:09 +02:00
|
|
|
local function function_ref (name,tbl)
|
|
|
|
local href
|
2013-08-21 15:52:53 +02:00
|
|
|
if not tbl then -- can only be a standard Lua global function
|
|
|
|
if globals.functions[name] then
|
|
|
|
return {href = fun_ref..name, label = name}
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
2014-04-23 13:38:58 +02:00
|
|
|
if tbl == 'file' then -- special case: file objects!
|
|
|
|
if not file_methods[name] then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
name = 'file:'..name
|
|
|
|
href = fun_ref..name
|
|
|
|
elseif tables[tbl] then -- function inside standard Lua table
|
2013-08-22 09:15:16 +02:00
|
|
|
local t = rawget(_G,tbl) -- do a quick sanity check
|
|
|
|
if not rawget(t,name) then
|
|
|
|
return nil
|
|
|
|
end
|
2013-08-21 14:52:09 +02:00
|
|
|
name = tbl..'.'..name
|
|
|
|
href = fun_ref..name
|
2013-08-21 15:52:53 +02:00
|
|
|
elseif xlibs[tbl] then -- in external libs, use LDoc style
|
2013-08-22 09:15:16 +02:00
|
|
|
local t = require('ldoc.builtin.'..tbl)
|
|
|
|
if not rawget(t,name) then
|
|
|
|
return nil
|
|
|
|
end
|
2013-08-21 14:52:09 +02:00
|
|
|
href = xlib_url..xlibs[tbl]..'#'..name
|
|
|
|
name = tbl..'.'..name
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return {href = href, label = name}
|
2011-06-19 17:52:02 +02:00
|
|
|
end
|
|
|
|
|
2013-08-21 14:52:09 +02:00
|
|
|
local function module_ref (tbl)
|
|
|
|
local href
|
2013-08-21 15:52:53 +02:00
|
|
|
if tables[tbl] ~= nil then -- standard Lua table
|
2013-08-21 14:52:09 +02:00
|
|
|
href = manual..tables[tbl]
|
2013-08-21 15:52:53 +02:00
|
|
|
elseif xlibs[tbl] then -- external lib
|
2013-08-21 14:52:09 +02:00
|
|
|
href = xlib_url..xlibs[tbl]
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return {href = href, label = tbl}
|
2011-06-19 17:52:02 +02:00
|
|
|
end
|
|
|
|
|
2011-09-19 14:42:54 +02:00
|
|
|
function globals.lua_manual_ref (name)
|
2011-06-19 17:52:02 +02:00
|
|
|
local tbl,fname = tools.split_dotted_name(name)
|
2013-08-21 14:52:09 +02:00
|
|
|
local ref
|
2011-06-19 17:52:02 +02:00
|
|
|
if not tbl then -- plain symbol
|
2013-08-21 14:52:09 +02:00
|
|
|
ref = function_ref(name)
|
|
|
|
if ref then return ref end
|
|
|
|
ref = module_ref(name)
|
|
|
|
if ref then return ref end
|
2011-06-19 17:52:02 +02:00
|
|
|
else
|
2013-08-21 14:52:09 +02:00
|
|
|
ref = function_ref(fname,tbl)
|
|
|
|
if ref then return ref end
|
2011-06-19 17:52:02 +02:00
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2011-09-19 14:42:54 +02:00
|
|
|
return globals
|