lua-users home
lua-l archive

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


OK.  Here's my dilema.  I'm *getting* lua, but there's just a couple 
of things I'm just not grokking.

Let's say, for example, I have a C struct like so:

typedef struct _point3d
{
 double x;
 double y;
 double z;
} Point3D;

What I'd like to be able to do is have a C function (later a class ... 
one step at a time) that could do this:

Point3D add(Point3D a, Point3D b)
{
  // does stuff
}

What would the glue function look like?  And how would I go about 
creating a userdata structure in lua (or tags, still not getting the 
difference here) that would be able to use is.  ie:

-- lua code
 mypoint.x = 1.0
 mypoint.y = 2.0
 mypoint.z = 3.0

 mylength.x = 5.0
 mylength.y = 0.0
 mylength.z = 1.0

 newlength = vecadd(mypoint, mylength)

I'm currently just not seeing the relationship here.  Can I even *do* 
this?

-Ash Matheson
 Programmer at large.