Kaynağa Gözat

Convert all Vector<T> and PODVector<T> to Lua table.

aster2013 12 yıl önce
ebeveyn
işleme
38c8f19fb4

+ 3 - 2
Bin/Data/LuaScripts/15_Navigation.lua

@@ -328,10 +328,11 @@ function HandlePostRenderUpdate(eventType, eventData)
         debug:AddBoundingBox(BoundingBox(endPos - Vector3(0.1, 0.1, 0.1), endPos + Vector3(0.1, 0.1, 0.1)), Color(1.0, 1.0, 1.0))
     end
     
-    if currentPath ~= nil and currentPath:Size() > 0 then
+    if currentPath ~= nil then
         -- Draw the path with a small upward bias so that it does not clip into the surfaces
         local bias = Vector3(0.0, 0.05, 0.0)
-        for i = 0, currentPath:Size() - 2 do
+        local size = table.maxn(currentPath)
+        for i = 1, size - 1 do
             debug:AddLine(currentPath[i] + bias, currentPath[i + 1] + bias, Color(1.0, 1.0, 1.0))
         end
     end

+ 10 - 51
Docs/LuaScriptAPI.dox

@@ -147,47 +147,6 @@ Properties:
 - float outerAngle
 - float rolloffFactor
 
-### PODVector
-
-Methods:
-
-- TOLUA_TEMPLATE_BIND(T, Vector3, OctreeQueryResult, RayQueryResult, PhysicsRaycastResult)
-- PODVector()
-- PODVector(const PODVector<T>& vector)
-- ~PODVector()
-- PODVector<T> operator + (const T& rhs) const
-- PODVector<T> operator + (const PODVector<T>& rhs) const
-- bool operator == (const PODVector<T>& rhs) const
-- T& operator [] (unsigned index)
-- const T& operator [] (unsigned index) const
-- T& At(unsigned index)
-- const T& At(unsigned index) const
-- void Push(const T& value)
-- void Push(const PODVector<T>& vector)
-- void Pop()
-- void Insert(unsigned pos, const T& value)
-- void Insert(unsigned pos, const PODVector<T>& vector)
-- void Erase(unsigned pos, unsigned length = 1)
-- bool Remove(const T& value)
-- void Clear()
-- void Resize(unsigned newSize)
-- void Reserve(unsigned newCapacity)
-- void Compact()
-- bool Contains(const T& value) const
-- T& Front()
-- const T& Front() const
-- T& Back()
-- const T& Back() const
-- unsigned Size() const
-- unsigned Capacity() const
-- bool Empty() const
-
-Properties:
-
-- unsigned size (readonly)
-- unsigned capacity (readonly)
-- bool empty (readonly)
-
 ### Context
 
 Methods:
@@ -1162,11 +1121,11 @@ Methods:
 - void Update(const FrameInfo& frame)
 - void AddManualDrawable(Drawable* drawable)
 - void RemoveManualDrawable(Drawable* drawable)
-- PODVector<OctreeQueryResult> GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
-- PODVector<OctreeQueryResult> GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
-- PODVector<OctreeQueryResult> GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
-- PODVector<OctreeQueryResult> GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
-- PODVector<RayQueryResult> Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const
+- const PODVector<OctreeQueryResult>& GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
+- const PODVector<OctreeQueryResult>& GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
+- const PODVector<OctreeQueryResult>& GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
+- const PODVector<OctreeQueryResult>& GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const
+- const PODVector<RayQueryResult>& Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const
 - RayQueryResult RaycastSingle(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const
 - unsigned GetNumLevels() const
 - void QueueUpdate(Drawable* drawable)
@@ -3053,7 +3012,7 @@ Methods:
 - bool Build(const BoundingBox& boundingBox)
 - Vector3 FindNearestPoint(const Vector3& point, const Vector3& extents = Vector3::ONE)
 - Vector3 MoveAlongSurface(const Vector3& start, const Vector3& end, const Vector3& extents=Vector3::ONE, int maxVisited=3)
-- PODVector<Vector3> FindPath(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE)
+- const PODVector<Vector3>& FindPath(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE)
 - Vector3 GetRandomPoint()
 - Vector3 GetRandomPointInCircle(const Vector3& center, float radius, const Vector3& extents = Vector3::ONE)
 - float GetDistanceToWall(const Vector3& point, float radius, const Vector3& extents = Vector3::ONE)
@@ -3408,7 +3367,7 @@ Methods:
 - void SetInternalEdge(bool enable)
 - void SetSplitImpulse(bool enable)
 - void SetMaxNetworkAngularVelocity(float velocity)
-- PODVector<PhysicsRaycastResult> Raycast(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
+- const PODVector<PhysicsRaycastResult>& Raycast(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
 - PhysicsRaycastResult RaycastSingle(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
 - PhysicsRaycastResult SphereCast(const Ray& ray, float radius, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
 - void DrawDebugGeometry(bool depthTest)
@@ -5499,9 +5458,9 @@ Properties:
 - int DRAG_RESIZE_LEFT
 
 \section LuaScriptAPI_RenameTypes Rename types
-- PODVector<PhysicsRaycastResult> becomes PhysicsRaycastResultVector
-- PODVector<OctreeQueryResult> becomes OctreeQueryResultVector
-- PODVector<RayQueryResult> becomes RayQueryResultVector
+- const PODVector<PhysicsRaycastResult>& becomes PhysicsRaycastResultVector
+- const PODVector<OctreeQueryResult>& becomes OctreeQueryResultVector
+- const PODVector<RayQueryResult>& becomes RayQueryResultVector
 - SharedPtr<HttpRequest> becomes HttpRequestSPtr
 
 */

+ 0 - 57
Source/Engine/LuaScript/pkgs/Container/Vector.pkg

@@ -1,57 +0,0 @@
-$#include "Vector.h"
-$#include "Vector3.h"
-$#include "OctreeQuery.h"
-$#include "PhysicsWorld.h"
-
-class PODVector
-{
-    TOLUA_TEMPLATE_BIND(T, Vector3, OctreeQueryResult, RayQueryResult, PhysicsRaycastResult)
-    
-    PODVector();
-    PODVector(const PODVector<T>& vector);
-    ~PODVector();
-    
-    PODVector<T> operator + (const T& rhs) const;
-    PODVector<T> operator + (const PODVector<T>& rhs) const;
-    
-    bool operator == (const PODVector<T>& rhs) const;
-    
-    T& operator [] (unsigned index);
-    const T& operator [] (unsigned index) const;
-    T& At(unsigned index);
-    const T& At(unsigned index) const;
-    
-    void Push(const T& value);
-    void Push(const PODVector<T>& vector);
-    void Pop();
-    
-    void Insert(unsigned pos, const T& value);
-    void Insert(unsigned pos, const PODVector<T>& vector);
-    void Erase(unsigned pos, unsigned length = 1);
-    
-    bool Remove(const T& value);
-    void Clear();
-    
-    void Resize(unsigned newSize);
-    void Reserve(unsigned newCapacity);
-    void Compact();
-    
-    bool Contains(const T& value) const;
-    
-    T& Front();
-    const T& Front() const;
-    T& Back();
-    const T& Back() const;
-    
-    unsigned Size() const;
-    unsigned Capacity() const;
-    bool Empty() const;
-    
-    tolua_readonly tolua_property__no_prefix unsigned size;
-    tolua_readonly tolua_property__no_prefix unsigned capacity;
-    tolua_readonly tolua_property__no_prefix bool empty;
-};
-
-$renaming PODVector<OctreeQueryResult> @ OctreeQueryResultVector
-$renaming PODVector<RayQueryResult> @ RayQueryResultVector
-$renaming PODVector<PhysicsRaycastResult> @ PhysicsRaycastResultVector

+ 0 - 2
Source/Engine/LuaScript/pkgs/ContainerLuaAPI.pkg

@@ -1,4 +1,2 @@
-$pfile "Container/Vector.pkg"
-
 $using namespace Urho3D;
 $#pragma warning(disable:4800)

+ 20 - 15
Source/Engine/LuaScript/pkgs/Graphics/Octree.pkg

@@ -8,13 +8,13 @@ class Octree : public Component
     void RemoveManualDrawable(Drawable* drawable);
 
     // void GetDrawables(OctreeQuery& query) const;
-    tolua_outside PODVector<OctreeQueryResult> OctreeGetDrawablesPoint @ GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
-    tolua_outside PODVector<OctreeQueryResult> OctreeGetDrawablesBoundingBox @ GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
-    tolua_outside PODVector<OctreeQueryResult> OctreeGetDrawablesFrustum @ GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
-    tolua_outside PODVector<OctreeQueryResult> OctreeGetDrawablesSphere @ GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
+    tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint @ GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
+    tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox @ GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
+    tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum @ GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
+    tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere @ GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
 
     // void Raycast(RayOctreeQuery& query) const;
-    tolua_outside PODVector<RayQueryResult> OctreeRaycast @ Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const;
+    tolua_outside const PODVector<RayQueryResult>& OctreeRaycast @ Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const;
     // void RaycastSingle(RayOctreeQuery& query) const;
     tolua_outside RayQueryResult OctreeRaycastSingle @ RaycastSingle(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags) const;
     
@@ -27,13 +27,14 @@ class Octree : public Component
 };
 
 ${
-static PODVector<OctreeQueryResult> OctreeGetDrawablesPoint(const Octree* octree, const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
+static const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint(const Octree* octree, const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
 {
     PODVector<Drawable*> drawableResult;
     PointOctreeQuery query(drawableResult, point, drawableFlags, viewMask);
     octree->GetDrawables(query);
     
-    PODVector<OctreeQueryResult> result(drawableResult.Size());
+    static PODVector<OctreeQueryResult> result;
+    result.Resize(drawableResult.Size());
     for (unsigned i = 0; i < drawableResult.Size(); ++i)
     {
         result[i].drawable_ = drawableResult[i];
@@ -42,13 +43,14 @@ static PODVector<OctreeQueryResult> OctreeGetDrawablesPoint(const Octree* octree
     return result;
 }
 
-static PODVector<OctreeQueryResult> OctreeGetDrawablesBoundingBox(const Octree* octree, const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
+static const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox(const Octree* octree, const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
 {
     PODVector<Drawable*> drawableResult;
     BoxOctreeQuery query(drawableResult, box, drawableFlags, viewMask);
     octree->GetDrawables(query);
 
-    PODVector<OctreeQueryResult> result(drawableResult.Size());
+    static PODVector<OctreeQueryResult> result;
+    result.Resize(drawableResult.Size());
     for (unsigned i = 0; i < drawableResult.Size(); ++i)
     {
         result[i].drawable_ = drawableResult[i];
@@ -57,13 +59,14 @@ static PODVector<OctreeQueryResult> OctreeGetDrawablesBoundingBox(const Octree*
     return result;
 }
 
-static PODVector<OctreeQueryResult> OctreeGetDrawablesFrustum(const Octree* octree, const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
+static const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum(const Octree* octree, const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
 {
     PODVector<Drawable*> drawableResult;
     FrustumOctreeQuery query(drawableResult, frustum, drawableFlags, viewMask);
     octree->GetDrawables(query);
 
-    PODVector<OctreeQueryResult> result(drawableResult.Size());
+    static PODVector<OctreeQueryResult> result;
+    result.Resize(drawableResult.Size());
     for (unsigned i = 0; i < drawableResult.Size(); ++i)
     {
         result[i].drawable_ = drawableResult[i];
@@ -72,13 +75,14 @@ static PODVector<OctreeQueryResult> OctreeGetDrawablesFrustum(const Octree* octr
     return result;
 }
 
-static PODVector<OctreeQueryResult> OctreeGetDrawablesSphere(const Octree* octree, const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
+static const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere(const Octree* octree, const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
 {
     PODVector<Drawable*> drawableResult;
     SphereOctreeQuery query(drawableResult, sphere, drawableFlags, viewMask);
     octree->GetDrawables(query);
 
-    PODVector<OctreeQueryResult> result(drawableResult.Size());
+    static PODVector<OctreeQueryResult> result;
+    result.Resize(drawableResult.Size());
     for (unsigned i = 0; i < drawableResult.Size(); ++i)
     {
         result[i].drawable_ = drawableResult[i];
@@ -105,9 +109,10 @@ static RayQueryResult OctreeRaycastSingle(const Octree* octree, const Ray& ray,
     }
 }
 
-static PODVector<RayQueryResult> OctreeRaycast(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags)
+static const PODVector<RayQueryResult>& OctreeRaycast(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags)
 {
-    PODVector<RayQueryResult> result;
+    static PODVector<RayQueryResult> result;
+    result.Clear();
     RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags);
     octree->Raycast(query);
     return result;

+ 4 - 3
Source/Engine/LuaScript/pkgs/Navigation/NavigationMesh.pkg

@@ -31,7 +31,7 @@ class NavigationMesh : public Component
     Vector3 FindNearestPoint(const Vector3& point, const Vector3& extents = Vector3::ONE);
     Vector3 MoveAlongSurface(const Vector3& start, const Vector3& end, const Vector3& extents=Vector3::ONE, int maxVisited=3);
     // void FindPath(PODVector<Vector3>& dest, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE);
-    tolua_outside PODVector<Vector3> NavigationMeshFindPath @ FindPath(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE);
+    tolua_outside const PODVector<Vector3>& NavigationMeshFindPath @ FindPath(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE);
     
     Vector3 GetRandomPoint();
     
@@ -80,9 +80,10 @@ class NavigationMesh : public Component
 };
 
 ${
-PODVector<Vector3> NavigationMeshFindPath(NavigationMesh* navMesh, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE)
+const PODVector<Vector3>& NavigationMeshFindPath(NavigationMesh* navMesh, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE)
 {
-    PODVector<Vector3> dest;
+    static PODVector<Vector3> dest;
+    dest.Clear();
     navMesh->FindPath(dest, start, end, extents);
     return dest;
 }

+ 4 - 3
Source/Engine/LuaScript/pkgs/Physics/PhysicsWorld.pkg

@@ -22,7 +22,7 @@ class PhysicsWorld : public Component
     void SetMaxNetworkAngularVelocity(float velocity);
 
     // void Raycast(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
-    tolua_outside PODVector<PhysicsRaycastResult> PhysicsWorldRaycast @ Raycast(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
+    tolua_outside const PODVector<PhysicsRaycastResult>& PhysicsWorldRaycast @ Raycast(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
 
     // void RaycastSingle(PhysicsRaycastResult& result, const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
     tolua_outside PhysicsRaycastResult PhysicsWorldRaycastSingle @ RaycastSingle(const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
@@ -52,9 +52,10 @@ class PhysicsWorld : public Component
 };
 
 ${
-static PODVector<PhysicsRaycastResult> PhysicsWorldRaycast(PhysicsWorld* physicsWorld, const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
+static const PODVector<PhysicsRaycastResult>& PhysicsWorldRaycast(PhysicsWorld* physicsWorld, const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED)
 {
-    PODVector<PhysicsRaycastResult> result;
+    static PODVector<PhysicsRaycastResult> result;
+    result.Clear();
     physicsWorld->Raycast(result, ray, maxDistance, collisionMask);
     return result;
 }

+ 50 - 16
Source/Engine/LuaScript/pkgs/basic.lua

@@ -3,22 +3,6 @@ local currentString = ''
 local out
 local WRITE, OUTPUT = write, output
 
-_is_functions["const PODVector<IntVector2>"] = "not implemented"
-_to_functions["const PODVector<IntVector2>"] = "not implemented"
-_push_functions["const PODVector<IntVector2>"] = "tolua_pushurho3dconstpodvectorintvector2"
-
-_is_functions["const PODVector<UIElement*>"] = "not implemented"
-_to_functions["const PODVector<UIElement*>"] = "not implemented"
-_push_functions["const PODVector<UIElement*>"] = "tolua_pushurho3dpodvectoruielement"
-
-_is_functions["const PODVector<unsigned>"] = "tolua_isurho3dconstpodvectorunsigned"
-_to_functions["const PODVector<unsigned>"] = "tolua_tourho3dconstpodvectorunsigned"
-_push_functions["const PODVector<unsigned>"] = "tolua_pushurho3dconstpodvectorunsigned"
-
-_is_functions["const Vector<String>"] = "tolua_isurho3dconstvectorstring"
-_to_functions["const Vector<String>"] = "tolua_tourho3dconstvectorstring"
-_push_functions["const Vector<String>"] = "tolua_pushurho3dconstvectorstring"
-
 function output(s)
     out = _OUTPUT
     output = OUTPUT -- restore
@@ -91,6 +75,56 @@ function post_output_hook(package)
     WRITE(result)
 end
 
+-- Is Urho3D Vector type.
+function urho3d_is_vector(t)
+    return t:find("Vector<") ~= nil
+end
+
+-- Is Urho3D PODVector type.
+function urho3d_is_podvector(t)
+    return t:find("PODVector<") ~= nil
+end
+
+local old_get_push_function = get_push_function
+local old_get_to_function = get_to_function
+local old_get_is_function = get_is_function
+
+function get_push_function(t)
+    if not urho3d_is_vector(t) then
+        return old_get_push_function(t)
+    end
+    
+    if not urho3d_is_podvector(t) then
+        return "tolua_pushurho3dvector" .. t:match("<.*>")
+    else
+        return "tolua_pushurho3dpodvector" .. t:match("<.*>")
+    end
+end
+
+function get_to_function(t)
+    if not urho3d_is_vector(t) then
+        return old_get_to_function(t)
+    end
+    
+    if not urho3d_is_podvector(t) then
+        return "tolua_tourho3dvector" .. t:match("<.*>")
+    else
+        return "tolua_tourho3dpodvector" .. t:match("<.*>")
+    end
+end
+
+function get_is_function(t)
+    if not urho3d_is_vector(t) then
+        return old_get_is_function(t)
+    end
+    
+    if not urho3d_is_podvector(t) then
+        return "tolua_isurho3dvector" .. t:match("<.*>")
+    else
+        return "tolua_isurho3dpodvector" .. t:match("<.*>")
+    end
+end
+
 function get_property_methods_hook(ptype, name)
     if ptype == "get_set" then
         local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)

+ 144 - 71
Source/Engine/LuaScript/tolua++urho3d.cpp

@@ -25,55 +25,18 @@
 #include "tolua++.h"
 #include "tolua++urho3d.h"
 
-const char* tolua_tourho3dstring(lua_State* L, int narg, const char* def)
+const char* tolua_tourho3dstring(lua_State* L, int narg, const char* str)
 {
-    const char* s = tolua_tostring(L, narg, def);
+    const char* s = tolua_tostring(L, narg, str);
     return s ? s : "";
 }
 
-const char* tolua_tourho3dstring(lua_State* L, int narg, const String& def)
+const char* tolua_tourho3dstring(lua_State* L, int narg, const String& str)
 {
-    return tolua_tourho3dstring(L, narg, def.CString());
+    return tolua_tourho3dstring(L, narg, str.CString());
 }
 
-int tolua_pushurho3dconstpodvectorintvector2(lua_State* L, void* data, const char* type)
-{
-#ifndef TOLUA_RELEASE
-    assert(strcmp(type, "const PODVector<IntVector2>") == 0);
-#endif
-
-    const PODVector<IntVector2>& vector = *((const PODVector<IntVector2>*)data);
-    lua_newtable(L);
-    for (unsigned i = 0; i < vector.Size(); ++i)
-    {
-        void* tolua_obj = Mtolua_new((IntVector2)(vector[i]));
-        tolua_pushusertype(L,tolua_obj,"IntVector2");
-        tolua_register_gc(L,lua_gettop(L));
-
-        lua_rawseti(L, -2, i + 1);
-    }
-
-    return 1;
-}
-
-int tolua_pushurho3dpodvectoruielement(lua_State* L, void* data, const char* type)
-{
-#ifndef TOLUA_RELEASE
-    assert(strcmp(type, "const PODVector<UIElement*>") == 0);
-#endif
-
-    const PODVector<UIElement*>& vector = *((const PODVector<UIElement*>*)data);
-    lua_newtable(L);
-    for (unsigned i = 0; i < vector.Size(); ++i)
-    {
-        tolua_pushusertype(L, vector[i], "UIElement");
-        lua_rawseti(L, -2, i + 1);
-    }
-
-    return 1;
-}
-
-int tolua_isurho3dconstpodvectorunsigned(lua_State* L, int lo, const char* type, int def, tolua_Error* err)
+template<> int tolua_isurho3dvector<String>(lua_State* L, int lo, const char* type, int def, tolua_Error* err)
 {
     if (lua_istable(L, lo))
     {
@@ -82,7 +45,7 @@ int tolua_isurho3dconstpodvectorunsigned(lua_State* L, int lo, const char* type,
         {
             lua_pushinteger(L, i);
             lua_gettable(L, lo);
-            if (!lua_isnumber(L, -1))
+            if (!lua_isstring(L, -1))
             {
                 lua_pop(L, 1);
 
@@ -105,12 +68,12 @@ int tolua_isurho3dconstpodvectorunsigned(lua_State* L, int lo, const char* type,
     return 0;
 }
 
-void* tolua_tourho3dconstpodvectorunsigned(lua_State* L, int narg, void* def)
+template<> void* tolua_tourho3dvector<String>(lua_State* L, int narg, void* def)
 {
     if (!lua_istable(L, narg))
         return 0;
 
-    static Vector<unsigned> result;
+    static Vector<String> result;
     result.Clear();
 
     int length = lua_objlen(L, narg);
@@ -119,14 +82,14 @@ void* tolua_tourho3dconstpodvectorunsigned(lua_State* L, int narg, void* def)
         lua_pushinteger(L, i);
         lua_gettable(L, narg);
 
-        if (!lua_isnumber(L, -1))
+        if (!lua_isstring(L, -1))
         {
             lua_pop(L, 1);
             return 0;
         }
 
-        unsigned value = (unsigned)tolua_tonumber(L, -1, 0);
-        result.Push(value);
+        String string = tolua_tourho3dstring(L, -1, "");
+        result.Push(string);
 
         lua_pop(L, 1);
     }
@@ -134,24 +97,19 @@ void* tolua_tourho3dconstpodvectorunsigned(lua_State* L, int narg, void* def)
     return &result;
 }
 
-int tolua_pushurho3dconstpodvectorunsigned(lua_State* L, void* data, const char* type)
+template<> int tolua_pushurho3dvector<String>(lua_State* L, void* data, const char* type)
 {
-#ifndef TOLUA_RELEASE
-    assert(strcmp(type, "const PODVector<unsigned>") == 0);
-#endif
-
-    const PODVector<unsigned>& vector = *((const PODVector<unsigned>*)data);
+    const Vector<String>& vectorstring = *((const Vector<String>*)data);
     lua_newtable(L);
-    for (unsigned i = 0; i < vector.Size(); ++i)
+    for (unsigned i = 0; i < vectorstring.Size(); ++i)
     {
-        lua_pushinteger(L, vector[i]);
+        tolua_pushurho3dstring(L, vectorstring[i]);
         lua_rawseti(L, -2, i + 1);
     }
-
     return 1;
 }
 
-int tolua_isurho3dconstvectorstring(lua_State* L, int lo, const char* type, int def, tolua_Error* err)
+template<> int tolua_isurho3dpodvector<unsigned>(lua_State* L, int lo, const char* type, int def, tolua_Error* err)
 {
     if (lua_istable(L, lo))
     {
@@ -160,7 +118,7 @@ int tolua_isurho3dconstvectorstring(lua_State* L, int lo, const char* type, int
         {
             lua_pushinteger(L, i);
             lua_gettable(L, lo);
-            if (!lua_isstring(L, -1))
+            if (!lua_isnumber(L, -1))
             {
                 lua_pop(L, 1);
 
@@ -183,12 +141,12 @@ int tolua_isurho3dconstvectorstring(lua_State* L, int lo, const char* type, int
     return 0;
 }
 
-void* tolua_tourho3dconstvectorstring(lua_State* L, int narg, void* def)
+template<> void* tolua_tourho3dpodvector<unsigned>(lua_State* L, int narg, void* def)
 {
     if (!lua_istable(L, narg))
         return 0;
 
-    static Vector<String> result;
+    static Vector<unsigned> result;
     result.Clear();
 
     int length = lua_objlen(L, narg);
@@ -197,14 +155,14 @@ void* tolua_tourho3dconstvectorstring(lua_State* L, int narg, void* def)
         lua_pushinteger(L, i);
         lua_gettable(L, narg);
 
-        if (!lua_isstring(L, -1))
+        if (!lua_isnumber(L, -1))
         {
             lua_pop(L, 1);
             return 0;
         }
 
-        String string = tolua_tourho3dstring(L, -1, "");
-        result.Push(string);
+        unsigned value = (unsigned)tolua_tonumber(L, -1, 0);
+        result.Push(value);
 
         lua_pop(L, 1);
     }
@@ -212,19 +170,134 @@ void* tolua_tourho3dconstvectorstring(lua_State* L, int narg, void* def)
     return &result;
 }
 
-int tolua_pushurho3dconstvectorstring(lua_State*L, void* data, const char* type)
+template<> int tolua_pushurho3dpodvector<int>(lua_State* L, void* data, const char* type)
 {
-#ifndef TOLUA_RELEASE
-    assert(strcmp(type, "const Vector<String>") == 0);
-#endif
+    const PODVector<int>& vector = *((const PODVector<int>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        lua_pushinteger(L, vector[i]);
+        lua_rawseti(L, -2, i + 1);
+    }
 
-    const Vector<String>& vectorstring = *((const Vector<String>*)data);
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<IntVector2>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<IntVector2>& vector = *((const PODVector<IntVector2>*)data);
     lua_newtable(L);
-    for (unsigned i = 0; i < vectorstring.Size(); ++i)
+    for (unsigned i = 0; i < vector.Size(); ++i)
     {
-        tolua_pushurho3dstring(L, vectorstring[i]);
+        void* tolua_obj = Mtolua_new((IntVector2)(vector[i]));
+        tolua_pushusertype(L,tolua_obj,"IntVector2");
+        tolua_register_gc(L,lua_gettop(L));
+
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<OctreeQueryResult>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<OctreeQueryResult>& vector = *((const PODVector<OctreeQueryResult>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        void* tolua_obj = Mtolua_new((OctreeQueryResult)(vector[i]));
+        tolua_pushusertype(L,tolua_obj,"OctreeQueryResult");
+        tolua_register_gc(L,lua_gettop(L));
+
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<PhysicsRaycastResult>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<PhysicsRaycastResult>& vector = *((const PODVector<PhysicsRaycastResult>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        void* tolua_obj = Mtolua_new((PhysicsRaycastResult)(vector[i]));
+        tolua_pushusertype(L,tolua_obj,"PhysicsRaycastResult");
+        tolua_register_gc(L,lua_gettop(L));
+
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<RayQueryResult>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<RayQueryResult>& vector = *((const PODVector<RayQueryResult>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        void* tolua_obj = Mtolua_new((RayQueryResult)(vector[i]));
+        tolua_pushusertype(L,tolua_obj,"RayQueryResult");
+        tolua_register_gc(L,lua_gettop(L));
+
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<UIElement*>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<UIElement*>& vector = *((const PODVector<UIElement*>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        tolua_pushusertype(L, vector[i], "UIElement");
+        lua_rawseti(L, -2, i + 1);
+    }
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<unsigned>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<unsigned>& vector = *((const PODVector<unsigned>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        lua_pushinteger(L, vector[i]);
         lua_rawseti(L, -2, i + 1);
     }
+
     return 1;
 }
 
+template<typename T> int PushPODVector(lua_State* L, const PODVector<T>& vector, const char* type)
+{
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        void* tolua_obj = Mtolua_new((T)(vector[i]));
+        tolua_pushusertype(L, tolua_obj, type);
+        tolua_register_gc(L, lua_gettop(L));
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}
+
+template<> int tolua_pushurho3dpodvector<Vector3>(lua_State* L, void* data, const char* type)
+{
+    const PODVector<Vector3>& vector = *((const PODVector<Vector3>*)data);
+    lua_newtable(L);
+    for (unsigned i = 0; i < vector.Size(); ++i)
+    {
+        void* tolua_obj = Mtolua_new((Vector3)(vector[i]));
+        tolua_pushusertype(L,tolua_obj,"Vector3");
+        tolua_register_gc(L,lua_gettop(L));
+
+        lua_rawseti(L, -2, i + 1);
+    }
+
+    return 1;
+}

+ 50 - 22
Source/Engine/LuaScript/tolua++urho3d.h

@@ -22,7 +22,10 @@
 
 #pragma once
 
+#include "OctreeQuery.h"
+#include "PhysicsWorld.h"
 #include "Vector2.h"
+#include "Vector3.h"
 
 struct lua_State;
 
@@ -38,25 +41,50 @@ using namespace Urho3D;
 /// Push String.
 #define tolua_pushurho3dstring(x, y) tolua_pushstring(x, y.CString())
 /// Convert to String.
-const char* tolua_tourho3dstring(lua_State* L, int narg, const char* def);
-const char* tolua_tourho3dstring(lua_State* L, int narg, const String& def);
-
-/// Push const PODVector<IntVector2>.
-int tolua_pushurho3dconstpodvectorintvector2(lua_State* L, void* data, const char* type);
-
-/// Push const PODVector<UIElement*>.
-int tolua_pushurho3dpodvectoruielement(lua_State* L, void* data, const char* type);
-
-/// Check is const PODVector<unsigned>.
-int tolua_isurho3dconstpodvectorunsigned(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
-/// Convert to const PODVector<unsigned>.
-void* tolua_tourho3dconstpodvectorunsigned(lua_State* L, int narg, void* def);
-/// Push const PODVector<unsigned>.
-int tolua_pushurho3dconstpodvectorunsigned(lua_State* L, void* data, const char* type);
-
-/// Check is const Vector<String>.
-int tolua_isurho3dconstvectorstring(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
-/// Convert to const Vector<String>.
-void* tolua_tourho3dconstvectorstring(lua_State* L, int narg, void* def);
-/// Push const Vector<String>.
-int tolua_pushurho3dconstvectorstring(lua_State* L, void* data, const char* type);
+const char* tolua_tourho3dstring(lua_State* L, int narg, const char* str);
+/// Convert to String.
+const char* tolua_tourho3dstring(lua_State* L, int narg, const String& str);
+
+/// Check Lua table is Vector<T>.
+template<typename T> int tolua_isurho3dvector(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
+/// Check Lua table is Vector<String>.
+template<> int tolua_isurho3dvector<String>(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
+
+/// Convert Lua  table to Vector<T>.
+template<typename T> void* tolua_tourho3dvector(lua_State* L, int narg, void* def);
+/// Convert Lua  table to Vector<String>.
+template<> void* tolua_tourho3dvector<String>(lua_State* L, int narg, void* def);
+
+/// Push Vector<T> to Lua as a table.
+template<typename T> int tolua_pushurho3dvector(lua_State*L, void* data, const char* type);
+/// Push Vector<String> to Lua as a table.
+template<> int tolua_pushurho3dvector<String>(lua_State* L, void* data, const char* type);
+
+/// Check Lua table is Vector<T>.
+template<typename T> int tolua_isurho3dpodvector(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
+/// Check Lua table is Vector<unsigned>.
+template<> int tolua_isurho3dpodvector<unsigned>(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
+
+/// Convert Lua  table to PODVector<T>.
+template<typename T> void* tolua_tourho3dpodvector(lua_State* L, int narg, void* def);
+/// Convert Lua  table to PODVector<unsigned>.
+template<> void* tolua_tourho3dpodvector<unsigned>(lua_State* L, int narg, void* def);
+
+/// Push PODVector<T> to Lua as a table.
+template<typename T> int tolua_pushurho3dpodvector(lua_State* L, void* data, const char* type);
+/// Push PODVector<int> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<int>(lua_State* L, void* data, const char* type);
+/// Push PODVector<IntVector2> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<IntVector2>(lua_State* L, void* data, const char* type);
+/// Push PODVector<OctreeQueryResult> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<OctreeQueryResult>(lua_State* L, void* data, const char* type);
+/// Push PODVector<PhysicsRaycastResult> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<PhysicsRaycastResult>(lua_State* L, void* data, const char* type);
+/// Push PODVector<RayQueryResult> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<RayQueryResult>(lua_State* L, void* data, const char* type);
+/// Push PODVector<UIElement*> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<UIElement*>(lua_State* L, void* data, const char* type);
+/// Push PODVector<unsigned> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<unsigned>(lua_State* L, void* data, const char* type);
+/// Push PODVector<Vector3> to Lua as a table.
+template<> int tolua_pushurho3dpodvector<Vector3>(lua_State* L, void* data, const char* type);