Each time a C work is named, the upvalues can be found at particular pseudo-indices

Each time a C work is named, the upvalues can be found at particular pseudo-indices

3.4 C Closures

When a-c function is created, it is possible to relate some prices along with it, thus creating a-c closure; these principles have been called upvalues and are generally accessible to the big event whenever its also known as (discover lua_pushcclosure ).

These pseudo-indices are produced by the macro lua_upvalueindex . The initial advantages related to a function is located at position lua_upvalueindex(1) , etc. Any the means to access lua_upvalueindex(letter) , where n was more than the quantity of upvalues of this current purpose (although not higher than 256), creates an acceptable (but invalid) directory.

3.5 Registry

Lua provides a registry, a pre-defined table which can be used by any C signal to store whatever Lua value it must store. This desk is located at pseudo-index LUA_REGISTRYINDEX . Any C collection can keep data into this desk, nonetheless it should make sure to determine secrets not the same as those utilized by other libraries, in order to prevent collisions. Generally, you should utilize as crucial a string that contain your own library name or lighting userdata making use of the target of a-c object within rule.

The integer points into the registry are utilized because of the guide mechanism, implemented of the reliable collection, therefore really should not be useful for various other needs.

3.6 Error Managing in C

Internally, Lua uses the C longjmp center to control mistakes. (You can also opt for exclusions by using C++; discover document luaconf.h .) When Lua face any mistake (such memory allocation mistakes, type problems, syntax errors, and runtime mistakes) it raises an error; that’s, it can a lengthy hop. A protected atmosphere utilizes setjmp to put a recover point; any mistake jumps with the most recent productive recuperate aim.

Most features inside the API can toss a mistake, as an example because a storage allocation error. The documents each features suggests whether it can toss mistakes.

3.7 Features and Types

Here we identify all applications and type through the C API in alphabetical purchase. Each work keeps an indication in this way: [-o, +p, x]

The first field, o , is actually the number of factors the function pops from the pile. The 2nd field, p , are just how many characteristics the event forces on the pile. (Any features always pushes the outcomes after swallowing their arguments.) A pregnant dating site field during the form x|y indicates the function can press (or pop music) x or y areas, with regards to the situation; an interrogation tag ‘ ? ‘ ensures that we can not learn how lots of items the big event pops/pushes by lookin only at the arguments (e.g., they might rely on something in the pile). The next industry, x , says to whether or not the function may place problems: ‘ – ‘ suggests the event never ever throws any mistake; ‘ m ‘ means the big event may toss a mistake only because not enough memory; ‘ age ‘ means the big event may put other forms of errors; ‘ v ‘ suggests the function may put an error deliberately.

lua_Alloc

The type of the memory-allocation function employed by Lua reports. The allocator purpose must make provision for a functionality comparable to realloc , not identical. Their arguments tend to be ud , an opaque pointer passed away to lua_newstate ; ptr , a pointer on the block are allocated/reallocated/freed; osize , the first size of the block; nsize , the newest measurements of the block. ptr try NULL if and simply if osize are zero. When nsize are zero, the allocator must come back NULL ; if osize is certainly not zero, it ought to complimentary the block indicated to by ptr . When nsize just isn’t zero, the allocator returns NULL if and just in the event it cannot fill the demand. When nsize is not zero and osize try zero, the allocator should respond like malloc . Whenever nsize and osize are not zero, the allocator acts like realloc . Lua assumes that the allocator never ever fails when osize >= nsize .

پیام بگذارید

در خبرنامه سایت ما عضو شوید

برای دریافت آخرین اخبار ، به روزرسانی ها ، تبلیغات و پیشنهادات ویژه ای که مستقیماً به صندوق ورودی شما تحویل داده می شود ثبت نام کنید.
خیر، متشکر
X