4. The auxiliary library

Comenzar desde el principio
                                        

void luaL_checkany (lua_State *L, int narg);

Checks whether the function has an argument of any type (including nil) at position narg.

--------------------------------------------------------------------------------

luaL_checkint

[-0, +0, v]

int luaL_checkint (lua_State *L, int narg);

Checks whether the function argument narg is a number and returns this number cast to an int.

--------------------------------------------------------------------------------

luaL_checkinteger

[-0, +0, v]

lua_Integer luaL_checkinteger (lua_State *L, int narg);

Checks whether the function argument narg is a number and returns this number cast to a lua_Integer.

--------------------------------------------------------------------------------

luaL_checklong

[-0, +0, v]

long luaL_checklong (lua_State *L, int narg);

Checks whether the function argument narg is a number and returns this number cast to a long.

--------------------------------------------------------------------------------

luaL_checklstring

[-0, +0, v]

const char *luaL_checklstring (lua_State *L, int narg, size_t *l);

Checks whether the function argument narg is a string and returns this string; if l is not NULL fills *l 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 narg);

Checks whether the function argument narg is a number and returns this number.

--------------------------------------------------------------------------------

luaL_checkoption

[-0, +0, v]

int luaL_checkoption (lua_State *L,

int narg,

const char *def,

const char *const lst[]);

Checks whether the function argument narg 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 narg or if 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

Lua coding guideDonde viven las historias. Descúbrelo ahora