Browse Source

Update Lua API, convert SharePtr to raw pointer.

aster2013 12 years ago
parent
commit
97eab8ecf5

+ 15 - 0
Source/Engine/LuaScript/pkgs/Graphics/Material.pkg

@@ -18,7 +18,10 @@ class Material : public Resource
     void SetDepthBias(const BiasParameters& parameters);
     void RemoveShaderParameter(const String name);
     void ReleaseShaders();
+    
     // SharedPtr<Material> Clone(const String cloneName = String::EMPTY) const;
+    tolua_outside Material* MaterialClone @ Clone(const String cloneName = String::EMPTY) const;
+    
     void SortTechniques();
     void MarkForAuxView(unsigned frameNumber);
     
@@ -57,4 +60,16 @@ static int tolua_GraphicsLuaAPI_Material_new00_local(lua_State* tolua_S)
 {
     return ToluaNewObjectGC<Material>(tolua_S);
 }
+
+static Material* MaterialClone(const Material* material, const String& cloneName = String::EMPTY)
+{
+    if (!material)
+        return 0;
+        
+    SharedPtr<Material> clonedMaterialPtr = material->Clone(cloneName);
+    Material* clonedMaterial = clonedMaterialPtr.Get();
+    clonedMaterialPtr.Detach();
+    
+    return clonedMaterial;
+}
 $}

+ 8 - 7
Source/Engine/LuaScript/pkgs/Graphics/RenderPath.pkg

@@ -31,14 +31,15 @@ class RenderPath
 };
 
 ${
-RenderPath* RenderPathClone(RenderPath* renderPath)
+static RenderPath* RenderPathClone(RenderPath* renderPath)
 {
-    if (renderPath == 0)
+    if (!renderPath)
         return 0;
-
-    RenderPath* newRenderPath = new RenderPath();
-    newRenderPath->renderTargets_ = renderPath->renderTargets_;
-    newRenderPath->commands_ = renderPath->commands_;
-    return newRenderPath;
+    
+    SharedPtr<RenderPath> clonedRenderPathPtr = renderPath->Clone();
+    RenderPath* clonedRenderPath = clonedRenderPathPtr.Get();
+    clonedRenderPathPtr.Detach();
+    
+    return clonedRenderPath;
 }
 $}

+ 12 - 10
Source/Engine/LuaScript/pkgs/Graphics/Texture2D.pkg

@@ -8,6 +8,8 @@ class Texture2D : public Texture
     ~Texture2D();
 
     bool SetSize(int width, int height, unsigned format, TextureUsage usage = TEXTURE_STATIC);
+
+    // bool Load(SharedPtr<Image> image, bool useAlpha = false);
     tolua_outside bool Texture2DLoad @ Load(Image* image, bool useAlpha = false);
 
     RenderSurface* GetRenderSurface() const;
@@ -16,16 +18,6 @@ class Texture2D : public Texture
 };
 
 ${
-static bool Texture2DLoad(Texture2D* texture, Image* image, bool useAlpha)
-{
-    SharedPtr<Image> imagePtr(image);
-    bool ret = texture->Load(imagePtr, useAlpha);
-    // Need to safely detach the object from the shared pointer so that the Lua script can manually
-    // delete the object once done
-    imagePtr.Detach();
-    return ret;
-}
-
 #define TOLUA_DISABLE_tolua_GraphicsLuaAPI_Texture2D_new00
 static int tolua_GraphicsLuaAPI_Texture2D_new00(lua_State* tolua_S)
 {
@@ -37,4 +29,14 @@ static int tolua_GraphicsLuaAPI_Texture2D_new00_local(lua_State* tolua_S)
 {
     return ToluaNewObjectGC<Texture2D>(tolua_S);
 }
+
+static bool Texture2DLoad(Texture2D* texture, Image* image, bool useAlpha)
+{
+    SharedPtr<Image> imagePtr(image);
+    bool ret = texture->Load(imagePtr, useAlpha);
+    // Need to safely detach the object from the shared pointer so that the Lua script can manually
+    // delete the object once done
+    imagePtr.Detach();
+    return ret;
+}
 $}

+ 0 - 14
Source/Engine/LuaScript/pkgs/Network/HttpRequest.pkg

@@ -24,17 +24,3 @@ class HttpRequest : public Deserializer
     tolua_readonly tolua_property__get_set unsigned availableSize;
     tolua_readonly tolua_property__is_set bool open;
 };
-
-class SharedPtr
-{
-    TOLUA_TEMPLATE_BIND(T, HttpRequest)
-    
-    SharedPtr();
-    ~SharedPtr();
-    
-    bool Null() const;
-    bool NotNull() const;
-    T* Get() const;
-};
-
-$renaming SharedPtr<HttpRequest> @ HttpRequestSPtr

+ 15 - 1
Source/Engine/LuaScript/pkgs/Network/Network.pkg

@@ -29,7 +29,9 @@ class Network
     
     void UnregisterAllRemoteEvents();
     void SetPackageCacheDir(const String path);
-    SharedPtr<HttpRequest> MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
+    
+    // SharedPtr<HttpRequest> MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
+    tolua_outside HttpRequest* NetworkMakeHttpRequest @ MakeHttpRequest(const String url, const String verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY);
     
     int GetUpdateFps() const;
     Connection* GetServerConnection() const;
@@ -57,4 +59,16 @@ static int tolua_NetworkLuaAPI_GetNetwork00(lua_State* tolua_S)
 
 #define TOLUA_DISABLE_tolua_get_network_ptr
 #define tolua_get_network_ptr tolua_NetworkLuaAPI_GetNetwork00
+
+static HttpRequest* NetworkMakeHttpRequest(Network* network, const String& url, const String& verb = String::EMPTY, const Vector<String>& headers = Vector<String>(), const String postData = String::EMPTY)
+{
+    if (!network)
+        return 0;
+
+    SharedPtr<HttpRequest> httpRequestPtr = network->MakeHttpRequest(url, verb, headers, postData);
+    HttpRequest* httpRequest = httpRequestPtr.Get();
+    httpRequestPtr.Detach();
+
+    return httpRequest;
+}
 $}

+ 9 - 10
Source/Engine/LuaScript/pkgs/Resource/ResourceCache.pkg

@@ -11,7 +11,9 @@ class ResourceCache
     void SetAutoReloadResources(bool enable);
     void SetSearchPackagesFirst(bool value);
 
+    // SharedPtr<File> GetFile(const String& name);
     tolua_outside File* ResourceCacheGetFile @ GetFile(const String name);
+
     Resource* GetResource(const String type, const String name);
     
     bool Exists(const String name) const;
@@ -47,17 +49,14 @@ static int tolua_ResourceLuaAPI_GetCache00(lua_State* tolua_S)
 
 static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
 {
-    SharedPtr<File> file = cache->GetFile(fileName);
-    if (!file)
+    SharedPtr<File> filePtr = cache->GetFile(fileName);
+    if (!filePtr)
         return 0;
-    else
-    {
-        // Need to safely detach the object from the shared pointer so that the Lua script can manually
-        // delete the object once done. The refcount needs to be zero or else the destructor will assert
-        File* fileRaw = file.Get();
-        file.Detach();
-        return fileRaw;
-    }
+
+    File* file = filePtr.Get();
+    filePtr.Detach();
+    
+    return file;
 }
 
 // Disable generated GetResource function.