lua-users home
lua-l archive

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


Hi,

I've been (continuing to) implement a vector class in lua with pointers to
vectors in my application using a combination between userdata and tables.
Here's how it works:

I'm implementing a vector class using tables.  I intend to do most of my
vector calculations in lua, however some things are implemented in C out of
necessity and familiarity.  So, if have the (lua) line

localvec = newVector(10, 10, 10)

it pushes a table onto the c2lua stack that has x, y and z values of 10, 10,
10.
I also have a pointer to global vectors within my application so that if I
have the (lua) line

localvec = GlobalVec

with GlobalVec being a userdata that points to an application variable (in
c), the getGlobal tag method for GlobalVec pushes a table with the
appropriate values onto the stack.  The getGlobal tag method pushing a table
onto the stack also allows me to type

localnum = GlobalVec.x

because once the getGlobal tag method pushes the appropriate table onto the
c2lua stack, it gets treated like a normal lua table from then on.  I don't
need a getTable tag method.  Unfortunately, the getGlobal tag method also
gets called when I do the following:

GlobalVec.x = localnum

but at this point, I would much rather have lua call the setTable tag method
so that I can set the value of my application's global variable directly
(again, as per an email I sent two weeks ago).  I tried setting the tag for
the table I push onto the stack in the getGlobal tag method, but the
userdata value gets lost once the table is pushed onto the stack, thus I
can't get the pointer info when the setTable tag method is called.  How do I
get around this problem?  Do I call setGlobal (or rawSetGlobal) to rebind
the variable name to the table I've pushed onto the c2lua stack?  Can I push
the userdata *and* the table onto the c2lua stack?

I'm not exactly sure where to go here.

Also, does lua_endblock() flush the c2lua stack?  I think it does, I just
want to make sure.

Thanks,
Falko

PS Thanks for the response on my previous email Steve Dekorte, that worked
perfectly!