elua: use the type API in lualian (but only basics of it)
authorDaniel Kolesa <d.kolesa@samsung.com>
Mon, 14 Jul 2014 15:08:31 +0000 (16:08 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Mon, 14 Jul 2014 15:08:31 +0000 (16:08 +0100)
src/bin/elua/modules/lualian.lua
src/bindings/luajit/eolian.lua

index fa0505a..371111d 100644 (file)
@@ -36,7 +36,7 @@ local known_out = {
 }
 
 local known_in = {
-    ["Eina_Bool" ] = function(expr) return expr end,
+    ["bool"] = function(expr) return expr end,
     ["Evas_Coord"] = function(expr) return expr end
 }
 
@@ -58,16 +58,17 @@ local build_calln = function(tps, expr, isin)
     }
 end
 
-local typeconv_in = function(tps, tp, expr, isconst, isptr)
-    if isptr then
-        local passtp = (isconst and "const " or "") .. tp
-        local f = known_ptr_in[passtp]
+local typeconv_in = function(tps, expr)
+    if tps:type_get() == eolian.type_type.POINTER then
+        local base = tps:base_type_get()
+        local f = known_ptr_in[base:c_type_get()]
         if f then return f(expr) end
         return build_calln(tps, expr, true)
     end
-    if isnum[tp] then
-        return expr
-    end
+
+    local tp = tps:name_get()
+
+    if isnum[tp] then return expr end
 
     local f = known_in[tp]
     if f then
@@ -78,34 +79,23 @@ local typeconv_in = function(tps, tp, expr, isconst, isptr)
 end
 
 local typeconv = function(tps, expr, isin)
-    local tp = tps:c_type_get()
-    -- strip away type qualifiers
-    local isconst, tpr = tp:match("^(const)[ ]+(.+)$")
-    isconst = not not isconst
-    if tpr then tp = tpr end
-
-    -- check if it's a pointer
-    local basetype = (tp:match("(.+)[ ]+%*$"))
-
-    -- out val
     if isin then
-        return typeconv_in(tps, basetype or tp, expr, isconst, not not basetype)
+        return typeconv_in(tps, expr)
     end
 
-    -- pointer type
-    if basetype then
-        local passtp = (isconst and "const " or "") .. basetype
-        local f = known_ptr_out[passtp]
+    if tps:type_get() == eolian.type_type.POINTER then
+        local base = tps:base_type_get()
+        local f = known_ptr_out[base:c_type_get()]
         if f then return f(expr) end
         return build_calln(tps, expr, false)
     end
 
-    -- number?
+    local tp = tps:name_get()
+
     if isnum[tp] then
         return ("tonumber(%s)"):format(expr)
     end
 
-    -- known primitive EFL type?
     local f = known_out[tp]
     if f then
         return f(expr)
index f666eb6..adf6e3a 100644 (file)
@@ -195,6 +195,16 @@ M.show_all = function()
     eolian.eolian_show_all()
 end
 
+M.type_type = {
+    UNKNOWN        = 0,
+    VOID           = 1,
+    REGULAR        = 2,
+    REGULAR_STRUCT = 3,
+    POINTER        = 4,
+    FUNCTION       = 5,
+    STRUCT         = 6
+}
+
 M.Type = ffi.metatype("Eolian_Type", {
     __index = {
         type_get = function(self)