C API、lua_newtable(), lua_gettable(), lua_settable()
/* * $ gcc -Wall -W -I/usr/include/lua50 -o 2008102900 -llua50 2008102900.c */ #include <stdio.h> #include <lua.h> int main(void) { lua_State *L; L = lua_open(); lua_newtable(L); lua_pushstring(L, "foo"); lua_gettable(L, 1); printf("%d\n", lua_isnil(L, -1)); lua_pop(L, 1); lua_pushstring(L, "foo"); lua_pushnumber(L, 10); lua_settable(L, 1); lua_pushstring(L, "foo"); lua_gettable(L, 1); printf("%s\n", lua_typename(L, lua_type(L, -1))); printf("%d\n", (int)lua_tonumber(L, -1)); lua_close(L); return 0; }
で、
1 number 10