From 71e4f46b3159642ba06fdc6df8e4e3630436fc01 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 31 May 2020 06:39:50 +0200 Subject: [PATCH] bindings/lua: fixes for cffi-lua --- src/bindings/lua/eina/file.lua | 12 +++++---- src/bindings/lua/eina/hamster.lua | 4 ++- src/bindings/lua/eina/xattr.lua | 6 +++-- src/bindings/lua/eo.lua | 6 +++-- src/bindings/lua/eolian.lua | 51 +++++++++++++++++++++------------------ 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/bindings/lua/eina/file.lua b/src/bindings/lua/eina/file.lua index 3f59391..f9fcf23 100644 --- a/src/bindings/lua/eina/file.lua +++ b/src/bindings/lua/eina/file.lua @@ -4,6 +4,8 @@ local ffi = require("ffi") local C = ffi.C +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") require("eina.xattr") @@ -210,8 +212,8 @@ local direct_info_iterator_next = function(self) if not v then return nil end local s = ffi.cast("Eina_File_Direct_Info*", v) local path = ffi.string(s.path, s.path_length) - local ns = tonumber(s.name_start) - local nl = tonumber(s.name_length) + local ns = tonum(s.name_start) + local nl = tonum(s.name_length) local tp = file_type_map[s.type] return Direct_Info(path, ns, nl, tp), self:container_get() end @@ -301,7 +303,7 @@ local Line_Iterator = Iterator:clone { local v = Iterator.next(self) if not v then return nil end v = ffi.cast(v, "Eina_File_Line*") - return ffi.string(v.start, v.length), tonumber(v.index) + return ffi.string(v.start, v.length), tonum(v.index) end } @@ -342,11 +344,11 @@ M.File = ffi.metatype("Eina_File", { end, size_get = function(self) - return tonumber(eina.eina_file_size_get(self)) + return tonum(eina.eina_file_size_get(self)) end, mtime_get = function(self) - return tonumber(eina.eina_file_mtime_get(self)) + return tonum(eina.eina_file_mtime_get(self)) end, filename_get = function(self) diff --git a/src/bindings/lua/eina/hamster.lua b/src/bindings/lua/eina/hamster.lua index e8f5e74..2e93086 100644 --- a/src/bindings/lua/eina/hamster.lua +++ b/src/bindings/lua/eina/hamster.lua @@ -3,6 +3,8 @@ local ffi = require("ffi") +local tonum = ffi.tonumber or tonumber + ffi.cdef [[ int eina_hamster_count(void); ]] @@ -25,7 +27,7 @@ end cutil.init_module(init, shutdown) M.count = function() - return tonumber(eina.eina_hamster_count()) + return tonum(eina.eina_hamster_count()) end return M diff --git a/src/bindings/lua/eina/xattr.lua b/src/bindings/lua/eina/xattr.lua index 3e2417d..bac2d85b 100644 --- a/src/bindings/lua/eina/xattr.lua +++ b/src/bindings/lua/eina/xattr.lua @@ -4,6 +4,8 @@ local ffi = require("ffi") local C = ffi.C +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") ffi.cdef [[ @@ -140,7 +142,7 @@ M.double_get = function(file, attribute) local v = ffi.new("double[1]") local r = eina.eina_xattr_double_get(file, attribute, v) if r == 0 then return false end - return true, tonumber(v[0]) + return true, tonum(v[0]) end M.int_set = function(file, attribute, value, flags) @@ -151,7 +153,7 @@ M.int_get = function(file, attribute) local v = ffi.new("int[1]") local r = eina.eina_xattr_int_get(file, attribute, v) if r == 0 then return false end - return true, tonumber(v[0]) + return true, tonum(v[0]) end return M diff --git a/src/bindings/lua/eo.lua b/src/bindings/lua/eo.lua index 42531aa..ff19afc 100644 --- a/src/bindings/lua/eo.lua +++ b/src/bindings/lua/eo.lua @@ -109,11 +109,13 @@ ffi.cdef [[ extern const Eo_Event_Description _EO_BASE_EVENT_DEL; ]] +local tonum = ffi.tonumber or tonumber + local addr_d = ffi.typeof("union { double d; const Eo *p; }") local eo_obj_addr_get = function(x) local v = addr_d() v.p = x - return tonumber(v.d) + return tonum(v.d) end local cutil = require("cutil") @@ -143,7 +145,7 @@ local eo_event_cb_fun = function(data, obj, desc, einfo) local addr = eo_obj_addr_get(obj) local cbs = eo_callbacks[addr] assert(cbs) - local cidx = tonumber(ffi.cast("intptr_t", data)) + local cidx = tonum(ffi.cast("intptr_t", data)) local fun = cbs[cidx] assert(fun) return fun() ~= false diff --git a/src/bindings/lua/eolian.lua b/src/bindings/lua/eolian.lua index eebe444..e530500 100644 --- a/src/bindings/lua/eolian.lua +++ b/src/bindings/lua/eolian.lua @@ -478,6 +478,8 @@ ffi.cdef [[ local cutil = require("cutil") local util = require("util") +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") local Ptr_Iterator = iterator.Ptr_Iterator @@ -554,7 +556,7 @@ local object_idx, wrap_object = gen_wrap { end, type_get = function(self) - return tonumber(eolian.eolian_object_type_get(cast_obj(self))) + return tonum(eolian.eolian_object_type_get(cast_obj(self))) end, unit_get = function(self) @@ -566,11 +568,11 @@ local object_idx, wrap_object = gen_wrap { end, line_get = function(self) - return tonumber(eolian.eolian_object_line_get(cast_obj(self))) + return tonum(eolian.eolian_object_line_get(cast_obj(self))) end, column_get = function(self) - return tonumber(eolian.eolian_object_column_get(cast_obj(self))) + return tonum(eolian.eolian_object_column_get(cast_obj(self))) end, file_get = function(self) @@ -642,7 +644,7 @@ local unit_idx, wrap_unit = gen_wrap { end, version_get = function(self) - return tonumber(eolian.eolian_unit_version_get(cast_unit(self))) + return tonum(eolian.eolian_unit_version_get(cast_unit(self))) end, object_by_name_get = function(self, name) @@ -729,7 +731,7 @@ local panic_cbs = {} local error_cbs = {} local obj_to_idx = function(obj) - return tonumber(ffi.cast("size_t", obj)) + return tonum(ffi.cast("size_t", obj)) end local panic_cb, err_cb @@ -1009,7 +1011,7 @@ ffi.metatype("Eolian_Enum_Type_Field", { M.Typedecl = ffi.metatype("Eolian_Typedecl", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_typedecl_type_get(self)) + return tonum(eolian.eolian_typedecl_type_get(self)) end, struct_fields_get = function(self) @@ -1085,11 +1087,11 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", { M.Type = ffi.metatype("Eolian_Type", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_type_type_get(self)) + return tonum(eolian.eolian_type_type_get(self)) end, builtin_type_get = function(self) - return tonumber(eolian.eolian_type_builtin_type_get(self)) + return tonum(eolian.eolian_type_builtin_type_get(self)) end, base_type_get = function(self) @@ -1160,11 +1162,11 @@ M.function_type = { M.Function = ffi.metatype("Eolian_Function", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_function_type_get(self)) + return tonum(eolian.eolian_function_type_get(self)) end, scope_get = function(self, ftype) - return tonumber(eolian.eolian_function_scope_get(self, ftype)) + return tonum(eolian.eolian_function_scope_get(self, ftype)) end, full_c_name_get = function(self, ftype) @@ -1259,7 +1261,7 @@ M.parameter_dir = { ffi.metatype("Eolian_Function_Parameter", { __index = wrap_object { direction_get = function(self) - return tonumber(eolian.eolian_parameter_direction_get(self)) + return tonum(eolian.eolian_parameter_direction_get(self)) end, type_get = function(self) @@ -1384,7 +1386,7 @@ ffi.metatype("Eolian_Event", { end, scope_get = function(self) - return tonumber(eolian.eolian_event_scope_get(self)) + return tonum(eolian.eolian_event_scope_get(self)) end, c_macro_get = function(self) @@ -1430,7 +1432,7 @@ M.class_type = { M.Class = ffi.metatype("Eolian_Class", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_class_type_get(self)) + return tonum(eolian.eolian_class_type_get(self)) end, documentation_get = function(self) @@ -1584,14 +1586,14 @@ emask.NUMBER = emask.INT + emask.FLOAT emask.ALL = emask.NUMBER + emask.BOOL + emask.STRING + emask.CHAR + emask.NULL local value_con = { - [etype.INT ] = function(v) return tonumber(v.value.i ) end, - [etype.UINT ] = function(v) return tonumber(v.value.u ) end, + [etype.INT ] = function(v) return tonum(v.value.i ) end, + [etype.UINT ] = function(v) return tonum(v.value.u ) end, [etype.LONG ] = function(v) return v.value.l end, [etype.ULONG ] = function(v) return v.value.ul end, [etype.LLONG ] = function(v) return v.value.ll end, [etype.ULLONG] = function(v) return v.value.ull end, - [etype.FLOAT ] = function(v) return tonumber(v.value.f ) end, - [etype.DOUBLE] = function(v) return tonumber(v.value.d ) end, + [etype.FLOAT ] = function(v) return tonum(v.value.f ) end, + [etype.DOUBLE] = function(v) return tonum(v.value.d ) end, [etype.STRING] = function(v) return ffi.string(v.value.s ) end, [etype.CHAR ] = function(v) return string.char(v.value.c) end, [etype.NULL ] = function(v) return nil end, @@ -1601,12 +1603,12 @@ local value_con = { M.Value = ffi.metatype("Eolian_Value", { __index = { get_type = function(self) - return tonumber(ffi.cast("Eolian_Value_t*", self).type) + return tonum(ffi.cast("Eolian_Value_t*", self).type) end, get_value = function(self) local tp = self:get_type() - local fun = value_con[tonumber(tp)] + local fun = value_con[tonum(tp)] if not fun then return nil end return fun() end, @@ -1677,11 +1679,11 @@ M.Expression = ffi.metatype("Eolian_Expression", { end, type_get = function(self) - return tonumber(eolian.eolian_expression_type_get(self)) + return tonum(eolian.eolian_expression_type_get(self)) end, binary_operator_get = function(self) - return tonumber(eolian.eolian_expression_binary_operator_get(self)) + return tonum(eolian.eolian_expression_binary_operator_get(self)) end, binary_lhs_get = function(self) @@ -1697,7 +1699,7 @@ M.Expression = ffi.metatype("Eolian_Expression", { end, unary_operator_get = function(self) - return tonumber(eolian.eolian_expression_unary_operator_get(self)) + return tonum(eolian.eolian_expression_unary_operator_get(self)) end, unary_expression_get = function(self) @@ -1836,7 +1838,7 @@ end M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", { __index = { type_get = function(self) - return tonumber(eolian.eolian_doc_token_type_get(self)) + return tonum(eolian.eolian_doc_token_type_get(self)) end, text_get = function(self) @@ -1851,7 +1853,8 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", { ref_resolve = function(self, state) local stor = ffi.new("const Eolian_Object *[2]") - local tp = tonumber(eolian.eolian_doc_token_ref_resolve(self, state, stor, stor + 1)) + local sp = ffi.cast("const Eolian_Object **", stor) + local tp = tonum(eolian.eolian_doc_token_ref_resolve(self, state, sp, sp + 1)) local reft = M.object_type if tp == reft.CLASS then return tp, ffi.cast("const Eolian_Class *", stor[0]) -- 2.7.4