lua-users home
lua-l archive

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

How can I set the variables of a data structure using an indexed array pointer?
Tolua doesn't seem to create such a binding?


Package file for Tolua:

class vec3 {

float x;
float y;
float z;

vec3() {};
vec3 & operator[] (int index) { return this[index]; };

// These are global variables in my program.  vectors is allocated,
// num_vectors=100, vectors=new vec3[100]; before running Lua script.

extern int num_vectors;
extern vec3 *vectors;


Lua test script:

function printf(...)

-- x,y,z variables are NOT set - values DO NOT change
for i=1,num_vectors do
  vectors[i].x = 10.0;
  vectors[i].y = 10.0;
  vectors[i].z = 10.0;
printf( "vectors: %f, %f, %f\n", vectors[i].x, vectors[i].y, vectors[i].z );


Note that Tolua does allow me to do this:
v = vec3:new();
vectors[i] = v;

But it doesn't let me set x,y,z variables individually.

Take charge with a pop-up guard built on patented Microsoft® SmartScreen Technology. Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.