Any arguments passed away to this features run as added arguments to coroutine

Any arguments passed away to this features run as added arguments to coroutine

Like coroutine.create , the coroutine.wrap features in addition brings a coroutine, but rather of returning the coroutine itself, it return a function that, whenever called, resumes the coroutine. application . coroutine.wrap returns every prices returned by coroutine.resume , except the very first one (the boolean mistake rule). Unlike coroutine.resume , coroutine.wrap will not catch errors; any error is propagated with the caller.

This section describes the C API for Lua, which, the collection of C applications accessible to the number plan to speak with Lua. All API performance and related sort and constants is stated when you look at the header document lua.h .

Even though we use the phase „function“, any establishment from inside the API is supplied as a macro instead. All such macros need all of their particular arguments precisely when (aside from one argument, which can be always a Lua state), and therefore try not to generate any hidden side-effects.

Like in most C libraries, the Lua API applications try not to search their particular arguments for credibility or persistence. However, you’ll be able to change this behavior by putting together Lua with a proper description your macro luai_apicheck , in file luaconf.h .

3.1 The Bunch

Lua makes use of a virtual stack to pass prices back and forth from C. Each aspect in this stack represents a Lua worth (nil, wide variety, sequence, etc.).

Whenever Lua calls C, the also known as purpose will get a fresh heap, which can be independent of past stacks as well as stacks of C functions which are nonetheless productive. This stack at first has any arguments into C features and is where in actuality the C purpose forces their leads to become gone back to the caller (see lua_CFunction ).

For benefits, many query operations inside API never follow a strict stack control. Rather, they can make reference to any aspect in the bunch by making use of a directory: a confident directory represents an outright heap position (starting at 1); a bad index represents an offset relative to the top the stack. Considerably especially, in the event the stack has n items, next index 1 signifies the first aspect (which, the element which was pressed onto the heap first) and directory n symbolizes the final aspect; index -1 also represents the final element (that’s, the component at the top) and index -n signifies initial element. We point out that an index are valid whether it consist between 1 and bunch leading (that will be, if 1 a‰¤ abs(index) a‰¤ top ).

3.2 Pile Size

Whenever you connect to Lua API, you will be in charge of making sure consistency. In particular, you might be in charge of controlling bunch overflow. You should use the big event lua_checkstack growing the bunch proportions.

Whenever Lua calls C, they makes sure that at least LUA_MINSTACK stack opportunities can be found. LUA_MINSTACK is understood to be 20, making sure that often there is no need to consider heap space unless your own code possess loops moving aspects onto the pile.

The majority of query performance recognize as indices any advantages inside offered stack area, that will be, indicator to the most bunch dimensions you may have set through lua_checkstack . These types of indices are known as appropriate indices. Considerably officially, we define an appropriate directory as follows:

3.3 Pseudo-Indices

Unless or else noted, any work that allows appropriate indices can be also known as with pseudo-indices, which represent some Lua values which happen to be handy for C laws but that are not inside bunch. Pseudo-indices are widely used to access the bond planet, the event ecosystem, the registry, as well as the upvalues of a-c work (see A§3.4).

The thread planet (where global factors stay) is at pseudo-index LUA_GLOBALSINDEX . The environment associated with the working C purpose is always at pseudo-index LUA_ENVIRONINDEX .