elua: move __ctor_common, __do_start, __do_end out of the object (as it's effectively...
authorDaniel Kolesa <d.kolesa@samsung.com>
Fri, 6 Jun 2014 13:40:04 +0000 (14:40 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:53 +0000 (15:48 +0100)
src/bin/elua/modules/lualian.lua
src/bindings/luajit/eo.lua

index ad80c48ad8d7135f9b5ea9b42cacd3c9c35411c2..3c3812ef771780cc7f1b071868a8b47efb7f75bf 100644 (file)
@@ -212,14 +212,14 @@ local Method = Node:clone {
         local proto = self:gen_proto()
         s:write("    ", proto.name, proto.suffix or "", " = function(",
             table.concat(proto.args, ", "), ")\n")
-        s:write( "        self:__do_start(__class)\n")
+        s:write( "        eo.__do_start(self, __class)\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 "", "__lib.",
             proto.full_name, "(", table.concat(proto.vargs, ", "), ")\n")
-        s:write("        self:__do_end()\n")
+        s:write("        eo.__do_end()\n")
         if #proto.rets > 0 then
             s:write("        return ", table.concat(proto.rets, ", "), "\n")
         end
@@ -390,8 +390,8 @@ local Constructor = Method:clone {
         local genv = (proto.ret_type ~= "void")
         local cvargs = table.concat(proto.vargs, ", ")
         if cvargs ~= "" then cvargs = ", " .. cvargs end
-        s:write("        ", genv and "local v = " or "", "self:__ctor_common(",
-            "__class, parent, __lib.", proto.full_name, cvargs, ")\n")
+        s:write("        ", genv and "local v = " or "", "eo.__ctor_common(",
+            "self, __class, parent, __lib.", proto.full_name, cvargs, ")\n")
         if not defctor then
             table.insert(proto.rets, 1, "self")
         end
@@ -411,7 +411,7 @@ local Default_Constructor = Node:clone {
 
         s:write( "    __ctor = function(self, parent)\n")
         s:write("        self:__define_properties(self.__proto.__proto)\n")
-        s:write("        self:__ctor_common(__class, parent)\n")
+        s:write("        eo.__ctor_common(self, __class, parent)\n")
         s:write("    end", last and "" or ",", last and "\n" or "\n\n")
     end,
 
index c6ef57c5b087f1db504ad8243e3f3e2947f5501b..c5216e43466cb7d5dd0ccfc580c77b739a6ab502 100644 (file)
@@ -72,42 +72,43 @@ M.class_register = function(name, val)
     classes[name] = val
 end
 
-M.Eo_Base = util.Object:clone {
-    __ctor_common = function(self, klass, parent, ctor, loff, ...)
-        local info    = getinfo(2 + (loff or 0), "nlSf")
-        local source  = info.source
-        local func    = getfuncname(info)
-        local line    = info.currentline
-        local tmp_obj = eo._eo_add_internal_start(source, line, klass,
-            parent.__obj)
-        local retval
-        if eo._eo_do_start(tmp_obj, nil, false, source, func, line) ~= 0 then
-            if ctor then
-                retval = ctor(...)
-            else
-                eo.eo_constructor()
-            end
-            tmp_obj = eo.eo_finalize()
-            eo._eo_do_end(nil)
-        end
-        self.__obj    = tmp_obj
-        self.__parent = parent
-        return retval
-    end,
-
-    __do_start = function(self, klass)
-        if eo.eo_isa(self.__obj, klass) == 0 then
-            error("method call on an invalid object", 3)
+M.__ctor_common = function(self, klass, parent, ctor, loff, ...)
+    local info    = getinfo(2 + (loff or 0), "nlSf")
+    local source  = info.source
+    local func    = getfuncname(info)
+    local line    = info.currentline
+    local tmp_obj = eo._eo_add_internal_start(source, line, klass,
+        parent.__obj)
+    local retval
+    if eo._eo_do_start(tmp_obj, nil, false, source, func, line) ~= 0 then
+        if ctor then
+            retval = ctor(...)
+        else
+            eo.eo_constructor()
         end
-        local info = getinfo(3, "nlSf")
-        return eo._eo_do_start(self.__obj, nil, false, info.source,
-            getfuncname(info), info.currentline) ~= 0
-    end,
-
-    __do_end = function(self)
-        eo._eo_do_end(nil) -- the parameter is unused and originally there
-                           -- only for cleanup (dtor)
+        tmp_obj = eo.eo_finalize()
+        eo._eo_do_end(nil)
+    end
+    self.__obj    = tmp_obj
+    self.__parent = parent
+    return retval
+end
+
+M.__do_start = function(self, klass)
+    if eo.eo_isa(self.__obj, klass) == 0 then
+        error("method call on an invalid object", 3)
     end
+    local info = getinfo(3, "nlSf")
+    return eo._eo_do_start(self.__obj, nil, false, info.source,
+        getfuncname(info), info.currentline) ~= 0
+end
+
+M.__do_end = function()
+    eo._eo_do_end(nil) -- the parameter is unused and originally there
+                       -- only for cleanup (dtor)
+end
+
+M.Eo_Base = util.Object:clone {
 }
 
 return M
\ No newline at end of file