elua: basic constructor generation in lualian
authorDaniel Kolesa <quaker66@gmail.com>
Tue, 22 Apr 2014 14:44:33 +0000 (15:44 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:48 +0000 (15:48 +0100)
src/bin/elua/modules/lualian.lua

index 9d333f5..207b3a6 100644 (file)
@@ -205,21 +205,15 @@ local Method = Node:clone {
 
     generate = function(self, s, last)
         local proto = self:gen_proto()
-        local lproto = {
-            "    ", proto.name, proto.suffix or "", " = function(",
-            table.concat(proto.args, ", "), ")\n"
-        }
-        s:write(table.concat(lproto))
+        s:write("    ", proto.name, proto.suffix or "", " = function(",
+            table.concat(proto.args, ", "), ")\n")
         s:write( "        self:__do_start()\n")
         for i, v in ipairs(proto.allocs) do
             s:write("        local ", v[2], " = ffi.new(\"", v[1], "[1]\")\n")
         end
         local genv = (proto.ret_type ~= "void")
-        local lcall = {
-            "        ", genv and "local v = " or "", "__lib.", proto.full_name,
-            "(", table.concat(proto.vargs, ", "), ")\n"
-        }
-        s:write(table.concat(lcall))
+        s:write("        ", genv and "local v = " or "", "__lib.",
+            proto.full_name, "(", table.concat(proto.vargs, ", "), ")\n")
         s:write("        self:__do_end()\n")
         if #proto.rets > 0 then
             s:write("        return ", table.concat(proto.rets, ", "), "\n")
@@ -378,14 +372,28 @@ local Event = Node:clone {
     end
 }
 
-local Constructor = Node:clone {
-    gen_ffi = function(self, s)
+local Constructor = Method:clone {
+    generate = function(self, s, last)
+        local proto   = self:gen_proto()
+        local name    = proto.name
+        local defctor = name == "constructor"
+        table.insert(proto.args, 2, "parent")
+        s:write( "    ", defctor and "__ctor" or name, " = function(",
+            table.concat(proto.args, ", "), ")\n")
+        for i, v in ipairs(proto.allocs) do
+            s:write("        local ", v[2], " = ffi.new(\"", v[1], "[1]\")\n")
+        end
+        local genv = (proto.ret_type ~= "void")
+        s:write("        ", genv and "local v = " or "", "self:__ctor_common(",
+            "butts, parent, __lib.", proto.full_name,
+            ", ", table.concat(proto.vargs, ", "), ")\n")
+        if #proto.rets > 0 then
+            s:write("        return ", table.concat(proto.rets, ", "), "\n")
+        end
+        s:write("    end", last and "" or ",", last and "\n" or "\n\n")
     end
 }
 
-local Destructor = Node:clone {
-}
-
 local Mixin = Node:clone {
     __ctor = function(self, cname, ch, evs)
         self.cname    = cname