aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of72
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,
2436you are responsible for ensuring consistency. 2436you are responsible for ensuring consistency.
2437In particular, 2437In particular,
2438@emph{you are responsible for controlling stack overflow}. 2438@emph{you are responsible for controlling stack overflow}.
2439You can use the function @Lid{lua_checkstack} 2439When you call any API function,
2440to ensure that the stack has enough space for pushing new elements. 2440you must ensure the stack has enough room to accommodate the results.
2441
2442There is one exception to the above rule:
2443When you call a Lua function
2444without a fixed number of results @seeF{lua_call},
2445Lua ensures that the stack has enough space for all results.
2446However, it does not ensure any extra space.
2447So, before pushing anything on the stack after such a call
2448you should use @Lid{lua_checkstack}.
2441 2449
2442Whenever Lua calls C, 2450Whenever Lua calls C,
2443it ensures that the stack has space for 2451it 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,
2447so that usually you do not have to worry about stack space 2455so that usually you do not have to worry about stack space
2448unless your code has loops pushing elements onto the stack. 2456unless your code has loops pushing elements onto the stack.
2449 2457Whenever necessary,
2450When you call a Lua function 2458you can use the function @Lid{lua_checkstack}
2451without a fixed number of results @seeF{lua_call}, 2459to ensure that the stack has enough space for pushing new elements.
2452Lua ensures that the stack has enough space for all results,
2453but it does not ensure any extra space.
2454So, before pushing anything on the stack after such a call
2455you 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
2695and this API function yields 2699and this API function yields
2696(directly or indirectly by calling another function that yields), 2700(directly or indirectly by calling another function that yields),
2697Lua cannot return to @id{foo} any more, 2701Lua cannot return to @id{foo} any more,
2698because the @id{longjmp} removes its frame from the C stack. 2702because the @id{longjmp} removes its frame from the @N{C stack}.
2699 2703
2700To avoid this kind of problem, 2704To avoid this kind of problem,
2701Lua raises an error whenever it tries to yield across an API call, 2705Lua raises an error whenever it tries to yield across an API call,
@@ -2719,7 +2723,7 @@ After the thread resumes,
2719it eventually will finish running the callee function. 2723it eventually will finish running the callee function.
2720However, 2724However,
2721the callee function cannot return to the original function, 2725the callee function cannot return to the original function,
2722because its frame in the C stack was destroyed by the yield. 2726because its frame in the @N{C stack} was destroyed by the yield.
2723Instead, Lua calls a @def{continuation function}, 2727Instead, Lua calls a @def{continuation function},
2724which was given as an argument to the callee function. 2728which was given as an argument to the callee function.
2725As the name implies, 2729As the name implies,
@@ -2841,7 +2845,7 @@ and therefore may raise any errors.
2841 2845
2842Converts the @x{acceptable index} @id{idx} 2846Converts the @x{acceptable index} @id{idx}
2843into an equivalent @x{absolute index} 2847into 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.
4340Note that, both in case of errors and of a regular return, 4344Note that, both in case of errors and of a regular return,
4341by the time the @idx{__close} metamethod runs, 4345by the time the @idx{__close} metamethod runs,
4342the @N{C stack} was already unwound, 4346the @N{C stack} was already unwound,
4343so that any automatic C variable declared in the calling function 4347so that any automatic @N{C variable} declared in the calling function
4344will be out of scope. 4348will 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
4961Sets a new limit for the C stack.
4962This limit controls how deeply nested calls can go in Lua,
4963with the intent of avoiding a stack overflow.
4964Returns the old limit in case of success,
4965or zero in case of error.
4966For more details about this function,
4967see @Lid{debug.setcstacklimit},
4968its 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
8761Sets a new limit for the C stack.
8762This limit controls how deeply nested calls can go in Lua,
8763with the intent of avoiding a stack overflow.
8764A limit too small restricts recursive calls pointlessly;
8765a limit too large exposes the interpreter to stack-overflow crashes.
8766Unfortunately, there is no way to know a priori
8767the maximum safe limit for a platform.
8768
8769Each call made from Lua code counts one unit.
8770Other operations (e.g., calls made from C to Lua or resuming a coroutine)
8771may have a higher cost.
8772
8773This 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}
8780If a call does not respect some restriction,
8781it returns a false value.
8782Otherwise,
8783the 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
8789Sets the given function as the debug hook. 8751Sets the given function as the debug hook.