elua: eina_counter bindings

This commit is contained in:
Daniel Kolesa 2014-04-10 09:56:30 +01:00 committed by Daniel Kolesa
parent 8fe7eb5381
commit b58888e0cd
2 changed files with 66 additions and 3 deletions

View File

@ -0,0 +1,64 @@
-- EFL LuaJIT bindings: Eina (counter module)
-- For use with Elua
local ffi = require("ffi")
local C = ffi.C
ffi.cdef [[
int eina_hamster_count(void);
typedef struct _Eina_Counter Eina_Counter;
Eina_Counter *eina_counter_new (const char *name);
void eina_counter_free (Eina_Counter *counter);
void eina_counter_start(Eina_Counter *counter);
void eina_counter_stop (Eina_Counter *counter, int specimen);
char *eina_counter_dump (Eina_Counter *counter);
void free(void*);
]]
local cutil = require("cutil")
local util = require("util")
local M = {}
local eina
local init = function()
eina = util.lib_load("eina")
end
local shutdown = function()
util.lib_unload("eina")
end
cutil.init_module(init, shutdown)
M.Counter = ffi.metatype("Eina_Counter", {
__new = function(self, name)
return ffi.gc(eina.eina_counter_new(name), self.free)
end,
__index = {
free = function(self)
return eina.eina_counter_free(ffi.gc(self, nil))
end,
start = function(self)
return eina.eina_counter_start(self)
end,
stop = function(self, specimen)
return eina.eina_counter_stop(self, specimen)
end,
dump = function(self)
local v = eina.eina_counter_dump(self)
if v == nil then return nil end
local r = ffi.string(v)
C.free(v)
return r
end
}
})
return M

View File

@ -173,9 +173,8 @@ M.default_domain = M.Domain_Default
M.Domain = M.Domain_Base:clone {
__ctor = function(self, name, color)
self.__domain = ffi.cast("Domain*", ffi.new("Domain_Private",
eina.eina_log_domain_register(name, color)))
ffi.gc(self.__domain, unregister_dom)
self.__domain = ffi.gc(ffi.cast("Domain*", ffi.new("Domain_Private",
eina.eina_log_domain_register(name, color))), unregister_dom)
end,
unregister = function(self)