lua-users home
lua-l archive

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


Hello Jeremy,

    I have sent a private e-mail to you.

                                    The God's Peace,

                                                                    Leandro.
----- Original Message -----
From: "Jeremy Cowgar" <jc@cowgar.com>
To: "Lua List" <lua@bazar2.conectiva.com.br>
Sent: Tuesday, December 16, 2003 5:03 PM
Subject: Reading table variable in C


> Greetings...
>
> How can I read a table variable in my C function? Here's my senario:
>
> (lua code)
> greeter.name = "Jeremy"
> greeter.age = 129
> greeter:sayHiAndAge()
>
> (c code)
>
> static int Lua_SayHiAndAge(lua_State *L) {
> /* param 1 should be table (where I can get .name, .age, but how? */
> const char *name = // get name from table
> const int age = // get age from table
> printf("Hello, %s... you are %i years old!\n", name, age);
> return 0;
> }
>
> (later in c code)
> ...
> lua_newtable(L)
> lua_pushstring(L, "sayHiAndAge");
> lua_pushcfunction(L, Lua_SayHiAndAge);
> lua_settable(L, -3);
> lua_setglobal(L, "greeter");
> ...
>
> Thanks,
>
> ----
> jeremy <jc@cowgar.com>
>
> The idle man does not know what it is to enjoy rest.
>