lua-users home
lua-l archive

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


--- Andy Bushnell <andy@carbongraphics.com> wrote:
> when I try to use any of my indent_level assignments above
> I get an error in the for loop (to print the tabs) about
> indent_level not being a number!!!

I don't see the problem in the code you posted. This will work
fine:

function printAll (node, ...)
  print(arg[1])
  print(type(arg[1]))
end

level = 1
printAll("foo", level)


Here's a simple example of what (I think) you're trying to do
(though varargs aren't necessary in this example). Maybe it will
help:

function indent(n)
  for i=1,n do io.write(' ') end
end

function printTable (t, ...)
  for k,v in t do
    indent(arg[1])
    if type(v) == "table" then
      print(k)
      printTable(v, arg[1] + 2)
    else
      print(k.." = "..v)
    end
  end
end

a = {
  ba = {},
  bb = {
    ca = { "da", "db", "dc", },
    cb = {
      da = { "ea" },
    },
  },
}

printTable (a, 1)


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com