User Tools

Site Tools


lua:lua

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lua:lua [2011/06/30 10:57]
deva
lua:lua [2012/04/20 13:53] (current)
deva
Line 21: Line 21:
  
 // and then some code to bind it to "myarray" // and then some code to bind it to "myarray"
 +</code>
 +
 +===Array of arrays===
 +An array with 10 entries each containing 2 entries:
 +<code>
 +  int num = 10;
 +  int sz = 2;
 +  
 +  lua_createtable(L, num, 0);
 +  int toptop = lua_gettop(L);
 +
 +  for(int i = 1; i <= num; i++) {
 +    lua_createtable(L, 0, sz);
 +    int top = lua_gettop(L);
 +
 +    for(int j = 1; j <= sz; j++) {
 +      char buf[10];
 +      sprintf(buf, "%d-%d", i, j);
 +      lua_pushstring(L, buf);
 +      lua_rawseti(L, top, j);
 +    }
 +
 +    lua_rawseti(L, toptop, i);
 +  }
 +
 +  return 1;
 </code> </code>
  
lua/lua.1309424233.txt.gz ยท Last modified: 2011/06/30 10:57 by deva