i'm working on exporting contents of lua table html file can display contents in browser. right i'm having problems passing function argument table key.
i have sparse table such:
map = {} x = 1, 20 map[x] = {} y = 1, 20 map[x][y] = {} map[x][y].node = math.random(1,20) map[x][y].image = "path/to/image.png" end end
i pass table function such: htmparser:_dumpsparsetohtml(map, 20, 20) map = table want pass, 20,20 = width , height of array. somewhere in _dumpsparsetohtml write values of v.node , v.image file. how handle exact same thing without knowing name of keys in table? example map contain map[x][y].value, map[x][y].gfx, map[x][y].nodetype, , pass them htmparser:_dumpsparsetohtml(map, 20, 20, value, gfx, nodetype, etc).
i know lua can handle variable number of arguments, defining function as: _dumpsparsetohtml(map, 20, 20, ...). tried following:
--_table = map i,v in ipairs(arg) file:write("<td>".._table[x][y].v.."</td>) end
the error is: "attempt concatenate field 'v' (a nil value). so, question is: how pass variable number of arguments table keys?
you need use _table[x][y][v]
that. _table[x][y].v
_table[x][y]["v"]
.
Comments
Post a Comment