lua-users home
lua-l archive

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


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.