lua-users home
lua-l archive

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

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;
> [...]
> - named fields,ie:
>    matrix = {xx=.5, yx=1.0, xy=.9, yy=.3, x0=.3, y0=.2}
> - or, array, ie:
>    matrix = {.5, 1.0, .9, .3, .3, .2}
> - or, something else

I vote for named fields :-)

As a general rule, I think C arrays should be put in array part of Lua
tables, with the same number of dimension, and a 1 offset, and C
structures should use named fields in tables. The exception would be if
the array cells are used as pseudo strutct members with constants
indices (like char* data[2]; data[CST_INDEX_NAME] = "me";
data[CST_INDEX_ADDRESS] = "here";).

Also the original Cairo designers probably had good reasons to use a
struct rather than a 1- or 2-dimensionnal array, you shouldn't do the
contrary unless you have an even better reason to do so.

My 2 cents :-)