lua-users home
lua-l archive

Iterating over a table from C

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi guys,
Does anyone know if it's possible to iterate over the contents of a
table from C?
I'm creating something similar to the configuration file example in
"Programming In Lua" 2ed. For instance, given this table (stored as a
global variable):
 shapes = {
 one = {
 colour = 'red'
 shape = 'round'
 }
 two = {
 colour = 'blue'
 shape = 'triangle
 }
 }
I want to make my C code iterate over 'one' and 'two'. In Lua it's
fairly simple --
 for x in shapes do
 print "A " .. shapes[x]['colour'] .. " " .. shapes[x]['shape']
 end
(I suspect I've hammed the syntax a bit, but you get the idea)
How can I do this in C?
Thanks,
-- 
Phil.
lists@philpem.me.uk
http://www.philpem.me.uk/

AltStyle によって変換されたページ (->オリジナル) /