obj_lookupΒΆ
obj_lookup returns the value of a given key.
-
val = obj_lookup(obj, key)
-
val = obj_lookup(obj, key, default)
Return Value
val is the value of the given key. If the key does not exist, the function returns the number 0 (default), an empty string, or throws an exception (see obj_set_str_return).
Parameters
-
obj
obj is the object created with obj_create.
-
key
key is a string or an integer number.
-
default
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 |
---|---|
R2013.2 | You can specify in obj_set_str_return that the look up call throws an exception, if the key does not exist. If a default value is specified and the key does not exist, the function does not throw an exception. |
5.14.7 | New parameter default. |
4.1.0 | New. |
id-1771386