lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Wesley Smith wrote:
Hi Hakki,
I've been using you Cairo bindings for Lua.  Thanks very much for
this.  It's working like a charm and your code is very clean.  One
question I have is why you decided to represent the Cairo C structs as
tables instead of using userdata.  An example:

static void push_matrix(lua_State* L, cairo_matrix_t *matrix)
{
    lua_newtable(L);
    set_numfield(L, "xx", matrix->xx);
    set_numfield(L, "yx", matrix->yx);
    set_numfield(L, "xy", matrix->xy);
    set_numfield(L, "yy", matrix->yy);
    set_numfield(L, "x0", matrix->x0);
    set_numfield(L, "y0", matrix->y0);
}


When you get into for loops where you're using alot of the data
structures represented this way, it adds quite an overhead.  I wonder
if you would consider moving these kinds of things to a userdata
representation for a future release?

thanks,
wes




Thank you for kind words.

I changed implementation of cairo_matrix_t, cairo_text_extents_t, cairo_fontt_extents_t to userdata. This change eliminated many "//WARN: different usage" comments :) You may search changes with "//.." in code. Snippets.lua updated accordingly. There is a matrix test section at bottom of that file.

Usage is like:
    local m1 = cairo.Matrix()
    local m2 = cairo.Matrix{xx=0,yy=0.3}
    m1.x0 = m2.xx + 12.1
    cairo.matrix_init (m1, 1, 2, 3, 4, 5, 6)

    local e1 = cairo.TextExtents()
    local e2 = cairo.TextExtents{x_bearing=2.1}
    cairo.text_extents (cr, utf8, e1);
    x = 0.5-(e1.width/2 + e1.x_bearing);

    local f1 = cairo.FontExtents()
    cairo.font_extents (cr, f1);


You may get it here:
http://www.dogusan.net/dogusanh/download/luacairo-0.7.zip (~3.5Mb)


--
Regards,
Hakki Dogusan