Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua table lookup

Tags:

find

lua

I know this seems like a dumb question but how do I search a lua table for a given item? let's say I have a table like this:

local table = {
    itemA = 0.8,
    itemB = 1.2,
    itemC = 1
}

Is there, say, a function named table.find or something? It's also late here so I'm not thinking too clearly at the moment...

like image 801
RCIX Avatar asked Jul 22 '09 09:07

RCIX


1 Answers

You can lookup items in the table either using the [] operator:

x=table["itemA"]

or by using the . operator:

x=table.itemA

Edited because original code is now syntax-correct.

like image 67
Martin B Avatar answered Oct 16 '22 04:10

Martin B