Преглед изворни кода

Added script (pkgToDox.lua) which regenerates Lua script API documentation. It can be run with a standalone Lua interpreter.

Lasse Öörni пре 12 година
родитељ
комит
862ca75a46
2 измењених фајлова са 353 додато и 0 уклоњено
  1. 118 0
      Source/Extras/LuaScript/pkgs/pkgFiles.lua
  2. 235 0
      Source/Extras/LuaScript/pkgs/pkgToDox.lua

+ 118 - 0
Source/Extras/LuaScript/pkgs/pkgFiles.lua

@@ -0,0 +1,118 @@
+pkgFiles =
+{
+    "Audio/Audio.pkg",
+    "Audio/Sound.pkg",
+    "Audio/SoundListener.pkg",
+    "Audio/SoundSource.pkg",
+    "Audio/SoundSource3D.pkg",
+    "Container/Vector.pkg",
+    "Core/Context.pkg",
+    "Core/Object.pkg",
+    "Core/ProcessUtils.pkg",
+    "Core/StringUtils.pkg",
+    "Core/Timer.pkg",
+    "Core/Variant.pkg",
+    "Engine/Console.pkg",
+    "Engine/DebugHud.pkg",
+    "Engine/Engine.pkg",
+    "Graphics/AnimatedModel.pkg",
+    "Graphics/Animation.pkg",
+    "Graphics/AnimationController.pkg",
+    "Graphics/AnimationState.pkg",
+    "Graphics/BillboardSet.pkg",
+    "Graphics/Camera.pkg",
+    "Graphics/DebugRenderer.pkg",
+    "Graphics/DecalSet.pkg",
+    "Graphics/Drawable.pkg",
+    "Graphics/Graphics.pkg",
+    "Graphics/GraphicsDefs.pkg",
+    "Graphics/Light.pkg",
+    "Graphics/Material.pkg",
+    "Graphics/Model.pkg",
+    "Graphics/Octree.pkg",
+    "Graphics/OctreeQuery.pkg",
+    "Graphics/ParticleEmitter.pkg",
+    "Graphics/Renderer.pkg",
+    "Graphics/RenderPath.pkg",
+    "Graphics/RenderSurface.pkg",
+    "Graphics/Skeleton.pkg",
+    "Graphics/Skybox.pkg",
+    "Graphics/StaticModel.pkg",
+    "Graphics/StaticModelGroup.pkg",
+    "Graphics/Technique.pkg",
+    "Graphics/Terrain.pkg",
+    "Graphics/TerrainPatch.pkg",
+    "Graphics/Texture.pkg",
+    "Graphics/Texture2D.pkg",
+    "Graphics/TextureCube.pkg",
+    "Graphics/Viewport.pkg",
+    "Graphics/Zone.pkg",
+    "Input/Input.pkg",
+    "Input/InputEvents.pkg",
+    "IO/Deserializer.pkg",
+    "IO/File.pkg",
+    "IO/FileSystem.pkg",
+    "IO/Log.pkg",
+    "IO/PackageFile.pkg",
+    "IO/Serializer.pkg",
+    "LuaScript/LuaScript.pkg",
+    "LuaScript/LuaScriptInstance.pkg",
+    "Math/BoundingBox.pkg",
+    "Math/Color.pkg",
+    "Math/Frustum.pkg",
+    "Math/MathDefs.pkg",
+    "Math/Matrix3.pkg",
+    "Math/Matrix3x4.pkg",
+    "Math/Matrix4.pkg",
+    "Math/Plane.pkg",
+    "Math/Polyhedron.pkg",
+    "Math/Quaternion.pkg",
+    "Math/Random.pkg",
+    "Math/Ray.pkg",
+    "Math/Rect.pkg",
+    "Math/Sphere.pkg",
+    "Math/StringHash.pkg",
+    "Math/Vector2.pkg",
+    "Math/Vector3.pkg",
+    "Math/Vector4.pkg",
+    "Navigation/Navigable.pkg",
+    "Navigation/NavigationMesh.pkg",
+    "Navigation/OffMeshConnection.pkg",
+    "Network/Connection.pkg",
+    "Network/Controls.pkg",
+    "Network/Network.pkg",
+    "Network/NetworkPriority.pkg",
+    "Physics/CollisionShape.pkg",
+    "Physics/Constraint.pkg",
+    "Physics/PhysicsWorld.pkg",
+    "Physics/RigidBody.pkg",
+    "Resource/Image.pkg",
+    "Resource/Resource.pkg",
+    "Resource/ResourceCache.pkg",
+    "Resource/XMLElement.pkg",
+    "Resource/XMLFile.pkg",
+    "Scene/Component.pkg",
+    "Scene/Node.pkg",
+    "Scene/Scene.pkg",
+    "Scene/Serializable.pkg",
+    "UI/BorderImage.pkg",
+    "UI/Button.pkg",
+    "UI/CheckBox.pkg",
+    "UI/Cursor.pkg",
+    "UI/DropDownList.pkg",
+    "UI/FileSelector.pkg",
+    "UI/Font.pkg",
+    "UI/LineEdit.pkg",
+    "UI/ListView.pkg",
+    "UI/Menu.pkg",
+    "UI/ScrollBar.pkg",
+    "UI/ScrollView.pkg",
+    "UI/Slider.pkg",
+    "UI/Sprite.pkg",
+    "UI/Text.pkg",
+    "UI/Text3D.pkg",
+    "UI/UI.pkg",
+    "UI/UIElement.pkg",
+    "UI/View3D.pkg",
+    "UI/Window.pkg"
+}

+ 235 - 0
Source/Extras/LuaScript/pkgs/pkgToDox.lua

@@ -0,0 +1,235 @@
+-- Generate dox from pkg file
+require "pkgFiles"
+
+enums = {}
+classes = {}
+globalConstants = {}
+globalFunctions = {}
+
+-- trim string.
+function trim(s)
+    return (s:gsub("^%s*(.-)%s*$", "%1"))
+end
+
+-- check is embed code.
+inEmbed = false
+function isEmbedLine(line)
+    if string.sub(line, 1, 2) == "$#" then
+        return true
+    end
+    
+    if not inEmbed then
+        if string.find(line, "${") ~= nil or string.find(line, "$[[]") ~= nil then
+            inEmbed = true
+            return true
+        end
+    else
+        if string.find(line, "$}") ~= nil or string.find(line, "$[]]") ~= nil then
+            inEmbed = false
+            return true
+        end
+    end
+    
+    return inEmbed
+end
+
+-- check is comment.
+inComment = false
+function isCommentLine(line)
+    if line:find("//") ~= nil then
+        return true
+    end
+    
+    if inComment then
+        if line:find("[*]/") ~= nil then
+            inComment = false
+            return true
+        end
+    else
+        if line:find("/[*]") ~= nil then
+            inComment = true
+            return true
+        end
+    end
+    return inComment
+end
+
+-- check is valid line.
+function isValidLine(line)
+    if #line < 2 then
+        return fasle
+    end
+   
+    if isEmbedLine(line) then
+        return false
+    end
+    
+    if isCommentLine(line) then
+        return false
+    end
+    
+    -- Declaration line.
+    if (string.find(line, "enum ")  ~= nil or string.find(line, "class ")  ~= nil or
+        string.find(line, "struct ") ~= nil ) and string.find(line, "}") ~= nil then
+        return false
+    end
+    
+    return true
+end
+
+local ENUM   = 1 -- line is enum code.
+local CLASS  = 2 -- line is class code.
+local GLOBAL = 3 -- line is global code.
+
+local type = GLOBAL -- current line type.
+
+function handleLine(line)
+    if type == ENUM then
+        if line:find("};") ~= nil then  -- end of enum.
+            type = GLOBAL
+        else
+            table.insert(enums, line)
+        end
+        return
+    end
+    
+    if type == CLASS then
+        if line:find("};") ~= nil then  -- end of class or struct.
+            type = GLOBAL
+        else
+            table.insert(classes, line)
+        end
+        return
+    end
+    
+    if type == GLOBAL then
+        if line:find("enum ") ~= nil then
+            type = ENUM
+            return
+        end
+        
+        if line:find("class ") ~= nil or line:find("struct ") ~= nil then -- begin of class or struct.
+            type = CLASS
+            table.insert(classes, line)
+            return
+        end
+        
+        if line:find(")") == nil then -- global function.
+            table.insert(globalConstants, line)
+        else
+            table.insert(globalFunctions, line)
+        end
+        
+        return
+    end
+end
+
+function handlePkgFile(pkgFile)
+    local file = io.open(pkgFile)
+    if file == nil then
+        return
+    end
+    
+    type = GLOBAL
+    
+    local line = file:read()
+    while line ~= nil do
+        line = trim(line)
+        if isValidLine(line) then
+            handleLine(line)
+        end
+        line = file:read()
+    end
+    file:close()
+end
+
+for _, pkgFile in ipairs(pkgFiles) do
+    handlePkgFile(pkgFile)
+end
+
+function writeGlobalFunctions(ofile)
+    ofile:write("\\section LuaScriptAPI_GlobalFunctions Global functions\n")
+    for _, line in ipairs(globalFunctions) do
+        line = line:gsub("%a @ ", "")
+        line = line:gsub(";", "")
+        ofile:write("- " .. line .. "\n")
+    end
+    
+    ofile:write("\n")
+end
+
+function writeGlobalConstants(ofile)
+    ofile:write("\\section LuaScriptAPI_GlobalConstants Global constants\n")
+    for _, line in ipairs(globalConstants) do
+        line = line:gsub("static ", "")
+        line = line:gsub("const ", "")
+        line = line:gsub(";", "")
+        ofile:write("- " .. line .. "\n")
+    end
+        
+    for _, line in ipairs(enums) do
+        line = line:gsub(",", "")
+        line = line:gsub(" = .*", "")
+        ofile:write("- int " .. line .. "\n")
+    end
+    
+    ofile:write("\n")
+end 
+
+function writeClasses(ofile)
+    ofile:write("\\section LuaScriptAPI_Classes Classes\n")
+    local firstProperty = true
+    for _, line in ipairs(classes) do
+        if line:find("class ") ~= nil or line:find("struct ") ~= nil then
+            line = line:gsub("class ", "")
+            line = line:gsub("struct ", "")
+            line = line:gsub("public ", "")
+            ofile:write("\n### " .. line .. "\n\nMethods:\n\n")
+            firstProperty = true
+        else
+            line = line:gsub(";", "")
+            if line:find(")") ~= nil then
+                line = line:gsub(" %w+ @ ", " ")
+                line = line:gsub("explicit ", "")
+                line = line:gsub("tolua_outside ", "")
+                ofile:write("- " .. line .. "\n")
+            else
+                if firstProperty then
+                    firstProperty = false
+                    ofile:write("\nProperties:\n\n")
+                end
+                line = line:gsub(" %w+_ @ ", " ")
+                line = line:gsub("tolua_property__get_set ", "")
+                line = line:gsub("tolua_property__is_set ", "")
+                line = line:gsub("tolua_property__has_set ", "")
+                line = line:gsub("tolua_property__no_prefix ", "")
+                if line:find("tolua_readonly") == nil then
+                    ofile:write("- " .. line .. "\n")
+                else
+                    line = line:gsub("tolua_readonly ", "")
+                    ofile:write("- " .. line .. " (readonly)\n")
+                end
+            end
+        end
+    end
+end
+
+ofile = io.open("LuaScriptAPI.dox", "w")
+ofile:write([[
+namespace Urho3D
+{
+
+/**
+\page LuaScriptAPI Lua Scripting API
+]])
+ofile:write("\n")
+
+writeGlobalFunctions(ofile)
+writeGlobalConstants(ofile)
+writeClasses(ofile)
+
+ofile:write([[
+*/
+
+}
+]])