operator (that is, may call metamethods). Otherwise returns 0.
Also returns 0 if any of the indices is non valid.
lua_load *lua_load()*
>c
int lua_load (lua_State *L,
lua_Reader reader,
void *data,
const char *chunkname);
<
Loads a Lua chunk. If there are no errors, `lua_load` pushes the
compiled chunk as a Lua function on top of the stack. Otherwise, it
pushes an error message. The return values of `lua_load` are:
- `0`: no errors;
- `LUA_ERRSYNTAX` : syntax error during pre-compilation;
- `LUA_ERRMEM` : memory allocation error.
This function only loads a chunk; it does not run it.
`lua_load` automatically detects whether the chunk is text or binary,
and loads it accordingly (see program `luac`).
The `lua_load` function uses a user-supplied `reader` function to read
the chunk (see |lua_Reader|). The `data` argument is an opaque
value passed to the reader function.
The `chunkname` argument gives a name to the chunk, which is used for
error messages and in debug information (see |lua-apiDebug|).
lua_newstate *lua_newstate()*
>c
lua_State *lua_newstate (lua_Alloc f, void *ud);
<
Creates a new, independent state. Returns `NULL` if cannot create the
state (due to lack of memory). The argument `f` is the allocator
function; Lua does all memory allocation for this state through this
function. The second argument, `ud`, is an opaque pointer that Lua
simply passes to the allocator in every call.
lua_newtable *lua_newtable()*
>c
void lua_newtable (lua_State *L);
<
Creates a new empty table and pushes it onto the stack. It is
equivalent to `lua_createtable(L, 0, 0)` (see
|lua_createtable()|).
lua_newthread *lua_newthread()*
>c
lua_State *lua_newthread (lua_State *L);
<
Creates a new thread, pushes it on the stack, and returns a pointer to
a `lua_State` (see |lua_State|) that represents this new
thread. The new state returned by this function shares with the
original state all global objects (such as tables), but has an
independent execution stack.
There is no explicit function to close or to destroy a thread. Threads
are subject to garbage collection, like any Lua object.
lua_newuserdata *lua_newuserdata()*
>c
void *lua_newuserdata (lua_State *L, size_t size);
<
This function allocates a new block of memory with the given size,
pushes onto the stack a new full userdata with the block address, and
returns this address.
*userdata*
Userdata represents C values in Lua. A full userdata represents a
block of memory. It is an object (like a table): you must create it,
it can have its own metatable, and you can detect when it is being
collected. A full userdata is only equal to itself (under raw
equality).
When Lua collects a full userdata with a `gc` metamethod, Lua calls
the metamethod and marks the userdata as finalized. When this userdata
is collected again then Lua frees its corresponding memory.
lua_next *lua_next()*
>c
int lua_next (lua_State *L, int index);
<
Pops a key from the stack, and pushes a key-value pair from the table
at the given index (the "next" pair after the given key). If there are
no more elements in the table, then `lua_next` returns 0 (and pushes
nothing).