natiny_script_table_set_item
void natiny_script_table_set_item(NatinyScript script, NatinyScriptValue table,
uint32_t index, NatinyScriptValue value);
Writes an item of a table by number.
Parameters
| Name | Type | Description |
|---|---|---|
script |
NatinyScript |
The state the table lives in |
table |
NatinyScriptValue |
The table to write to |
index |
uint32_t |
The integer key. Lists in a script start at 1 |
value |
NatinyScriptValue |
Value to store; string bytes are copied before the function returns |
Example
/* The `arg` table a standalone interpreter provides: arg[0] is the
executable, arg[1] onwards what followed it. */
NatinyScriptValue args = natiny_script_make_table(script);
for (int i = 0; i < argc; ++i)
natiny_script_table_set_item(script, args, (uint32_t)i,
natiny_script_make_string(argv[i]));
natiny_script_set(script, "arg", args);
Notes
- Indices are the script's, not C's. Write a list from
1, and use0only when you mean a slot outside the list - asarg[0]above does.