Each time a-c features is called, their upvalues can be found at certain pseudo-indices

Each time a-c features is called, their upvalues can be found at certain pseudo-indices

3.4 C Closures

Whenever a-c features is generated, you can connect some standards with-it, thus creating a-c closure; these prices have been called upvalues and so are handy for the function whenever it really is also known as (read lua_pushcclosure ).

These pseudo-indices are produced by the macro lua_upvalueindex . The initial benefits related to a function is at situation lua_upvalueindex(1) , etc. Any access to lua_upvalueindex(n) , in which letter are higher than the sheer number of upvalues for the recent purpose (yet not greater than 256), create a reasonable (but incorrect) directory.

3.5 Registry

Lua provides a registry, a pre-defined table that can be used by any C rule to save whatever Lua appreciate it needs to put. This desk is always located at pseudo-index LUA_REGISTRYINDEX . Any C library can keep data into this dining table, however it should take care to choose tactics distinct from those used by different libraries, in order to avoid collisions. Usually, you need to use as key a string that contain their collection name or a light userdata because of the target of a-c object in your code.

The integer points during the registry are utilized from the resource process, implemented from the additional collection, and as a consequence should not be used for various other reasons.

3.6 Error Management in C

Internally, Lua utilizes the C longjmp center to handle mistakes. (you can even opt for conditions by using C++; read document luaconf.h .) When Lua faces any mistake (particularly memory space https://datingmentor.org/portuguese-dating/ allocation errors, type errors, syntax errors, and runtime mistakes) it increases one; which, it can an extended hop. A protected environment utilizes setjmp to set a recover aim; any mistake jumps towards newest energetic recover aim.

The majority of performance in API can toss an error, for instance because a memory space allowance error. The paperwork for every single purpose indicates whether or not it can place mistakes.

3.7 Applications and Sort

Right here we list all features and kinds through the C API in alphabetical order. Each function features an indicator like this: [-o, +p, x]

1st industry, o , are exactly how many items the event pops through the heap. The next industry, p , is actually how many characteristics the function pushes on the pile. (Any function constantly pushes the results after popping the arguments.) A field within the type x|y suggests the event can push (or pop) x or y characteristics, according to the scenario; an interrogation tag ‘ ? ‘ ensures that we simply cannot learn how lots of details the big event pops/pushes by searching merely at the arguments (elizabeth.g., they may be determined by what’s in the bunch). The next area, x , says to if the function may put errors: ‘ – ‘ implies the function never ever tosses any mistake; ‘ m ‘ suggests the function may throw a mistake just as a result of lack of mind; ‘ age ‘ ways the event may put other kinds of mistakes; ‘ v ‘ implies the function may toss a mistake purposely.


The sort of the memory-allocation purpose utilized by Lua says. The allocator purpose must provide a functionality much like realloc , although not the same. Its arguments tend to be ud , an opaque tip passed to lua_newstate ; ptr , a pointer to the block are allocated/reallocated/freed; osize , the initial measurements of the block; nsize , this new measurements of the block. ptr try NULL if and only if osize was zero. When nsize is actually zero, the allocator must get back NULL ; if osize isn’t zero, it ought to free the block directed to by ptr . Whenever nsize is not zero, the allocator return NULL if and just when it cannot fill the demand. When nsize is certainly not zero and osize are zero, the allocator should act similar malloc . When nsize and osize are not zero, the allocator acts like realloc . Lua assumes the allocator never ever fails when osize >= nsize .

Leave a Reply

Your email address will not be published. Required fields are marked *