Script values
Two scripts exchange copies. Whatever crosses between them, in either direction, arrives as an ordinary Lua value of the script it arrives in:
| What crosses | What arrives |
|---|---|
nil, a boolean, a number, a string |
The same value |
| An engine handle | The same number - it names the same window or mesh |
| A table | A copy, made field by field; nested tables are copied with it |
| A function | A function that calls the original over there |
It does not matter which way the value travels or which call carries it:
set, get, the arguments and results of
call, the arguments of a function you put into another
script, a field read with table_get. A value you
receive is yours, nothing has to be given back, and changing it changes nothing
in the other script.
A reference, when you want one
A copy is what you want nearly always. The exception is a table you mean to go on writing into after the other script has it, where a copy would stop being the same table. For that there is a reference, and two functions give one:
make_tablemakes a table in the other script;make_functionmakes a function there that calls one of yours.
local state = natiny.script.make_table(mod) -- a reference
print(state.type == natiny.script.TABLE) --> true
print(state.script == mod) --> true
| Field | Type | Description |
|---|---|---|
type |
number |
natiny.script.TABLE or natiny.script.FUNCTION |
script |
number |
The script it lives in |
A reference names the thing over there. table_set
through it is seen at once, and passing it to set gives the
other script that same table under a name. What the table functions read out of
it is a copy again.
There is nothing to release. A reference is released when Lua collects it, the same way a table of your own is freed when nothing refers to it any more.
Type tags
| Constant | Meaning |
|---|---|
natiny.script.NIL |
nothing |
natiny.script.BOOL |
true or false |
natiny.script.NUMBER |
a number |
natiny.script.STRING |
a string, bytes and not necessarily text |
natiny.script.HANDLE |
an engine handle, which is a number |
natiny.script.TABLE |
a table; reference.type for a table reference |
natiny.script.FUNCTION |
a function; reference.type for a function reference |
natiny.script.MAX_ARGS and natiny.script.MAX_RESULTS are both 16.