When a-c work is called, their upvalues are found at certain pseudo-indices

When a-c work is called, their upvalues are found at certain pseudo-indices

3.4 C Closures

When a-c function is made, you are able to relate some prices with-it, therefore generating a C closing; these standards have been called upvalues and so are handy for the function each time it really is called (read lua_pushcclosure ).

These pseudo-indices are manufactured of the macro lua_upvalueindex . Initial worth connected with a function is at place lua_upvalueindex(1) , and so on. Any access to lua_upvalueindex(n) , where n is actually greater than the quantity of upvalues in the present purpose (however greater than 256), generates a satisfactory (but incorrect) index.

3.5 Registry

Lua supplies a registry, a pre-defined table which you can use by any C code to save whatever Lua worth it needs to shop. This desk is always located at pseudo-index LUA_REGISTRYINDEX . Any C collection can store data into this dining table, however it should take time to pick tips not the same as those used by different libraries, in order to avoid crashes. Usually, you should utilize as essential a string that contain the collection term or a light userdata aided by the target of a-c item inside signal.

The integer tips when you look at the registry are used by research device, applied of the reliable library, and so shouldn’t be employed for other reasons.

3.6 Error Handling in C

Internally, Lua makes use of the C longjmp center to handle mistakes. (you may also opt for conditions when you use C++; read document luaconf.h .) When Lua deals with any error (instance memory allocation problems, type mistakes, syntax errors, and runtime mistakes) it raises a mistake; that is, it will a long hop. A protected planet utilizes setjmp to set a recover point; any mistake jumps to your newest effective recuperate aim.

Most features from inside the API can throw a mistake, by way of example due to a mind allotment error. The documentation per work shows whether or not it can place problems.

3.7 Performance and Types

Right here we identify all functions and types from C API in alphabetical order. Each work enjoys an indication like this: [-o, +p, x]

1st industry, o , are just how many elements the big event pops through the heap. Another area, p , are the number of factors the big event forces on the pile. (Any features usually forces the outcome after swallowing the arguments.) A field from inside the type x|y means the function can push (or pop music) x or y characteristics, according to circumstances; an interrogation tag ‘ ? ‘ means that we can not discover how most areas the event pops/pushes by looking only at the arguments (e.g., they might rely on what exactly is on the pile). The third area, x , says to whether the features may put problems: ‘ – ‘ implies the big event never ever throws any mistake; ‘ m ‘ means the event may throw one just because insufficient memories; ‘ age ‘ means the event may put other types of mistakes; ‘ v ‘ suggests the event may place an error purposely.

lua_Alloc

The kind of the memory-allocation function employed by Lua reports. The allocator features must provide a functionality comparable to realloc , not the identical. Its arguments were ud , an opaque tip passed to lua_newstate ; ptr , a pointer to your block getting allocated/reallocated/freed; osize , the first sized the block; nsize , new size of the block. ptr are NULL if and simply if osize are zero. When nsize try zero, the allocator must return NULL ; if osize isn’t zero, it ought to free the block pointed to by ptr . Whenever nsize isn’t zero, the allocator comes back NULL if and just when it polish hearts PЕ™ihlГЎЕЎenГ­ cannot fill the consult. When nsize just isn’t zero and osize is actually zero, the allocator should respond love malloc . Whenever nsize and osize are not zero, the allocator acts like realloc . Lua assumes the allocator never fails whenever osize >= nsize .

Deixe um comentário