natiny_script_table_get_item

C
NatinyScriptValue natiny_script_table_get_item(NatinyScript script,
                                               NatinyScriptValue table,
                                               uint32_t index);

Reads an item of a table by number.

Parameters

Name Type Description
script NatinyScript The state the table lives in
table NatinyScriptValue The table to read
index uint32_t The integer key. Lists in a script start at 1

Returns

Type Description
NatinyScriptValue Value stored at index, or NATINY_SCRIPT_NIL when the item or table handle is missing

Example

C
uint32_t count = natiny_script_table_get_length(script, tags);

for (uint32_t i = 1; i <= count; ++i) {
    NatinyScriptValue tag = natiny_script_table_get_item(script, tags, i);
    if (tag.type == NATINY_SCRIPT_STRING)
        printf("%.*s\n", (int)tag.string.size, tag.string.data);
}

Notes

  • A table or a function read out comes back as a borrowed handle, valid until the next call into the state, with nothing to release.
  • A returned string remains valid until the next natiny_script_run, natiny_script_call or natiny_script_call_value on the state.