forked from enlightenment/efl
elua: initial rectangle mdule and iterator fixes/cleanups
This commit is contained in:
parent
155eae24e1
commit
5aedc8c722
|
@ -31,15 +31,15 @@ end
|
|||
|
||||
ffi.metatype("Eina_Iterator", {
|
||||
__index = {
|
||||
free = function(self) C.eina_iterator_free(self) end,
|
||||
free = function(self) eina.eina_iterator_free(ffi.gc(self, nil)) end,
|
||||
next = function(self)
|
||||
local data = ffi.new("void*[1]")
|
||||
local r = C.eina_iterator_next(self, data)
|
||||
local r = eina.eina_iterator_next(self, data)
|
||||
if r == 0 then return nil end
|
||||
return data[0]
|
||||
end,
|
||||
lock = function(self) return C.eina_iterator_lock (self) == 1 end,
|
||||
unlock = function(self) return C.eina_iterator_unlock(self) == 1 end
|
||||
lock = function(self) return eina.eina_iterator_lock (self) == 1 end,
|
||||
unlock = function(self) return eina.eina_iterator_unlock(self) == 1 end
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -48,9 +48,9 @@ cutil.init_module(init, shutdown)
|
|||
M.Iterator = util.Object:clone {
|
||||
__ctor = function(self, iter)
|
||||
self.__iterator = iter
|
||||
if self.__iterator then ffi.gc(self.__iterator, function(iter)
|
||||
iter:free()
|
||||
end) end
|
||||
if self.__iterator then
|
||||
ffi.gc(self.__iterator, self.__iterator.free)
|
||||
end
|
||||
self.__eq = function(self, other)
|
||||
return self.__iterator == other.__iterator
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ M.Iterator = util.Object:clone {
|
|||
|
||||
free = function(self)
|
||||
if not self.__iterator then return end
|
||||
self.__iterator.free(ffi.gc(self.__iterator, nil))
|
||||
self.__iterator:free()
|
||||
self.__iterator = nil
|
||||
end,
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
-- EFL LuaJIT bindings: Eina (rectangle module)
|
||||
-- For use with Elua
|
||||
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
|
||||
ffi.cdef [[
|
||||
typedef struct _Eina_Rectangle {
|
||||
int x, y, w, h;
|
||||
} Eina_Rectangle;
|
||||
|
||||
typedef struct _Eina_Rectangle_Pool Eina_Rectangle_Pool;
|
||||
|
||||
typedef unsigned char Eina_Bool;
|
||||
|
||||
Eina_Rectangle_Pool *eina_rectangle_pool_new(int w, int h);
|
||||
Eina_Rectangle_Pool *eina_rectangle_pool_get(Eina_Rectangle *rect);
|
||||
Eina_Bool eina_rectangle_pool_geometry_get(Eina_Rectangle_Pool *pool, int *w, int *h);
|
||||
void *eina_rectangle_pool_data_get(Eina_Rectangle_Pool *pool);
|
||||
void eina_rectangle_pool_data_set(Eina_Rectangle_Pool *pool, const void *data);
|
||||
void eina_rectangle_pool_free(Eina_Rectangle_Pool *pool);
|
||||
int eina_rectangle_pool_count(Eina_Rectangle_Pool *pool);
|
||||
Eina_Rectangle *eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h);
|
||||
void eina_rectangle_pool_release(Eina_Rectangle *rect);
|
||||
|
||||
Eina_Rectangle *eina_rectangle_new (int x, int y, int w, int h);
|
||||
void eina_rectangle_free(Eina_Rectangle *rect);
|
||||
]]
|
||||
|
||||
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.Rectangle = ffi.metatype("Eina_Rectangle", {
|
||||
__new = function(self, x, y, w, h)
|
||||
return ffi.gc(eina.eina_rectangle_new(x, y, w, h), self.free)
|
||||
end,
|
||||
__index = {
|
||||
free = function(self) eina.eina_rectangle_free(ffi.gc(self, nil)) end,
|
||||
set = function(self, x, y, w, h)
|
||||
self.x, self.y, self.w, self.h = x, y, w, h
|
||||
end,
|
||||
get_pool = function(self)
|
||||
local v = eina.eina_rectangle_pool_get(self)
|
||||
return v ~= nil and v or nil
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
M.Rectangle_Pool = ffi.metatype("Eina_Rectangle_Pool", {
|
||||
__new = function(self, w, h)
|
||||
return ffi.gc(eina.eina_rectangle_pool_new(w, h), self.free)
|
||||
end,
|
||||
|
||||
__len = function(self) return eina.eina_rectangle_pool_count(self) end,
|
||||
|
||||
__index = {
|
||||
free = function(self)
|
||||
eina.eina_rectangle_pool_free(ffi.gc(self, nil))
|
||||
end,
|
||||
get = function(rect) return rect:get_pool() end,
|
||||
|
||||
geometry_get = function(self)
|
||||
local w, h = ffi.new("int[1]"), ffi.new("int[1]")
|
||||
eina.eina_rectangle_pool_geometry_get(self, w, h)
|
||||
return w[0], h[0]
|
||||
end,
|
||||
|
||||
--[[
|
||||
data_get = function(self)
|
||||
return eina.eina_rectangle_pool_data_get(self)
|
||||
end,
|
||||
data_set = function(self, v)
|
||||
eina.eina_rectangle_pool_data_set(self, v)
|
||||
end,
|
||||
]]
|
||||
|
||||
request = function(self, w, h)
|
||||
local v = eina.eina_rectangle_pool_request(self, w, h)
|
||||
return v ~= nil and v or nil
|
||||
end,
|
||||
|
||||
release = function(self, rect)
|
||||
eina.eina_rectangle_pool_release(rect)
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
return M
|
Loading…
Reference in New Issue