lua-users home
lua-l archive

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

On Monday, March 14, 2011 9:27 AM, Henderson, Michael D said

> I understand how to use lua_type and lua_isnumber, at least
> once I'm able to get the index of an item on the stack. What
> I don't understand is how to get the index of items that are
> in a table in the stack. I've been looking at section 24.2
> and the stack dumping example.

I just realized that I have been looking at this the wrong way. The examples in the PIL use lua_getglobal(L, tableName) to put a table at the top of the stack and then process it. I had been skimming over those examples because my table was already on the stack. Duh. Once the table is on the stack, these examples show how to get values out of the table.

That means that I can get the positional parameters out of the table with a for loop and lua_rawgeti.

How about the named parameters? If I know their name, then I could use lua_getfield to get their values. How do I get the names, though? I could scan the query string looking for :[a-zA-Z][a-zA-Z0-9_]* but is there a simpler way?

I'll look at the lua code to see how pairs and ipairs are implemented, that seems like it should show how to do this.