Advertisement
Guest User

Untitled

a guest
Oct 4th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. print("Input luascript.cpp directory: ")
  2. local luascript = io.read()
  3. print("Input your output directory: ")
  4. local output_dir = io.read()
  5. local file = io.open(luascript)
  6. local doc = {}
  7. function table.find(t, val)
  8.     for k, v in pairs(t) do
  9.         if v == val then
  10.             return true
  11.         end
  12.     end
  13. end
  14.  
  15. local block = {"registerClass", "registerMethod", "registerTable", "registerMetaMethod", "registerGlobalMethod", "registerVariable", "registerGlobalVariable", "registerEnum", "registerEnumIn"}
  16.  
  17. if file then
  18.     for line in file:lines() do
  19.         local m = line:match("//%s?([%a%w%p%s%(%)]*)\n?")
  20.         if m then
  21.             local method, constructor = m:match("%a+[%.:]%a+%(.*%)"), m:match("^%u%a+%(.*%)$")
  22.             if method or constructor then
  23.                 -- class method / constructor
  24.                 local class = m:match("(%a+)"):gsub("^%l", string.upper, 1)
  25.                 if not doc[class] then
  26.                     doc[class] = {m}
  27.                 else
  28.                     if not table.find(doc[class], m) then
  29.                         doc[class][#doc[class] + 1] = m
  30.                     end
  31.                 end
  32.             elseif m:match("%a+%(.*%)") then
  33.                 -- regular lua function
  34.                 local func_name = m:match("(%a+)%(.*%)")
  35.                 if not table.find(block, func_name) then
  36.                     if not doc["[ Extra Lua Functions ]"] then
  37.                         doc["[ Extra Lua Functions ]"] = {}
  38.                     else
  39.                         if not table.find(doc["[ Extra Lua Functions ]"], m) then
  40.                             doc["[ Extra Lua Functions ]"][#doc["[ Extra Lua Functions ]"] + 1] = m
  41.                         end
  42.                     end
  43.                 end
  44.             end
  45.         end
  46.     end
  47. end
  48.  
  49. function alphanumsort(o)
  50.     local function padnum(d) return ("%03d%s"):format(#d, d) end
  51.     table.sort(o, function(a,b)
  52.         return tostring(a):gsub("%d+",padnum) < tostring(b):gsub("%d+",padnum)
  53.     end)
  54.     return o
  55. end
  56.  
  57. function kipairs(t)
  58.     local keys = {}
  59.     for k, v in pairs(t) do
  60.         keys[#keys + 1] = k
  61.     end
  62.     table.sort(keys)
  63.     local i = 0
  64.     return function()
  65.         i = i + 1
  66.         local v = t[keys[i]]
  67.         if v then
  68.             return keys[i], v
  69.         end
  70.     end
  71. end
  72.  
  73. for k, v in pairs(doc) do
  74.     alphanumsort(doc[k])
  75. end
  76.  
  77. local documentation = io.open(output_dir .. "\\documentation.txt", "w+")
  78.  
  79. for k, v in kipairs(doc) do
  80.     documentation:write(k .. "\n")
  81.     for _, m in ipairs(v) do
  82.         documentation:write("\t".. m .. "\n")
  83.     end
  84.     documentation:write("\n")
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement