lua-users home
lua-l archive

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


Hi,
      I would like to define an array with the following structure:

      typedef struct
      {
          int size;
          double x_values[1];  /* x variable part */
          double y_values[1];  /* y variable part */
      } PairArray;

      As you can see, it is quite similar to the NumArray defined in
ch28, pil, with the only difference being that there are a pair of
values (x,y) for each index. The size of PairArray is provided by user
at run time. Therefore, I wrote a "new" function for PairArray , which
is again similar to the one on pil:

      static PairArray PairArray_alloc(lua_State *L, int size)
      {
          size_t nbytes = sizeof(PairArray) + 2*sizeof(double)*(size-1);
          PairArray* p  = (PairArray*)lua_newuserdata(L, nbytes);