Debian Codegraph @

texmf-dist/doc/support/cluttex/checkglobal.lua

raw symbols SCIP
1 if #arg == 0 then
2 io.stderr:write[[
3 Usage: lua checkglobal.lua <file.lua>
4 ]]
5 os.exit(1)
6 end
7 local f = assert(io.popen("luac -l -l " .. arg[1]))
8 local known_global = {
9 -- Basic
10 _G = true,
11 _VERSION = true,
12 assert = true,
13 collectgarbage = true,
14 dofile = true,
15 error = true,
16 getmetatable = true,
17 ipairs = true,
18 load = true,
19 loadfile = true,
20 next = true,
21 pairs = true,
22 pcall = true,
23 print = true,
24 rawequal = true,
25 rawget = true,
26 rawlen = true,
27 rawset = true,
28 require = true,
29 select = true,
30 setmetatable = true,
31 tonumber = true,
32 tostring = true,
33 type = true,
34 xpcall = true,
35 loadstring = true, -- Lua 5.1
36
37 -- Standard modules
38 bit32 = true, -- Lua 5.2
39 coroutine = true,
40 debug = true,
41 io = true,
42 math = true,
43 os = true,
44 package = true,
45 string = true,
46 table = true,
47 -- Lua 5.3 adds 'utf8' module
48
49 -- LuaJIT / LuaTeX extensions
50 bit = true,
51 lfs = true,
52
53 -- Others
54 arg = true, -- command line argument
55 }
56 local result = true
57 for line in f:lines() do
58 local m = line:match("; _ENV \"(%w+)\"")
59 if m then
60 if not known_global[m] then
61 print("Unknown global variable: ", m)
62 result = false
63 end
64 end
65 end
66 if result then
67 os.exit(0)
68 else
69 os.exit(1)
70 end