Document source
- Source
- Lua 5.5.1 Documentation
- Upstream version
- Lua 5.5.1
- Document status
- Canonical language
Auxiliary functions and types: makeseed–pushresultsize
luaL_makeseed
[-0, +0, –]
unsigned int luaL_makeseed (lua_State *L);Returns a value with a weak attempt for randomness. The parameter L can be NULL if there is no Lua state available.
luaL_newlib
[-0, +1, m]
void luaL_newlib (lua_State *L, const luaL_Reg l[]);Creates a new table and registers there the functions in the list l.
It is implemented as the following macro:
(luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))The array l must be the actual array, not a pointer to it.
luaL_newlibtable
[-0, +1, m]
void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);Creates a new table with a size optimized to store all entries in the array l (but does not actually store them). It is intended to be used in conjunction with luaL_setfuncs (see luaL_newlib).
It is implemented as a macro. The array l must be the actual array, not a pointer to it.
luaL_newmetatable
[-0, +1, m]
int luaL_newmetatable (lua_State *L, const char *tname);If the registry already has the key tname, returns 0. Otherwise, creates a new table to be used as a metatable for userdata, adds to this new table the pair __name = tname, adds to the registry the pair [tname] = new table, and returns 1.
In both cases, the function pushes onto the stack the final value associated with tname in the registry.
Usage note: Beware the use of the return value of this function to conditionally initializes the new metatable (e.g., by adding metamethods to it). If the initialization raises an error, the metatable will not be properly initialized, but a subsequent execution of that code will detect that the metatable already exists and then skip the initialization.
luaL_newstate
[-0, +0, –]
lua_State *luaL_newstate (void);Creates a new Lua state. It calls lua_newstate with luaL_alloc as the allocator function and the result of luaL_makeseed(NULL) as the seed, and then sets a warning function and a panic function (see §4.4) that print messages to the standard error output.
Returns the new state, or NULL if there is a memory allocation error.
luaL_opt
[-0, +0, –]
T luaL_opt (L, func, arg, dflt);This macro is defined as follows:
(lua_isnoneornil(L,(arg)) ? (dflt) : func(L,(arg)))In words, if the argument arg is nil or absent, the macro results in the default dflt. Otherwise, it results in the result of calling func with the state L and the argument index arg as arguments. Note that it evaluates the expression dflt only if needed.
luaL_optinteger
[-0, +0, v]
lua_Integer luaL_optinteger (lua_State *L,
int arg,
lua_Integer d);If the function argument arg is an integer (or it is convertible to an integer), returns this integer. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_optlstring
[-0, +0, v]
const char *luaL_optlstring (lua_State *L,
int arg,
const char *d,
size_t *l);If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error.
If l is not NULL, fills its referent with the result’s length. If the result is NULL (only possible when returning d and d == NULL), its length is considered zero.
This function uses lua_tolstring to get its result, so all conversions and caveats of that function apply here.
luaL_optnumber
[-0, +0, v]
lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);If the function argument arg is a number, returns this number as a lua_Number. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_optstring
[-0, +0, v]
const char *luaL_optstring (lua_State *L,
int arg,
const char *d);If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_prepbuffer
[-?, +?, m]
char *luaL_prepbuffer (luaL_Buffer *B);Equivalent to luaL_prepbuffsize with the predefined size LUAL_BUFFERSIZE.
luaL_prepbuffsize
[-?, +?, m]
char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);Returns an address to a space of size sz where you can copy a string to be added to buffer B (see luaL_Buffer). After copying the string into this space you must call luaL_addsize with the size of the string to actually add it to the buffer.
luaL_pushfail
[-0, +1, –]
void luaL_pushfail (lua_State *L);Pushes the fail value onto the stack (see §6).
luaL_pushresult
[-?, +1, m]
void luaL_pushresult (luaL_Buffer *B);Finishes the use of buffer B leaving the final string on the top of the stack.
luaL_pushresultsize
[-?, +1, m]
void luaL_pushresultsize (luaL_Buffer *B, size_t sz);Equivalent to the sequence luaL_addsize, luaL_pushresult.