lua-users home
lua-l archive

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


Sam Roberts yazmış:
On Fri, May 25, 2007 at 01:35:16AM +0300, Hakki Dogusan wrote:
I need your advice for cairo_matrix_t; It is declared as:

typedef struct _cairo_matrix {
    double xx; double yx;
    double xy; double yy;
    double x0; double y0;
} cairo_matrix_t;

And usage is like:

cairo_matrix_t   matrix;
cairo_matrix_init_scale (&matrix, w * 5., h * 5.);
cairo_pattern_set_matrix (pattern, &matrix);

Which one of the following is "Lua way"/practical?

- named fields,ie:
  matrix = {xx=.5, yx=1.0, xy=.9, yy=.3, x0=.3, y0=.2}

It looks like named fields would allow something more like:

  matrix = cairo.matrix{scalex=0.5, scaley=0.5}
  matrix = cairo.matrix{rotate=-0.2}

  ... similarly with the various _init() functions from

  ... then operate on it like:
  m0 = matrix:translate{tx=4} -- ty = 0, by default

  m = m0 * matrix

But this requires a user type. Being new to Cairo (and it's concepts), I thought, it is more meaningful to make a one-to-one binding first, then create Lua types on -or in addition to- it. Using Lunar is just habit, a simple namespace table would suffice. BTW, while translating snippets, it seemed two table would be more practical, ie:

C    cairo_set_operator (cr, CAIRO_OPERATOR_IN);
Lua  cairo:set_operator (cr, Cairo.OPERATOR_IN)

C    cairo_set_operator (cr, CAIRO_OPERATOR_IN);
Lua  cairo:set_operator (cr, CAIRO.OPERATOR_IN)

Just throwing ideas out.

I appreciate, thank you!


Hakki Dogusan