lua:lua
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
lua:lua [2008/09/01 14:36] – created deva | lua:lua [2011/06/30 10:57] – deva | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====LUA===== | =====LUA===== | ||
- | ====c/c++==== | + | ====C/C++==== |
+ | ===Arrays=== | ||
<code lua> | <code lua> | ||
myarray = {1,2,3}; | myarray = {1,2,3}; | ||
Line 8: | Line 9: | ||
<code c> | <code c> | ||
lua_createtable(L, | lua_createtable(L, | ||
+ | int top = lua_gettop(L); | ||
+ | // add ' | ||
lua_pushinteger(L, | lua_pushinteger(L, | ||
+ | lua_rawseti(L, | ||
+ | // add ' | ||
lua_pushinteger(L, | lua_pushinteger(L, | ||
+ | lua_rawseti(L, | ||
+ | // add ' | ||
lua_pushinteger(L, | lua_pushinteger(L, | ||
- | lua_rawset(L, -3); | + | lua_rawseti(L, top, 2); |
+ | |||
+ | // and then some code to bind it to " | ||
+ | </ | ||
+ | |||
+ | ===Fields (maps)=== | ||
+ | <code lua> | ||
+ | foo = {} | ||
+ | foo.hello = ' | ||
+ | foo.bar = {} | ||
+ | foo.bar.ping = ' | ||
+ | foo.bar.bas = {} | ||
+ | foo.bar.bas.ding = ' | ||
+ | </ | ||
+ | |||
+ | Corresponds to: | ||
+ | <code c> | ||
+ | int foo, bar, bas; | ||
+ | |||
+ | // Create global ' | ||
+ | lua_newtable(L); | ||
+ | lua_setglobal(L, | ||
+ | |||
+ | // Set foo.hello = ' | ||
+ | lua_getglobal(L, | ||
+ | foo = lua_gettop(L); | ||
+ | lua_pushstring(L, | ||
+ | lua_setfield(L, | ||
+ | |||
+ | // Create ' | ||
+ | lua_getglobal(L, | ||
+ | foo = lua_gettop(L); | ||
+ | lua_newtable(L); | ||
+ | lua_setfield(L, | ||
+ | |||
+ | // Set foo.bar.ping = ' | ||
+ | lua_getglobal(L, | ||
+ | foo = lua_gettop(L); | ||
+ | lua_getfield(L, | ||
+ | bar = lua_gettop(L); | ||
+ | lua_pushstring(L, | ||
+ | lua_setfield(L, | ||
+ | |||
+ | // Create ' | ||
+ | lua_getglobal(L, | ||
+ | foo = lua_gettop(L); | ||
+ | lua_getfield(L, | ||
+ | bar = lua_gettop(L); | ||
+ | lua_newtable(L); | ||
+ | lua_setfield(L, | ||
+ | |||
+ | // Set foo.bar.bas.ding = ' | ||
+ | lua_getglobal(L, | ||
+ | foo = lua_gettop(L); | ||
+ | lua_getfield(L, | ||
+ | bar = lua_gettop(L); | ||
+ | lua_getfield(L, | ||
+ | bas = lua_gettop(L); | ||
+ | lua_pushstring(L, | ||
+ | lua_setfield(L, | ||
+ | |||
+ | lua_pop(L, 1); // pop ' | ||
</ | </ |
lua/lua.txt · Last modified: 2012/04/20 13:53 by deva