lua-users home
lua-l archive

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


Beginning whith something like the very simple program
listed below (trimmed for size), I would like end up
being able to do the following from Lua:

$ ./luatest
Lua 4.0  Copyright (C) 1994-2000 TeCGraf, PUC-Rio
> x = xform()
> val = x[1][1]
> print(val)
1.1
>

What I have done in the past is build up tables and
pass those around instead of userdata.  It seems that
I should be able to get a similar end result using
helper functions and tag methods, but I just haven't
been able to "get it".  Your tutelage will be appreciated.


/*** file: testlib.c ***/
static int test_xform(lua_State *L) {
    float xform[4][4];

    /* initialize xform */
    xform[0][0] = 1.1;
    .
    .
    xform[3][3] = 4.4;

    /* for now, return nothing useful */
    /* since I can't make it work!    */
    return 0;
}

static const struc luaL_reg testlib[] = {
    {"xform", test_xform}
}

LUALIB_API void testopen (lua_State *L) {
    luaL_openl(L, testlib);
}