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