Name
RawGet -- read value from table without metamethods (V2.0)
Synopsis
v = RawGet(t, key)
Function
This function reads the value at index key from the specified table and returns it. Basically, this function does the same as the following expression:

 
v = t[key]

The difference is that RawGet() will never invoke any metamethod and it will not fail if the specified key does not exist. Thus, it is useful for checking if a specific table key exists, or for reading values from tables without invoking any metamethod. See Metamethods for details.

Please note that string indices are normally in lower case except when using brackets to initialize the table index. Consider the following code:

 
t1 = {TEST = 1}
DebugPrint(RawGet(t1, "TEST"), RawGet(t1, "test")) ; prints Nil/1
t2 = {}
t2.TEST = 1
DebugPrint(RawGet(t2, "TEST"), RawGet(t2, "test")) ; prints Nil/1
t3 = {}
t3["TEST"] = 1
DebugPrint(RawGet(t3, "TEST"), RawGet(t3, "test")) ; prints 1/Nil

As you can see, when initializing the TEST element using curly braces or the dot operator, the string index TEST is automatically converted to lower case. When using brackets to initialize the TEST element, however, no conversion is taking place. This also has the consequence that you can't access non-lower case string indices initialized with the bracket syntax using the dot operator because the dot operator always converts the index to lower case.

Starting with Hollywood 6.0 you can also use the convenience function HaveItem() to check if a table item exists. See HaveItem for details.

Inputs
t
table to query
key
key to search for
Results
v
value of the specified key or Nil if key does not exist in the table
Example
t = {x = 10, y = 20}
NPrint(RawGet(t, "x"))
NPrint(RawGet(t, "y"))
NPrint(RawGet(t, "z"))
The code above will print 10 / 20 / Nil.

Show TOC