q66 pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=47a41298a339bc0681263697cbfc97526ca403ef

commit 47a41298a339bc0681263697cbfc97526ca403ef
Author: Daniel Kolesa <d.kol...@samsung.com>
Date:   Thu Oct 2 14:25:08 2014 +0100

    elua: initial/incomplete support for constructors in lualian
---
 src/bin/elua/modules/lualian.lua | 54 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/bin/elua/modules/lualian.lua b/src/bin/elua/modules/lualian.lua
index 1e97b4c..b591c19 100644
--- a/src/bin/elua/modules/lualian.lua
+++ b/src/bin/elua/modules/lualian.lua
@@ -403,6 +403,7 @@ local Class = Node:clone {
         local mname = gen_ns(self.klass, s)
 
         s:write("__body = {\n")
+        self:gen_ctor(s)
         self:gen_children(s)
         s:write("}\n")
 
@@ -414,7 +415,58 @@ end
 ]]):format(mname, self.klass:name_get()))
     end,
 
-    gen_ffi = Mixin.gen_ffi
+    gen_ffi = Mixin.gen_ffi,
+
+    gen_ctor = function(self, s)
+        local ctors = self.klass:constructors_get()
+        if not ctors then return end
+        -- collect constructor information
+        local ftp = eolian.function_type
+        s:write("    __eo_ctor = function(")
+        local cfuncs, parnames = {}, {}
+        for ctor in ctors do
+            local cfunc = ctor:function_get()
+            local tp = cfunc:type_get()
+            if tp == ftp.PROPERTY or tp == ftp.PROP_SET or tp == ftp.METHOD 
then
+                cfuncs[#cfuncs + 1] = cfunc
+                if tp ~= ftp.METHOD then
+                    for par in cfunc:property_keys_get() do
+                        parnames[#parnames + 1] = par:name_get()
+                    end
+                end
+                for par in cfunc:parameters_get() do
+                    parnames[#parnames + 1] = par:name_get()
+                end
+            end
+        end
+        s:write(table.concat(parnames, ", "))
+        s:write(")\n")
+        -- write ctor body
+        for i, cfunc in ipairs(cfuncs) do
+            s:write("        self:__raw_", cfunc:name_get())
+            if cfunc:type_get() ~= ftp.METHOD then
+                s:write("_set")
+            end
+            s:write("(")
+            local fpars = {}
+            if cfunc:type_get() ~= ftp.METHOD then
+                for par in cfunc:property_keys_get() do
+                    fpars[#fpars + 1] = par:name_get()
+                end
+            end
+            for par in cfunc:parameters_get() do
+                fpars[#fpars + 1] = par:name_get()
+            end
+            s:write(table.concat(fpars, ", "))
+            s:write(")\n")
+        end
+        s:write("    end")
+        if #self.children > 0 then
+            s:write(",\n\n")
+        else
+            s:write("\n")
+        end
+    end
 }
 
 local File = Node:clone {

-- 


Reply via email to