Document source
- Source
- Lua 5.5.1 Documentation
- Upstream version
- Lua 5.5.1
- Document status
- Canonical language
Auxiliary functions and types: callmeta–checkversion
luaL_callmeta
[-0, +(0|1), e]
int luaL_callmeta (lua_State *L, int obj, const char *e);Calls a metamethod.
If the object at index obj has a metatable and this metatable has a field e, this function calls this field passing the object as its only argument. In this case this function returns true and pushes onto the stack the value returned by the call. If there is no metatable or no metamethod, this function returns false without pushing any value on the stack.
luaL_checkany
[-0, +0, v]
void luaL_checkany (lua_State *L, int arg);Checks whether the function has an argument of any type (including nil) at position arg.
luaL_checkinteger
[-0, +0, v]
lua_Integer luaL_checkinteger (lua_State *L, int arg);Checks whether the function argument arg is an integer (or can be converted to an integer) and returns this integer.
luaL_checklstring
[-0, +0, v]
const char *luaL_checklstring (lua_State *L, int arg, size_t *l);Checks whether the function argument arg is a string and returns this string; if l is not NULL fills its referent with the string’s length.
This function uses lua_tolstring to get its result, so all conversions and caveats of that function apply here.
luaL_checknumber
[-0, +0, v]
lua_Number luaL_checknumber (lua_State *L, int arg);Checks whether the function argument arg is a number and returns this number converted to a lua_Number.
luaL_checkoption
[-0, +0, v]
int luaL_checkoption (lua_State *L,
int arg,
const char *def,
const char *const lst[]);Checks whether the function argument arg is a string and searches for this string in the array lst (which must be NULL-terminated). Returns the index in the array where the string was found. Raises an error if the argument is not a string or if the string cannot be found.
If def is not NULL, the function uses def as a default value when there is no argument arg or when this argument is nil.
This is a useful function for mapping strings to C enums. (The usual convention in Lua libraries is to use strings instead of numbers to select options.)
luaL_checkstack
[-0, +0, v]
void luaL_checkstack (lua_State *L, int sz, const char *msg);Grows the stack size to top + sz elements, raising an error if the stack cannot grow to that size. msg is an additional text to go into the error message (or NULL for no additional text).
luaL_checkstring
[-0, +0, v]
const char *luaL_checkstring (lua_State *L, int arg);Checks whether the function argument arg is a string and returns this string.
This function uses lua_tolstring to get its result, so all conversions and caveats of that function apply here.
luaL_checktype
[-0, +0, v]
void luaL_checktype (lua_State *L, int arg, int t);Checks whether the function argument arg has type t. See lua_type for the encoding of types for t.
luaL_checkudata
[-0, +0, v]
void *luaL_checkudata (lua_State *L, int arg, const char *tname);Checks whether the function argument arg is a userdata of the type tname (see luaL_newmetatable) and returns the userdata’s memory-block address (see lua_touserdata).
luaL_checkversion
[-0, +0, v]
void luaL_checkversion (lua_State *L);Checks whether the code making the call and the Lua library being called are using the same version of Lua and the same numeric types.