The table function in Lua is really powerful. Because table is the only data structure in LUA. Today a bit dizzy, less say two more copies of code it.
Instance:
Suppose you want to list all the identifiers that appear in a source code, in a way, you need to filter out the reserved words of those languages themselves . Some C programmers like to use a string array to represent, all the reserved words in the array, for each identifier into the array to see if it is a reserved word, and sometimes in order to improve query efficiency, the use of binary search or hash algorithm for the array storage .
LUA indicates that this collection has a simple and efficient way to store all the elements in the collection as subscripts in a table , without having to look up the table, just to test to see if the corresponding subscript element value for the given element is nil. Like what:
Reserved ={[" while"] =true, ["End"] =true, ["function"] =true, ["Local"] =true,} forWinchAllwords () Do ifRESERVED[W] Then --' W ' is a reserved word...
You can also use helper functions to construct the collection more clearly:
functionSet (list)LocalSet ={} for_, Linch Ipairs(list) DoSET[L] =true End returnSetEndreserved= set{" while","End","function","Local", }
Well, this way, it's a lot of places.
LUA applies--tables app to find out if it's a reserved word