print("Input luascript.cpp directory: ") local luascript = io.read() print("Input your output directory: ") local output_dir = io.read() local file = io.open(luascript) local doc = {} function table.find(t, val) for k, v in pairs(t) do if v == val then return true end end end local block = {"registerClass", "registerMethod", "registerTable", "registerMetaMethod", "registerGlobalMethod", "registerVariable", "registerGlobalVariable", "registerEnum", "registerEnumIn"} if file then for line in file:lines() do local m = line:match("//%s?([%a%w%p%s%(%)]*)\n?") if m then local method, constructor = m:match("%a+[%.:]%a+%(.*%)"), m:match("^%u%a+%(.*%)$") if method or constructor then -- class method / constructor local class = m:match("(%a+)"):gsub("^%l", string.upper, 1) if not doc[class] then doc[class] = {m} else if not table.find(doc[class], m) then doc[class][#doc[class] + 1] = m end end elseif m:match("%a+%(.*%)") then -- regular lua function local func_name = m:match("(%a+)%(.*%)") if not table.find(block, func_name) then if not doc["[ Extra Lua Functions ]"] then doc["[ Extra Lua Functions ]"] = {} else if not table.find(doc["[ Extra Lua Functions ]"], m) then doc["[ Extra Lua Functions ]"][#doc["[ Extra Lua Functions ]"] + 1] = m end end end end end end end function alphanumsort(o) local function padnum(d) return ("%03d%s"):format(#d, d) end table.sort(o, function(a,b) return tostring(a):gsub("%d+",padnum) < tostring(b):gsub("%d+",padnum) end) return o end function kipairs(t) local keys = {} for k, v in pairs(t) do keys[#keys + 1] = k end table.sort(keys) local i = 0 return function() i = i + 1 local v = t[keys[i]] if v then return keys[i], v end end end for k, v in pairs(doc) do alphanumsort(doc[k]) end local documentation = io.open(output_dir .. "\\documentation.txt", "w+") for k, v in kipairs(doc) do documentation:write(k .. "\n") for _, m in ipairs(v) do documentation:write("\t".. m .. "\n") end documentation:write("\n") end