diff options
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 72 |
1 files changed, 17 insertions, 55 deletions
diff --git a/manual/manual.of b/manual/manual.of index 8b34b5bd..86631bbc 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -2436,8 +2436,16 @@ When you interact with the Lua API, | |||
2436 | you are responsible for ensuring consistency. | 2436 | you are responsible for ensuring consistency. |
2437 | In particular, | 2437 | In particular, |
2438 | @emph{you are responsible for controlling stack overflow}. | 2438 | @emph{you are responsible for controlling stack overflow}. |
2439 | You can use the function @Lid{lua_checkstack} | 2439 | When you call any API function, |
2440 | to ensure that the stack has enough space for pushing new elements. | 2440 | you must ensure the stack has enough room to accommodate the results. |
2441 | |||
2442 | There is one exception to the above rule: | ||
2443 | When you call a Lua function | ||
2444 | without a fixed number of results @seeF{lua_call}, | ||
2445 | Lua ensures that the stack has enough space for all results. | ||
2446 | However, it does not ensure any extra space. | ||
2447 | So, before pushing anything on the stack after such a call | ||
2448 | you should use @Lid{lua_checkstack}. | ||
2441 | 2449 | ||
2442 | Whenever Lua calls C, | 2450 | Whenever Lua calls C, |
2443 | it ensures that the stack has space for | 2451 | it ensures that the stack has space for |
@@ -2446,13 +2454,9 @@ that is, you can safely push up to @id{LUA_MINSTACK} values into it. | |||
2446 | @id{LUA_MINSTACK} is defined as 20, | 2454 | @id{LUA_MINSTACK} is defined as 20, |
2447 | so that usually you do not have to worry about stack space | 2455 | so that usually you do not have to worry about stack space |
2448 | unless your code has loops pushing elements onto the stack. | 2456 | unless your code has loops pushing elements onto the stack. |
2449 | 2457 | Whenever necessary, | |
2450 | When you call a Lua function | 2458 | you can use the function @Lid{lua_checkstack} |
2451 | without a fixed number of results @seeF{lua_call}, | 2459 | to ensure that the stack has enough space for pushing new elements. |
2452 | Lua ensures that the stack has enough space for all results, | ||
2453 | but it does not ensure any extra space. | ||
2454 | So, before pushing anything on the stack after such a call | ||
2455 | you should use @Lid{lua_checkstack}. | ||
2456 | 2460 | ||
2457 | } | 2461 | } |
2458 | 2462 | ||
@@ -2695,7 +2699,7 @@ Therefore, if a @N{C function} @id{foo} calls an API function | |||
2695 | and this API function yields | 2699 | and this API function yields |
2696 | (directly or indirectly by calling another function that yields), | 2700 | (directly or indirectly by calling another function that yields), |
2697 | Lua cannot return to @id{foo} any more, | 2701 | Lua cannot return to @id{foo} any more, |
2698 | because the @id{longjmp} removes its frame from the C stack. | 2702 | because the @id{longjmp} removes its frame from the @N{C stack}. |
2699 | 2703 | ||
2700 | To avoid this kind of problem, | 2704 | To avoid this kind of problem, |
2701 | Lua raises an error whenever it tries to yield across an API call, | 2705 | Lua raises an error whenever it tries to yield across an API call, |
@@ -2719,7 +2723,7 @@ After the thread resumes, | |||
2719 | it eventually will finish running the callee function. | 2723 | it eventually will finish running the callee function. |
2720 | However, | 2724 | However, |
2721 | the callee function cannot return to the original function, | 2725 | the callee function cannot return to the original function, |
2722 | because its frame in the C stack was destroyed by the yield. | 2726 | because its frame in the @N{C stack} was destroyed by the yield. |
2723 | Instead, Lua calls a @def{continuation function}, | 2727 | Instead, Lua calls a @def{continuation function}, |
2724 | which was given as an argument to the callee function. | 2728 | which was given as an argument to the callee function. |
2725 | As the name implies, | 2729 | As the name implies, |
@@ -2841,7 +2845,7 @@ and therefore may raise any errors. | |||
2841 | 2845 | ||
2842 | Converts the @x{acceptable index} @id{idx} | 2846 | Converts the @x{acceptable index} @id{idx} |
2843 | into an equivalent @x{absolute index} | 2847 | into an equivalent @x{absolute index} |
2844 | (that is, one that does not depend on the stack top). | 2848 | (that is, one that does not depend on the stack size). |
2845 | 2849 | ||
2846 | } | 2850 | } |
2847 | 2851 | ||
@@ -4340,7 +4344,7 @@ as if it was already marked. | |||
4340 | Note that, both in case of errors and of a regular return, | 4344 | Note that, both in case of errors and of a regular return, |
4341 | by the time the @idx{__close} metamethod runs, | 4345 | by the time the @idx{__close} metamethod runs, |
4342 | the @N{C stack} was already unwound, | 4346 | the @N{C stack} was already unwound, |
4343 | so that any automatic C variable declared in the calling function | 4347 | so that any automatic @N{C variable} declared in the calling function |
4344 | will be out of scope. | 4348 | will be out of scope. |
4345 | 4349 | ||
4346 | } | 4350 | } |
@@ -4955,20 +4959,6 @@ calling @Lid{lua_yield} with @id{nresults} equal to zero | |||
4955 | 4959 | ||
4956 | } | 4960 | } |
4957 | 4961 | ||
4958 | @APIEntry{int (lua_setcstacklimit) (lua_State *L, unsigned int limit);| | ||
4959 | @apii{0,0,-} | ||
4960 | |||
4961 | Sets a new limit for the C stack. | ||
4962 | This limit controls how deeply nested calls can go in Lua, | ||
4963 | with the intent of avoiding a stack overflow. | ||
4964 | Returns the old limit in case of success, | ||
4965 | or zero in case of error. | ||
4966 | For more details about this function, | ||
4967 | see @Lid{debug.setcstacklimit}, | ||
4968 | its equivalent in the standard library. | ||
4969 | |||
4970 | } | ||
4971 | |||
4972 | @APIEntry{void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);| | 4962 | @APIEntry{void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);| |
4973 | @apii{0,0,-} | 4963 | @apii{0,0,-} |
4974 | 4964 | ||
@@ -8756,34 +8746,6 @@ to the userdata @id{u} plus a boolean, | |||
8756 | 8746 | ||
8757 | } | 8747 | } |
8758 | 8748 | ||
8759 | @LibEntry{debug.setcstacklimit (limit)| | ||
8760 | |||
8761 | Sets a new limit for the C stack. | ||
8762 | This limit controls how deeply nested calls can go in Lua, | ||
8763 | with the intent of avoiding a stack overflow. | ||
8764 | A limit too small restricts recursive calls pointlessly; | ||
8765 | a limit too large exposes the interpreter to stack-overflow crashes. | ||
8766 | Unfortunately, there is no way to know a priori | ||
8767 | the maximum safe limit for a platform. | ||
8768 | |||
8769 | Each call made from Lua code counts one unit. | ||
8770 | Other operations (e.g., calls made from C to Lua or resuming a coroutine) | ||
8771 | may have a higher cost. | ||
8772 | |||
8773 | This function has the following restrictions: | ||
8774 | @description{ | ||
8775 | @item{It can only be called from the main coroutine (thread);} | ||
8776 | @item{It cannot be called while handling a stack-overflow error;} | ||
8777 | @item{@id{limit} must be less than 40000;} | ||
8778 | @item{@id{limit} cannot be less than the amount of C stack in use.} | ||
8779 | } | ||
8780 | If a call does not respect some restriction, | ||
8781 | it returns a false value. | ||
8782 | Otherwise, | ||
8783 | the call returns the old limit. | ||
8784 | |||
8785 | } | ||
8786 | |||
8787 | @LibEntry{debug.sethook ([thread,] hook, mask [, count])| | 8749 | @LibEntry{debug.sethook ([thread,] hook, mask [, count])| |
8788 | 8750 | ||
8789 | Sets the given function as the debug hook. | 8751 | Sets the given function as the debug hook. |