lua-users home
lua-l archive

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

> 2. Have the position vector be returned as a reference to the actual vector 
> within the matrix. Depending on how you expose userdata, and how you've 
> programmed your classes, this will be easy or difficult. If it is difficult, 
> consider a more thorough rewrite.

That is exactly my question... How do make m.pos return a reference to the position vector residing inside my matrix? Here are my C++ classes:

class Vector {
    float x,y,z;

class Matrix {
    Vector front, right, up, pos;

My __index method for the matrix is:

    Matrix *m=Lua_CheckMatrix(L,1);
    const char *s=luaL_checkstring(L,2);
    if (strcmp(s,"pos")==0) {
        return 1;

Currently it creates a new vector on the stack. How can I change it to create a reference to pos instead?