obj_lookup returns the value of a given key.
Return Value
val is the value of the given key. If the key does not exist, by default the function returns the number 0 (see obj_set_str_return).
Parameters
obj is the object created with obj_create.
key is a string or an integer number.
default is the value that will be returned if the key does not exists.
Comment
An alternative syntax for val = obj_lookup(obj, key) is val = obj.lookup(key) or val = obj[key]. If the key is a string and matches the rules for function names val = m.key is allowed too.
Example
obj = obj_create()
obj.set_at(1, 123)
obj.set_at("a", 456)
print obj_lookup(obj, 1)
print obj.lookup(1)
print obj[1]
print obj_lookup(obj, "a")
print obj.lookup("a")
print obj["a"]
print obj.a
History
| Version | Description |
|---|---|
| 5.14.7 | New parameter default. |
| 4.1.0 | New. |
id-1771386