lua:lua
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
lua:lua [2008/09/01 15:42] – 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 20: | Line 21: | ||
// and then some code to bind it to " | // 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