[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Tables, Functions & varargs
- From: "Andy Bushnell" <andy@...>
- Date: Thu, 9 Oct 2003 22:16:35 -0600
Another (newbie) question here (and I did RTFM first - but it isnt sinking
I have a function to print the name of a node (a tolua'd data structure)
function printName( node, ... )
print( node:getName() )
I want to be able to call printName with some optional arguments. In my
print example I want to call it with an "indent level" number which the
function can key-off & print appropriate tabs before writing the name as
Another function is supposed to get passed the exact same argument &
increment/decrement the value which will be used in printName.
so at the top level I have code like:
level = 1
printAll(root,level) where printAll is defined as printAll(node,...)
I believe my level number value is put into a table & passed to varargs
functions as a table. Hence in my vararg functions Ive tried...
indent_level = arg
indent_level = unpack(arg) // not sure what/when or why i'd use the unpack
indent_level = tonumber(arg)
my intention being that I could then...
arg = indent_level + 1 --or minus 1
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!!!
Im a bit confused and I couldnt find an example which seems to do what i'm
doing - so any help appreciated!:-)
Lua is very cool though!