[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua userdata question
- From: Michael Roth <mroth@...>
- Date: Sun, 17 Jan 2010 23:55:04 +0100
> typedef struct
> {
> int size;
> double x_values[1]; /* x variable part */
> double y_values[1]; /* y variable part */
> } PairArray;
Get your data structures and types right and don't fight against the language
but instead use its features:
typedef struct
{
double x;
double y;
} Pair;
typedef struct
{
int size;
Pair values[];
} PairArray;
> static PairArray PairArray_alloc(lua_State *L, int size)
> {
> size_t nbytes = sizeof(PairArray) + 2*sizeof(double)*(size-1);
size_t nbytes = sizeof(PairArray) + size * sizeof(Pair);
--
Michael Roth