Default welcome message to get attention!

Use PrimaThemes coupon code to save you 15% off on your order.

Shop Now!

When a C features is named, its upvalues are situated at specific pseudo-indices

3.4 C Closures

When a-c work is made, it is possible to connect some beliefs with it, thus promoting a C closing; these values are called upvalues consequently they are accessible to the event each time it really is known as (discover lua_pushcclosure ).

These pseudo-indices are manufactured because of the macro lua_upvalueindex . 1st advantages connected with a function are at situation lua_upvalueindex(1) , etc. Any access to lua_upvalueindex(n) , where n was higher than the sheer number of upvalues associated with present function ( not greater than 256), generates a reasonable (but invalid) list.

3.5 Registry

Lua provides a registry, a pre-defined dining table which can be used by any C rule to store whatever Lua price it requires to save. This table is located at pseudo-index LUA_REGISTRYINDEX . Any C library can shop information into this desk, but it should take the time to pick keys unlike those employed by different libraries, to avoid crashes. Generally, you need to use as essential a string that contain the collection title or a light userdata aided by the target of a-c item inside laws.

The integer techniques for the registry are utilized from the reference mechanism, applied by auxiliary library, and as a consequence shouldn’t be used in other reasons.

3.6 Error Management in C

Internally, Lua utilizes the C longjmp premises to deal with problems. (It is possible to decide on exceptions by using C++; see document luaconf.h .) Whenever Lua faces any error (particularly mind allocation mistakes, type problems, syntax problems, and runtime mistakes) it increases a mistake; which, it does a lengthy jump. A protected surroundings utilizes setjmp to set a recover point; any error jumps on most recent effective recuperate point.

Most functions in the API can throw one, such as because a memory allocation mistake. The records for each work suggests whether it can place errors.

3.7 Performance and Type

Here we identify all functionality and sort from C API in alphabetical order. Each function keeps indicative in this way: [-o, +p, x]

Initial industry, o , is actually what amount of elements the event pops through the heap. The next area, p , is actually what amount of items the big event pushes on the pile. (Any features usually forces their outcome after popping its arguments.) A field for the kind x|y implies the event can force (or pop) x or y areas, with regards to the circumstances; an interrogation mark ‘ ? ‘ ensures that we cannot understand how numerous areas the function pops/pushes by appearing merely at the arguments (e.g., they might depend on proceed the link what exactly is on pile). The third area, x , tells if the features may put mistakes: ‘ – ‘ indicates the function never throws any error; ‘ m ‘ ways the event may put an error best due to not enough memory space; ‘ age ‘ means the function may throw other kinds of errors; ‘ v ‘ means the big event may throw a mistake on purpose.

lua_Alloc

The type of the memory-allocation features used by Lua states. The allocator purpose must definitely provide a functionality similar to realloc , however identical. The arguments include ud , an opaque pointer passed to lua_newstate ; ptr , a pointer for the block being allocated/reallocated/freed; osize , the first measurements of the block; nsize , the fresh size of the block. ptr are NULL if and only if osize is actually zero. When nsize try zero, the allocator must return NULL ; if osize just isn’t zero, it should complimentary the block directed to by ptr . When nsize just isn’t zero, the allocator returns NULL if and just in the event it cannot fill the request. Whenever nsize isn’t zero and osize was zero, the allocator should react love malloc . When nsize and osize are not zero, the allocator acts like realloc . Lua assumes your allocator never ever fails when osize >= nsize .