A Simple Syntax Question: "for _, foo .."

I am trying to learn Corons SDK / Lua and use it to program a small game. One of the ways I’m learning is by looking at sample code. However I get hung up on tiny questions, like syntax questions. The answers to some are harder to find than others.

For example, I was seeing this syntax for iterating through a table that does not have numerical keys, using “pairs()”. The following is from the sample code “FrameAnimation2” :

for \_,item in ipairs( params ) do  
 local ball = newBall( item )  
 collection[#collection + 1] = ball  
end  

It’s the underscore “_” I couldn’t find any documentation for. I’ve seen it used in other function calls too. By noodling around I figured it’s probably used when you don’t want to use that value - kind of a placeholder.

So this just a style thing? How would I have looked it up instead of having to spend so much time researching and finally having to experiment? I have a Lua book (Roberto Ierusalimschy’s), but it wasn’t in there…

Thanks [import]uid: 128346 topic_id: 23448 reply_id: 323448[/import]

I’m pretty sure that the underscore is just a variable name, same as any other, and in the example you posted is one of the iterators in the for loop.

the double underscore is used to define metatables, like “__tostring” et c. [import]uid: 120 topic_id: 23448 reply_id: 93995[/import]

the _ is a valid variable, generally used when the programmer wants to discard that value or does not want to really use it anywhere. [import]uid: 3826 topic_id: 23448 reply_id: 94002[/import]

OK thanks for confirming that.

Is this a Lua-specific thing, or used more generally in programming? [import]uid: 128346 topic_id: 23448 reply_id: 94006[/import]

I’ve only seen it in Lua. [import]uid: 10389 topic_id: 23448 reply_id: 94347[/import]