lua-users home
lua-l archive

Re: lua userdata question

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


> 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

AltStyle によって変換されたページ (->オリジナル) /