Any arguments passed away to the work run as further arguments to coroutine

Any arguments passed away to the work run as further arguments to coroutine

Like coroutine.create , the coroutine.wrap function in addition brings a coroutine, but instead of going back the coroutine alone, they return a function that, whenever called, resumes the coroutine. application . coroutine.wrap profits most of the prices came back by coroutine.resume , except the very first one (the boolean mistake signal). Unlike coroutine.resume , coroutine.wrap doesn’t capture problems; any mistake is propagated toward person.

This part describes the C API for Lua, this is certainly, the set of C applications open to the host program to speak with Lua. All API features and relevant types and constants were stated in header document lua.h .

Even when we make use of the phase “function”, any center during the API is likely to be given as a macro instead. All this type of macros make use of every one of their arguments just when (aside from one discussion, that’s always a Lua condition), and therefore try not to produce any undetectable side effects.

Like in most C libraries, the Lua API features try not to check their arguments for validity or reliability. But possible change this behavior by producing Lua with a proper description for all the macro luai_apicheck , in document luaconf.h .

3.1 The Pile

Lua uses an online stack to pass through beliefs back and forth C. Each factor in this stack shows a Lua value (nil, quantity, sequence, etc.).

Whenever Lua calls C, the called features becomes another pile, which can be separate of past piles and of stacks of C functionality which can be nonetheless productive. This pile at first includes any arguments to your C purpose and it is where the C purpose forces the leads to feel gone back to the caller (read lua_CFunction ).

For benefits, the majority of question procedures in the API you should never heed a tight pile discipline. Rather, capable refer to any factor in the stack using a list: A positive list presents a total heap place (beginning at 1); a negative directory symbolizes an offset relative to the top the bunch. A lot more especially, in the event the heap enjoys n aspects, next directory 1 presents initial aspect (this is certainly, the component that was forced onto the bunch very first) and index n represents the final element; list -1 additionally represents the last aspect (that will be, the element at the top) and list -n shows the initial aspect. We point out that an index try appropriate when it lies between 1 additionally the heap leading (this is certainly, if 1 a‰¤ abs(index) a‰¤ very top ).

3.2 Bunch Size

When you communicate with Lua API, you may be in charge of guaranteeing consistency. Specifically, you will be in charge of regulating heap overflow. You need the function lua_checkstack to develop the bunch proportions.

Whenever Lua phone calls C, they ensures that about LUA_MINSTACK bunch positions are available. LUA_MINSTACK means 20, so frequently you don’t have to bother with pile space unless your own rule enjoys loops moving areas onto the heap.

Most query applications accept as indicator any worth inside the readily available stack space, that is, indicator around the maximum stack dimensions you really have put through lua_checkstack . These indicator are called appropriate indices. Much more officially, we define a satisfactory index as follows:

3.3 Pseudo-Indices

Unless usually mentioned, Pueblo escort any purpose that takes appropriate indices may also be known as with pseudo-indices, which signify some Lua values being accessible to C laws but which are not from inside the stack. Pseudo-indices are widely used to access the bond environment, the function environment, the registry, therefore the upvalues of a-c function (discover A§3.4).

The thread ecosystem (where global factors living) is obviously at pseudo-index LUA_GLOBALSINDEX . The environmental surroundings regarding the operating C work is at pseudo-index LUA_ENVIRONINDEX .