summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 06:39:50 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 06:39:50 +0200
commit8cc2c419cb870dd20d43eb887bf72410fa8b9472 (patch)
tree14eb8f506c4cbe4bcce92562491c5ec3a9f6ee0a
parentb953b99a6607535a860269d835b8447ea9497508 (diff)
bindings/lua: fixes for cffi-lua
-rw-r--r--src/bindings/lua/eina/file.lua12
-rw-r--r--src/bindings/lua/eina/hamster.lua4
-rw-r--r--src/bindings/lua/eina/xattr.lua6
-rw-r--r--src/bindings/lua/eo.lua6
-rw-r--r--src/bindings/lua/eolian.lua51
5 files changed, 45 insertions, 34 deletions
diff --git a/src/bindings/lua/eina/file.lua b/src/bindings/lua/eina/file.lua
index 3f59391b60..f9fcf2350c 100644
--- a/src/bindings/lua/eina/file.lua
+++ b/src/bindings/lua/eina/file.lua
@@ -4,6 +4,8 @@
4local ffi = require("ffi") 4local ffi = require("ffi")
5local C = ffi.C 5local C = ffi.C
6 6
7local tonum = ffi.tonumber or tonumber
8
7local iterator = require("eina.iterator") 9local iterator = require("eina.iterator")
8require("eina.xattr") 10require("eina.xattr")
9 11
@@ -210,8 +212,8 @@ local direct_info_iterator_next = function(self)
210 if not v then return nil end 212 if not v then return nil end
211 local s = ffi.cast("Eina_File_Direct_Info*", v) 213 local s = ffi.cast("Eina_File_Direct_Info*", v)
212 local path = ffi.string(s.path, s.path_length) 214 local path = ffi.string(s.path, s.path_length)
213 local ns = tonumber(s.name_start) 215 local ns = tonum(s.name_start)
214 local nl = tonumber(s.name_length) 216 local nl = tonum(s.name_length)
215 local tp = file_type_map[s.type] 217 local tp = file_type_map[s.type]
216 return Direct_Info(path, ns, nl, tp), self:container_get() 218 return Direct_Info(path, ns, nl, tp), self:container_get()
217end 219end
@@ -301,7 +303,7 @@ local Line_Iterator = Iterator:clone {
301 local v = Iterator.next(self) 303 local v = Iterator.next(self)
302 if not v then return nil end 304 if not v then return nil end
303 v = ffi.cast(v, "Eina_File_Line*") 305 v = ffi.cast(v, "Eina_File_Line*")
304 return ffi.string(v.start, v.length), tonumber(v.index) 306 return ffi.string(v.start, v.length), tonum(v.index)
305 end 307 end
306} 308}
307 309
@@ -342,11 +344,11 @@ M.File = ffi.metatype("Eina_File", {
342 end, 344 end,
343 345
344 size_get = function(self) 346 size_get = function(self)
345 return tonumber(eina.eina_file_size_get(self)) 347 return tonum(eina.eina_file_size_get(self))
346 end, 348 end,
347 349
348 mtime_get = function(self) 350 mtime_get = function(self)
349 return tonumber(eina.eina_file_mtime_get(self)) 351 return tonum(eina.eina_file_mtime_get(self))
350 end, 352 end,
351 353
352 filename_get = function(self) 354 filename_get = function(self)
diff --git a/src/bindings/lua/eina/hamster.lua b/src/bindings/lua/eina/hamster.lua
index e8f5e7434f..2e93086e82 100644
--- a/src/bindings/lua/eina/hamster.lua
+++ b/src/bindings/lua/eina/hamster.lua
@@ -3,6 +3,8 @@
3 3
4local ffi = require("ffi") 4local ffi = require("ffi")
5 5
6local tonum = ffi.tonumber or tonumber
7
6ffi.cdef [[ 8ffi.cdef [[
7 int eina_hamster_count(void); 9 int eina_hamster_count(void);
8]] 10]]
@@ -25,7 +27,7 @@ end
25cutil.init_module(init, shutdown) 27cutil.init_module(init, shutdown)
26 28
27M.count = function() 29M.count = function()
28 return tonumber(eina.eina_hamster_count()) 30 return tonum(eina.eina_hamster_count())
29end 31end
30 32
31return M 33return M
diff --git a/src/bindings/lua/eina/xattr.lua b/src/bindings/lua/eina/xattr.lua
index 3e2417d194..bac2d85bd8 100644
--- a/src/bindings/lua/eina/xattr.lua
+++ b/src/bindings/lua/eina/xattr.lua
@@ -4,6 +4,8 @@
4local ffi = require("ffi") 4local ffi = require("ffi")
5local C = ffi.C 5local C = ffi.C
6 6
7local tonum = ffi.tonumber or tonumber
8
7local iterator = require("eina.iterator") 9local iterator = require("eina.iterator")
8 10
9ffi.cdef [[ 11ffi.cdef [[
@@ -140,7 +142,7 @@ M.double_get = function(file, attribute)
140 local v = ffi.new("double[1]") 142 local v = ffi.new("double[1]")
141 local r = eina.eina_xattr_double_get(file, attribute, v) 143 local r = eina.eina_xattr_double_get(file, attribute, v)
142 if r == 0 then return false end 144 if r == 0 then return false end
143 return true, tonumber(v[0]) 145 return true, tonum(v[0])
144end 146end
145 147
146M.int_set = function(file, attribute, value, flags) 148M.int_set = function(file, attribute, value, flags)
@@ -151,7 +153,7 @@ M.int_get = function(file, attribute)
151 local v = ffi.new("int[1]") 153 local v = ffi.new("int[1]")
152 local r = eina.eina_xattr_int_get(file, attribute, v) 154 local r = eina.eina_xattr_int_get(file, attribute, v)
153 if r == 0 then return false end 155 if r == 0 then return false end
154 return true, tonumber(v[0]) 156 return true, tonum(v[0])
155end 157end
156 158
157return M 159return M
diff --git a/src/bindings/lua/eo.lua b/src/bindings/lua/eo.lua
index 42531aa153..ff19afc595 100644
--- a/src/bindings/lua/eo.lua
+++ b/src/bindings/lua/eo.lua
@@ -109,11 +109,13 @@ ffi.cdef [[
109 extern const Eo_Event_Description _EO_BASE_EVENT_DEL; 109 extern const Eo_Event_Description _EO_BASE_EVENT_DEL;
110]] 110]]
111 111
112local tonum = ffi.tonumber or tonumber
113
112local addr_d = ffi.typeof("union { double d; const Eo *p; }") 114local addr_d = ffi.typeof("union { double d; const Eo *p; }")
113local eo_obj_addr_get = function(x) 115local eo_obj_addr_get = function(x)
114 local v = addr_d() 116 local v = addr_d()
115 v.p = x 117 v.p = x
116 return tonumber(v.d) 118 return tonum(v.d)
117end 119end
118 120
119local cutil = require("cutil") 121local cutil = require("cutil")
@@ -143,7 +145,7 @@ local eo_event_cb_fun = function(data, obj, desc, einfo)
143 local addr = eo_obj_addr_get(obj) 145 local addr = eo_obj_addr_get(obj)
144 local cbs = eo_callbacks[addr] 146 local cbs = eo_callbacks[addr]
145 assert(cbs) 147 assert(cbs)
146 local cidx = tonumber(ffi.cast("intptr_t", data)) 148 local cidx = tonum(ffi.cast("intptr_t", data))
147 local fun = cbs[cidx] 149 local fun = cbs[cidx]
148 assert(fun) 150 assert(fun)
149 return fun() ~= false 151 return fun() ~= false
diff --git a/src/bindings/lua/eolian.lua b/src/bindings/lua/eolian.lua
index eebe44486f..e530500360 100644
--- a/src/bindings/lua/eolian.lua
+++ b/src/bindings/lua/eolian.lua
@@ -478,6 +478,8 @@ ffi.cdef [[
478local cutil = require("cutil") 478local cutil = require("cutil")
479local util = require("util") 479local util = require("util")
480 480
481local tonum = ffi.tonumber or tonumber
482
481local iterator = require("eina.iterator") 483local iterator = require("eina.iterator")
482 484
483local Ptr_Iterator = iterator.Ptr_Iterator 485local Ptr_Iterator = iterator.Ptr_Iterator
@@ -554,7 +556,7 @@ local object_idx, wrap_object = gen_wrap {
554 end, 556 end,
555 557
556 type_get = function(self) 558 type_get = function(self)
557 return tonumber(eolian.eolian_object_type_get(cast_obj(self))) 559 return tonum(eolian.eolian_object_type_get(cast_obj(self)))
558 end, 560 end,
559 561
560 unit_get = function(self) 562 unit_get = function(self)
@@ -566,11 +568,11 @@ local object_idx, wrap_object = gen_wrap {
566 end, 568 end,
567 569
568 line_get = function(self) 570 line_get = function(self)
569 return tonumber(eolian.eolian_object_line_get(cast_obj(self))) 571 return tonum(eolian.eolian_object_line_get(cast_obj(self)))
570 end, 572 end,
571 573
572 column_get = function(self) 574 column_get = function(self)
573 return tonumber(eolian.eolian_object_column_get(cast_obj(self))) 575 return tonum(eolian.eolian_object_column_get(cast_obj(self)))
574 end, 576 end,
575 577
576 file_get = function(self) 578 file_get = function(self)
@@ -642,7 +644,7 @@ local unit_idx, wrap_unit = gen_wrap {
642 end, 644 end,
643 645
644 version_get = function(self) 646 version_get = function(self)
645 return tonumber(eolian.eolian_unit_version_get(cast_unit(self))) 647 return tonum(eolian.eolian_unit_version_get(cast_unit(self)))
646 end, 648 end,
647 649
648 object_by_name_get = function(self, name) 650 object_by_name_get = function(self, name)
@@ -729,7 +731,7 @@ local panic_cbs = {}
729local error_cbs = {} 731local error_cbs = {}
730 732
731local obj_to_idx = function(obj) 733local obj_to_idx = function(obj)
732 return tonumber(ffi.cast("size_t", obj)) 734 return tonum(ffi.cast("size_t", obj))
733end 735end
734 736
735local panic_cb, err_cb 737local panic_cb, err_cb
@@ -1009,7 +1011,7 @@ ffi.metatype("Eolian_Enum_Type_Field", {
1009M.Typedecl = ffi.metatype("Eolian_Typedecl", { 1011M.Typedecl = ffi.metatype("Eolian_Typedecl", {
1010 __index = wrap_object { 1012 __index = wrap_object {
1011 type_get = function(self) 1013 type_get = function(self)
1012 return tonumber(eolian.eolian_typedecl_type_get(self)) 1014 return tonum(eolian.eolian_typedecl_type_get(self))
1013 end, 1015 end,
1014 1016
1015 struct_fields_get = function(self) 1017 struct_fields_get = function(self)
@@ -1085,11 +1087,11 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", {
1085M.Type = ffi.metatype("Eolian_Type", { 1087M.Type = ffi.metatype("Eolian_Type", {
1086 __index = wrap_object { 1088 __index = wrap_object {
1087 type_get = function(self) 1089 type_get = function(self)
1088 return tonumber(eolian.eolian_type_type_get(self)) 1090 return tonum(eolian.eolian_type_type_get(self))
1089 end, 1091 end,
1090 1092
1091 builtin_type_get = function(self) 1093 builtin_type_get = function(self)
1092 return tonumber(eolian.eolian_type_builtin_type_get(self)) 1094 return tonum(eolian.eolian_type_builtin_type_get(self))
1093 end, 1095 end,
1094 1096
1095 base_type_get = function(self) 1097 base_type_get = function(self)
@@ -1160,11 +1162,11 @@ M.function_type = {
1160M.Function = ffi.metatype("Eolian_Function", { 1162M.Function = ffi.metatype("Eolian_Function", {
1161 __index = wrap_object { 1163 __index = wrap_object {
1162 type_get = function(self) 1164 type_get = function(self)
1163 return tonumber(eolian.eolian_function_type_get(self)) 1165 return tonum(eolian.eolian_function_type_get(self))
1164 end, 1166 end,
1165 1167
1166 scope_get = function(self, ftype) 1168 scope_get = function(self, ftype)
1167 return tonumber(eolian.eolian_function_scope_get(self, ftype)) 1169 return tonum(eolian.eolian_function_scope_get(self, ftype))
1168 end, 1170 end,
1169 1171
1170 full_c_name_get = function(self, ftype) 1172 full_c_name_get = function(self, ftype)
@@ -1259,7 +1261,7 @@ M.parameter_dir = {
1259ffi.metatype("Eolian_Function_Parameter", { 1261ffi.metatype("Eolian_Function_Parameter", {
1260 __index = wrap_object { 1262 __index = wrap_object {
1261 direction_get = function(self) 1263 direction_get = function(self)
1262 return tonumber(eolian.eolian_parameter_direction_get(self)) 1264 return tonum(eolian.eolian_parameter_direction_get(self))
1263 end, 1265 end,
1264 1266
1265 type_get = function(self) 1267 type_get = function(self)
@@ -1384,7 +1386,7 @@ ffi.metatype("Eolian_Event", {
1384 end, 1386 end,
1385 1387
1386 scope_get = function(self) 1388 scope_get = function(self)
1387 return tonumber(eolian.eolian_event_scope_get(self)) 1389 return tonum(eolian.eolian_event_scope_get(self))
1388 end, 1390 end,
1389 1391
1390 c_macro_get = function(self) 1392 c_macro_get = function(self)
@@ -1430,7 +1432,7 @@ M.class_type = {
1430M.Class = ffi.metatype("Eolian_Class", { 1432M.Class = ffi.metatype("Eolian_Class", {
1431 __index = wrap_object { 1433 __index = wrap_object {
1432 type_get = function(self) 1434 type_get = function(self)
1433 return tonumber(eolian.eolian_class_type_get(self)) 1435 return tonum(eolian.eolian_class_type_get(self))
1434 end, 1436 end,
1435 1437
1436 documentation_get = function(self) 1438 documentation_get = function(self)
@@ -1584,14 +1586,14 @@ emask.NUMBER = emask.INT + emask.FLOAT
1584emask.ALL = emask.NUMBER + emask.BOOL + emask.STRING + emask.CHAR + emask.NULL 1586emask.ALL = emask.NUMBER + emask.BOOL + emask.STRING + emask.CHAR + emask.NULL
1585 1587
1586local value_con = { 1588local value_con = {
1587 [etype.INT ] = function(v) return tonumber(v.value.i ) end, 1589 [etype.INT ] = function(v) return tonum(v.value.i ) end,
1588 [etype.UINT ] = function(v) return tonumber(v.value.u ) end, 1590 [etype.UINT ] = function(v) return tonum(v.value.u ) end,
1589 [etype.LONG ] = function(v) return v.value.l end, 1591 [etype.LONG ] = function(v) return v.value.l end,
1590 [etype.ULONG ] = function(v) return v.value.ul end, 1592 [etype.ULONG ] = function(v) return v.value.ul end,
1591 [etype.LLONG ] = function(v) return v.value.ll end, 1593 [etype.LLONG ] = function(v) return v.value.ll end,
1592 [etype.ULLONG] = function(v) return v.value.ull end, 1594 [etype.ULLONG] = function(v) return v.value.ull end,
1593 [etype.FLOAT ] = function(v) return tonumber(v.value.f ) end, 1595 [etype.FLOAT ] = function(v) return tonum(v.value.f ) end,
1594 [etype.DOUBLE] = function(v) return tonumber(v.value.d ) end, 1596 [etype.DOUBLE] = function(v) return tonum(v.value.d ) end,
1595 [etype.STRING] = function(v) return ffi.string(v.value.s ) end, 1597 [etype.STRING] = function(v) return ffi.string(v.value.s ) end,
1596 [etype.CHAR ] = function(v) return string.char(v.value.c) end, 1598 [etype.CHAR ] = function(v) return string.char(v.value.c) end,
1597 [etype.NULL ] = function(v) return nil end, 1599 [etype.NULL ] = function(v) return nil end,
@@ -1601,12 +1603,12 @@ local value_con = {
1601M.Value = ffi.metatype("Eolian_Value", { 1603M.Value = ffi.metatype("Eolian_Value", {
1602 __index = { 1604 __index = {
1603 get_type = function(self) 1605 get_type = function(self)
1604 return tonumber(ffi.cast("Eolian_Value_t*", self).type) 1606 return tonum(ffi.cast("Eolian_Value_t*", self).type)
1605 end, 1607 end,
1606 1608
1607 get_value = function(self) 1609 get_value = function(self)
1608 local tp = self:get_type() 1610 local tp = self:get_type()
1609 local fun = value_con[tonumber(tp)] 1611 local fun = value_con[tonum(tp)]
1610 if not fun then return nil end 1612 if not fun then return nil end
1611 return fun() 1613 return fun()
1612 end, 1614 end,
@@ -1677,11 +1679,11 @@ M.Expression = ffi.metatype("Eolian_Expression", {
1677 end, 1679 end,
1678 1680
1679 type_get = function(self) 1681 type_get = function(self)
1680 return tonumber(eolian.eolian_expression_type_get(self)) 1682 return tonum(eolian.eolian_expression_type_get(self))
1681 end, 1683 end,
1682 1684
1683 binary_operator_get = function(self) 1685 binary_operator_get = function(self)
1684 return tonumber(eolian.eolian_expression_binary_operator_get(self)) 1686 return tonum(eolian.eolian_expression_binary_operator_get(self))
1685 end, 1687 end,
1686 1688
1687 binary_lhs_get = function(self) 1689 binary_lhs_get = function(self)
@@ -1697,7 +1699,7 @@ M.Expression = ffi.metatype("Eolian_Expression", {
1697 end, 1699 end,
1698 1700
1699 unary_operator_get = function(self) 1701 unary_operator_get = function(self)
1700 return tonumber(eolian.eolian_expression_unary_operator_get(self)) 1702 return tonum(eolian.eolian_expression_unary_operator_get(self))
1701 end, 1703 end,
1702 1704
1703 unary_expression_get = function(self) 1705 unary_expression_get = function(self)
@@ -1836,7 +1838,7 @@ end
1836M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", { 1838M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
1837 __index = { 1839 __index = {
1838 type_get = function(self) 1840 type_get = function(self)
1839 return tonumber(eolian.eolian_doc_token_type_get(self)) 1841 return tonum(eolian.eolian_doc_token_type_get(self))
1840 end, 1842 end,
1841 1843
1842 text_get = function(self) 1844 text_get = function(self)
@@ -1851,7 +1853,8 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
1851 1853
1852 ref_resolve = function(self, state) 1854 ref_resolve = function(self, state)
1853 local stor = ffi.new("const Eolian_Object *[2]") 1855 local stor = ffi.new("const Eolian_Object *[2]")
1854 local tp = tonumber(eolian.eolian_doc_token_ref_resolve(self, state, stor, stor + 1)) 1856 local sp = ffi.cast("const Eolian_Object **", stor)
1857 local tp = tonum(eolian.eolian_doc_token_ref_resolve(self, state, sp, sp + 1))
1855 local reft = M.object_type 1858 local reft = M.object_type
1856 if tp == reft.CLASS then 1859 if tp == reft.CLASS then
1857 return tp, ffi.cast("const Eolian_Class *", stor[0]) 1860 return tp, ffi.cast("const Eolian_Class *", stor[0])