Lua funksjonsbibliotek
Referanse: Lua 5.4 Referansehåndbok Vis detaljer →
Lua C API
lua_absindex
C APIint lua_absindex (lua_State *L, int idx);
Converts the acceptable index into an equivalent absolute index.
lua_Alloc
C APItypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
, a pointer to the block being allocated/reallocated/freed;, the original size of the block or some code about what is being allocated; and, the new size of the block. When is not, is the size of the block pointed by, that is, the size given when it was allocated or reallocated. When is, encodes the kind of object that Lua is allocating. is any of, , , , or when Lua is creating a new object of that type. When is some other value, Lua is allocating memory for something else. Lua assumes the following behavior from the allocator function: When is zero, the allocator must behave like and then return. When is not zero, the allocator must behave like. In particular, the allocator returns if and only if it cannot fulfill the request. Here is a simple implementation for the allocator function. It is used in the auxiliary library by. static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { ud; osize; /* not used */ if { free; return NULL; } else return realloc; } Note that ISO C ensures that has no effect and that is equivalent to.
lua_arith
C APIvoid lua_arith (lua_State *L, int op);
Performs an arithmetic or bitwise operation over the two values at the top of the stack, with the value on the top being the second operand, pops these values, and pushes the result of the operation. The function follows the semantics of the corresponding Lua operator. The value of must be one of the following constants: : performs addition : performs subtraction : performs multiplication : performs float division : performs floor division : performs modulo : performs exponentiation : performs mathematical negation : performs bitwise NOT : performs bitwise AND : performs bitwise OR : performs bitwise exclusive OR : performs left shift : performs right shift
lua_atpanic
C APIlua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
Sets a new panic function and returns the old one.
lua_call
C APIvoid lua_call (lua_State *L, int nargs, int nresults);
Calls a function. Like regular Lua calls, respects the metamethod. So, here the word "function" means any callable value. To do a call you must use the following protocol: first, the function to be called is pushed onto the stack; then, the arguments to the call are pushed in direct order; that is, the first argument is pushed first. Finally you call ; is the number of arguments that you pushed onto the stack. When the function returns, all arguments and the function value are popped and the call results are pushed onto the stack. The number of results is adjusted to, unless is. In this case, all results from the function are pushed; Lua takes care that the returned values fit into the stack space, but it does not ensure any extra space in the stack. The function results are pushed onto the stack in direct order, so that after the call the last result is on the top of the stack. Any error while calling and running the function is propagated upwards. The following example shows how the host program can do the equivalent to this Lua code: a = f
Auxiliary Library
luaL_addchar
Hjelpemiddelvoid luaL_addchar (luaL_Buffer *B, char c);
Adds the byte to the buffer.
luaL_addgsub
Hjelpemiddelconst void luaL_addgsub (luaL_Buffer *B, const char *s, const char *p, const char *r);
Adds a copy of the string to the buffer, replacing any occurrence of the string with the string.
luaL_addlstring
Hjelpemiddelvoid luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
Adds the string pointed to by with length to the buffer. The string can contain embedded zeros.
luaL_addsize
Hjelpemiddelvoid luaL_addsize (luaL_Buffer *B, size_t n);
Adds to the buffer a string of length previously copied to the buffer area.
luaL_addstring
Hjelpemiddelvoid luaL_addstring (luaL_Buffer *B, const char *s);
Adds the zero-terminated string pointed to by to the buffer.