diff options
Diffstat (limited to '')
| -rw-r--r-- | manual.tex | 207 |
1 files changed, 138 insertions, 69 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | % $Id: manual.tex,v 1.20 1998/11/13 16:48:48 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.21 1998/11/20 15:41:43 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | \documentclass[11pt]{article} | 3 | \documentclass[11pt]{article} |
| 4 | \usepackage{fullpage,bnf} | 4 | \usepackage{fullpage,bnf} |
| @@ -41,7 +41,7 @@ Waldemar Celes | |||
| 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | %\date{\small \verb$Date: 1998/11/13 16:48:48 $} | 44 | %\date{\small \verb$Date: 1998/11/20 15:41:43 $} |
| 45 | 45 | ||
| 46 | \maketitle | 46 | \maketitle |
| 47 | 47 | ||
| @@ -410,11 +410,7 @@ Lua provides some automatic conversions between values at run time. | |||
| 410 | Any arithmetic operation applied to a string tries to convert | 410 | Any arithmetic operation applied to a string tries to convert |
| 411 | that string to a number, following the usual rules. | 411 | that string to a number, following the usual rules. |
| 412 | Conversely, whenever a number is used when a string is expected, | 412 | Conversely, whenever a number is used when a string is expected, |
| 413 | that number is converted to a string, according to the following rule: | 413 | that number is converted to a string, in a reasonable format. |
| 414 | if the number is an integer, it is written without exponent or decimal point; | ||
| 415 | otherwise, it is formatted following the \verb|%g| | ||
| 416 | conversion specification of the \verb|printf| function in the | ||
| 417 | standard C library. | ||
| 418 | For complete control on how numbers are converted to strings, | 414 | For complete control on how numbers are converted to strings, |
| 419 | use the \verb|format| function \see{format}. | 415 | use the \verb|format| function \see{format}. |
| 420 | 416 | ||
| @@ -523,9 +519,9 @@ only \nil\ is considered false. | |||
| 523 | \begin{Produc} | 519 | \begin{Produc} |
| 524 | \produc{stat}{\rwd{while} exp1 \rwd{do} block \rwd{end} \OrNL | 520 | \produc{stat}{\rwd{while} exp1 \rwd{do} block \rwd{end} \OrNL |
| 525 | \rwd{repeat} block \rwd{until} exp1 \OrNL | 521 | \rwd{repeat} block \rwd{until} exp1 \OrNL |
| 526 | \rwd{if} exp1 \rwd{then} block \rep{elseif} | 522 | \rwd{if} exp1 \rwd{then} block |
| 523 | \rep{\rwd{elseif} exp1 \rwd{then} block} | ||
| 527 | \opt{\rwd{else} block} \rwd{end}} | 524 | \opt{\rwd{else} block} \rwd{end}} |
| 528 | \produc{elseif}{\rwd{elseif} exp1 \rwd{then} block} | ||
| 529 | \end{Produc} | 525 | \end{Produc} |
| 530 | 526 | ||
| 531 | A \T{return} is used to return values from a function or from a chunk. | 527 | A \T{return} is used to return values from a function or from a chunk. |
| @@ -688,6 +684,24 @@ All binary operators are left associative, | |||
| 688 | except for \verb|^| (exponentiation), | 684 | except for \verb|^| (exponentiation), |
| 689 | which is right associative. | 685 | which is right associative. |
| 690 | 686 | ||
| 687 | \subsubsection{If Expressions} | ||
| 688 | \begin{Produc} | ||
| 689 | \produc{exp}{\rwd{if} exp1 \rwd{then} exp1 | ||
| 690 | \rep{\rwd{elseif} exp1 \rwd{then} exp1} | ||
| 691 | \opt{\rwd{else} exp1} \rwd{end}} | ||
| 692 | \end{Produc}% | ||
| 693 | An \Index{if expression} chooses an expression to evaluate | ||
| 694 | according to its condition. | ||
| 695 | Its final value is the value of the chosen expression. | ||
| 696 | An absent else-part is equivalent to \verb|else nil|. | ||
| 697 | |||
| 698 | \subsubsection{Assignment Expressions} | ||
| 699 | \begin{Produc} | ||
| 700 | \produc{exp}{\ter{(} var \ter{=} exp1 \ter{)}} | ||
| 701 | \end{Produc}% | ||
| 702 | An \Index{assignment expression} executes a regular assignment, | ||
| 703 | and results in the final value of its right hand expression. | ||
| 704 | |||
| 691 | \subsubsection{Table Constructors} \label{tableconstructor} | 705 | \subsubsection{Table Constructors} \label{tableconstructor} |
| 692 | Table \Index{constructors} are expressions that create tables; | 706 | Table \Index{constructors} are expressions that create tables; |
| 693 | every time a constructor is evaluated, a new table is created. | 707 | every time a constructor is evaluated, a new table is created. |
| @@ -1978,8 +1992,9 @@ field not present in a table or a field with value \nil. | |||
| 1978 | Therefore, the function only considers fields with non \nil\ values. | 1992 | Therefore, the function only considers fields with non \nil\ values. |
| 1979 | The order in which the indices are enumerated is not specified, | 1993 | The order in which the indices are enumerated is not specified, |
| 1980 | \emph{even for numeric indices} | 1994 | \emph{even for numeric indices} |
| 1981 | (to traverse a table in numeric order, use a counter). | 1995 | (to traverse a table in numeric order, |
| 1982 | If the table is modified in any way during a traversal, | 1996 | use a counter or function \verb|foreachi|). |
| 1997 | If the table indices are modified in any way during a traversal, | ||
| 1983 | the semantics of \verb|next| is undefined. | 1998 | the semantics of \verb|next| is undefined. |
| 1984 | 1999 | ||
| 1985 | This function cannot be written with the standard API. | 2000 | This function cannot be written with the standard API. |
| @@ -1992,7 +2007,7 @@ or \nil\ to get a first name. | |||
| 1992 | Similarly to \verb|next|, it returns the name of another variable | 2007 | Similarly to \verb|next|, it returns the name of another variable |
| 1993 | and its value, | 2008 | and its value, |
| 1994 | or \nil\ if there are no more variables. | 2009 | or \nil\ if there are no more variables. |
| 1995 | There can be no assignments to global variables during the traversal; | 2010 | There can be no creation of new global variables during the traversal; |
| 1996 | otherwise the semantics of \verb|nextvar| is undefined. | 2011 | otherwise the semantics of \verb|nextvar| is undefined. |
| 1997 | 2012 | ||
| 1998 | This function cannot be written with the standard API. | 2013 | This function cannot be written with the standard API. |
| @@ -2150,14 +2165,13 @@ value in the table. | |||
| 2150 | This function could be defined in Lua: | 2165 | This function could be defined in Lua: |
| 2151 | \begin{verbatim} | 2166 | \begin{verbatim} |
| 2152 | function getn (t) | 2167 | function getn (t) |
| 2153 | if type(t.n) == 'number' then return floor(t.n) end | 2168 | if type(t.n) == 'number' then return t.n end |
| 2154 | local i = next(t, nil) | 2169 | local i = nil |
| 2155 | local max = 0 | 2170 | local max = 0 |
| 2156 | while i do | 2171 | while (i=next(t, i)) do |
| 2157 | if type(i) == 'number' and i>max then max=i end | 2172 | if type(i) == 'number' and i>max then max=i end |
| 2158 | i = next(t, i) | ||
| 2159 | end | 2173 | end |
| 2160 | return floor(max) | 2174 | return max |
| 2161 | end | 2175 | end |
| 2162 | \end{verbatim} | 2176 | \end{verbatim} |
| 2163 | 2177 | ||
| @@ -2198,11 +2212,10 @@ as the final value of \verb|foreachi|. | |||
| 2198 | This function could be defined in Lua: | 2212 | This function could be defined in Lua: |
| 2199 | \begin{verbatim} | 2213 | \begin{verbatim} |
| 2200 | function foreachi (t, f) | 2214 | function foreachi (t, f) |
| 2201 | local i, n = 1, getn(t) | 2215 | local i, n = 0, getn(t) |
| 2202 | while i<=n do | 2216 | while (i=i+1)<=n do |
| 2203 | local res = f(i, t[i]) | 2217 | local res = f(i, t[i]) |
| 2204 | if res then return res end | 2218 | if res then return res end |
| 2205 | i = i+1 | ||
| 2206 | end | 2219 | end |
| 2207 | end | 2220 | end |
| 2208 | \end{verbatim} | 2221 | \end{verbatim} |
| @@ -2227,50 +2240,80 @@ This function could be defined in Lua: | |||
| 2227 | end | 2240 | end |
| 2228 | \end{verbatim} | 2241 | \end{verbatim} |
| 2229 | 2242 | ||
| 2243 | \subsubsection*{\ff \T{tinsert (table [, pos] , value)}}\Deffunc{tinsert} | ||
| 2244 | |||
| 2245 | Inserts element \verb|value| at table position \verb|pos|, | ||
| 2246 | shifting other elements to open space. | ||
| 2247 | The default value for \verb|pos| is \verb|n+1| | ||
| 2248 | (where \verb|n| is the result of \verb|getn(table)| \see{getn}) | ||
| 2249 | so that a call \verb|tinsert(t,x)| inserts \verb|x| at the end | ||
| 2250 | of table \verb|t|. | ||
| 2251 | |||
| 2252 | This function also sets or increments the field \verb|n| of the table, | ||
| 2253 | to \verb|n+1|. | ||
| 2254 | |||
| 2255 | This function is equivalent to the following Lua function, | ||
| 2256 | except that the table accesses are all raw (that is, without tag methods): | ||
| 2257 | \begin{verbatim} | ||
| 2258 | function tinsert (t, ...) | ||
| 2259 | local pos, value | ||
| 2260 | local n = getn(t) | ||
| 2261 | if arg.n == 1 then | ||
| 2262 | pos = n+1; value = arg[1] | ||
| 2263 | else | ||
| 2264 | pos = arg[1]; value = arg[2] | ||
| 2265 | end | ||
| 2266 | t.n = n+1; n=n+1 | ||
| 2267 | while (n=n-1)>=pos do | ||
| 2268 | t[n+1] = t[n] | ||
| 2269 | end | ||
| 2270 | t[pos] = value | ||
| 2271 | end | ||
| 2272 | \end{verbatim} | ||
| 2273 | |||
| 2274 | \subsubsection*{\ff \T{tremove (table [, pos])}}\Deffunc{tremove} | ||
| 2275 | |||
| 2276 | Removes from \verb|table| the element at position \verb|pos|, | ||
| 2277 | shifting other elements to close the space. | ||
| 2278 | Returns the value of the removed element. | ||
| 2279 | The default value for \verb|pos| is \verb|n| | ||
| 2280 | (where \verb|n| is the result of \verb|getn(table)| \see{getn}), | ||
| 2281 | so that a call \verb|tremove(t)| removes the last element | ||
| 2282 | of table \verb|t|. | ||
| 2283 | |||
| 2284 | This function also sets or decrements the field \verb|n| of the table, | ||
| 2285 | to \verb|n-1|. | ||
| 2286 | |||
| 2287 | This function is equivalent to the following Lua function, | ||
| 2288 | except that the table accesses are all raw (that is, without tag methods): | ||
| 2289 | \begin{verbatim} | ||
| 2290 | function tremove (t, pos) | ||
| 2291 | local n = getn(t) | ||
| 2292 | pos = pos or n | ||
| 2293 | local value = t[pos] | ||
| 2294 | if n<=0 then return end | ||
| 2295 | t.n = n-1 | ||
| 2296 | pos = pos-1 | ||
| 2297 | while (pos=pos+1)<n do | ||
| 2298 | t[pos] = t[pos+1] | ||
| 2299 | end | ||
| 2300 | return value | ||
| 2301 | end | ||
| 2302 | \end{verbatim} | ||
| 2303 | |||
| 2230 | \subsubsection*{\ff \T{sort (table [, comp])}}\Deffunc{sort} | 2304 | \subsubsection*{\ff \T{sort (table [, comp])}}\Deffunc{sort} |
| 2231 | Sorts table elements in ascending order, \emph{in-place}, | 2305 | Sorts table elements in a given order, \emph{in-place}, |
| 2232 | from \verb|table[1]| to \verb|table[n]|, | 2306 | from \verb|table[1]| to \verb|table[n]|, |
| 2233 | where \verb|n| is the result of \verb|getn(table)| \see{getn}. | 2307 | where \verb|n| is the result of \verb|getn(table)| \see{getn}. |
| 2234 | If \verb|comp| is given, | 2308 | If \verb|comp| is given, |
| 2235 | it must be a function that compares two table elements, | 2309 | it must be a function that receives two table elements, |
| 2236 | and returns true when the first is less than the second | 2310 | and returns true when the first is less than the second |
| 2237 | (that is, \verb|not comp(a[i+1], a[i])| will be true after the sort). | 2311 | (so that \verb|not comp(a[i+1], a[i])| will be true after the sort). |
| 2238 | If \verb|comp| is not given, | 2312 | If \verb|comp| is not given, |
| 2239 | the standard \verb|<| Lua operator is used instead. | 2313 | the standard \verb|<| Lua operator is used instead. |
| 2240 | 2314 | ||
| 2241 | Function \verb|sort| returns the (sorted) table. | 2315 | Function \verb|sort| returns the (sorted) table. |
| 2242 | 2316 | ||
| 2243 | This function could be defined in Lua: | ||
| 2244 | \begin{verbatim} | ||
| 2245 | function aux_qsort (a, l, u, leq) | ||
| 2246 | if l < u then | ||
| 2247 | local m = floor((l+u)/2) -- choose middle element as pivot | ||
| 2248 | a[l], a[m] = a[m], a[l] -- swap pivot to first position | ||
| 2249 | local t = a[l] -- pivot value | ||
| 2250 | m = l | ||
| 2251 | local i = l+1 | ||
| 2252 | while i <= u do | ||
| 2253 | -- invariant: a[l+1..m] < t <= a[m+1..i-1] | ||
| 2254 | if leq(a[i], t) then | ||
| 2255 | m = m+1 | ||
| 2256 | a[m], a[i] = a[i], a[m] -- swap | ||
| 2257 | end | ||
| 2258 | i = i+1 | ||
| 2259 | end | ||
| 2260 | a[l], a[m] = a[m], a[l] -- swap pivot to a valid place | ||
| 2261 | -- a[l+1..m-1] < a[m] <= a[m+1..u] | ||
| 2262 | aux_qsort(a, l, m-1, leq) | ||
| 2263 | aux_qsort(a, m+1, u, leq) | ||
| 2264 | end | ||
| 2265 | return a -- return the table | ||
| 2266 | end | ||
| 2267 | |||
| 2268 | function sort (a, f) | ||
| 2269 | f = f or function (a,b) return a<b end | ||
| 2270 | return aux_qsort(a, 1, getn(a), f) | ||
| 2271 | end | ||
| 2272 | \end{verbatim} | ||
| 2273 | |||
| 2274 | 2317 | ||
| 2275 | \subsection{String Manipulation} | 2318 | \subsection{String Manipulation} |
| 2276 | This library provides generic functions for string manipulation, | 2319 | This library provides generic functions for string manipulation, |
| @@ -2364,9 +2407,8 @@ The only differences are that the options/modifiers | |||
| 2364 | and \verb|h| are not supported, | 2407 | and \verb|h| are not supported, |
| 2365 | and there is an extra option, \verb|q|. | 2408 | and there is an extra option, \verb|q|. |
| 2366 | This option formats a string in a form suitable to be safely read | 2409 | This option formats a string in a form suitable to be safely read |
| 2367 | back by the Lua interpreter; | 2410 | back by the Lua interpreter: |
| 2368 | that is, | 2411 | The string is written between double quotes, |
| 2369 | the string is written between double quotes, | ||
| 2370 | and all double quotes, returns and backslashes in the string | 2412 | and all double quotes, returns and backslashes in the string |
| 2371 | are correctly escaped when written. | 2413 | are correctly escaped when written. |
| 2372 | For instance, the call | 2414 | For instance, the call |
| @@ -2393,7 +2435,7 @@ The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, | |||
| 2393 | \verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all | 2435 | \verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all |
| 2394 | expect a number as argument, | 2436 | expect a number as argument, |
| 2395 | whereas \verb|q| and \verb|s| expect a string. | 2437 | whereas \verb|q| and \verb|s| expect a string. |
| 2396 | Note that the \verb|*| modifier can be simulated by building | 2438 | The \verb|*| modifier can be simulated by building |
| 2397 | the appropriate format string. | 2439 | the appropriate format string. |
| 2398 | For example, \verb|"%*g"| can be simulated with | 2440 | For example, \verb|"%*g"| can be simulated with |
| 2399 | \verb|"%"..width.."g"|. | 2441 | \verb|"%"..width.."g"|. |
| @@ -2464,17 +2506,15 @@ The following combinations are allowed in describing a character class: | |||
| 2464 | --- represents the character \emph{x} itself. | 2506 | --- represents the character \emph{x} itself. |
| 2465 | \item[\T{.}] --- (a dot) represents all characters. | 2507 | \item[\T{.}] --- (a dot) represents all characters. |
| 2466 | \item[\T{\%a}] --- represents all letters. | 2508 | \item[\T{\%a}] --- represents all letters. |
| 2467 | \item[\T{\%A}] --- represents all non letter characters. | 2509 | \item[\T{\%c}] --- represents all control characters. |
| 2468 | \item[\T{\%d}] --- represents all digits. | 2510 | \item[\T{\%d}] --- represents all digits. |
| 2469 | \item[\T{\%D}] --- represents all non digits. | ||
| 2470 | \item[\T{\%l}] --- represents all lower case letters. | 2511 | \item[\T{\%l}] --- represents all lower case letters. |
| 2471 | \item[\T{\%L}] --- represents all non lower case letter characters. | 2512 | \item[\T{\%p}] --- represents all punctuation characters. |
| 2472 | \item[\T{\%s}] --- represents all space characters. | 2513 | \item[\T{\%s}] --- represents all space characters. |
| 2473 | \item[\T{\%S}] --- represents all non space characters. | ||
| 2474 | \item[\T{\%u}] --- represents all upper case letters. | 2514 | \item[\T{\%u}] --- represents all upper case letters. |
| 2475 | \item[\T{\%U}] --- represents all non upper case letter characters. | ||
| 2476 | \item[\T{\%w}] --- represents all alphanumeric characters. | 2515 | \item[\T{\%w}] --- represents all alphanumeric characters. |
| 2477 | \item[\T{\%W}] --- represents all non alphanumeric characters. | 2516 | \item[\T{\%x}] --- represents all hexa-decimal digits. |
| 2517 | \item[\T{\%z}] --- represents the character with representation 0. | ||
| 2478 | \item[\T{\%\M{x}}] (where \M{x} is any non alphanumeric character) --- | 2518 | \item[\T{\%\M{x}}] (where \M{x} is any non alphanumeric character) --- |
| 2479 | represents the character \M{x}. | 2519 | represents the character \M{x}. |
| 2480 | This is the standard way to escape the magic characters \verb|()%.[*-?|. | 2520 | This is the standard way to escape the magic characters \verb|()%.[*-?|. |
| @@ -2495,6 +2535,9 @@ E.g., assuming an \emph{ascii} character set, | |||
| 2495 | represents the complement of char-set, | 2535 | represents the complement of char-set, |
| 2496 | where char-set is interpreted as above. | 2536 | where char-set is interpreted as above. |
| 2497 | \end{description} | 2537 | \end{description} |
| 2538 | For all classes represented by single letters (\verb|%a|, \verb|%c|, \ldots), | ||
| 2539 | the correspondent upper-case letter represents the complement of the class. | ||
| 2540 | For instance, \verb|%S| represents all non-space characters. | ||
| 2498 | 2541 | ||
| 2499 | The definitions of letter, space, etc. depend on the current locale. | 2542 | The definitions of letter, space, etc. depend on the current locale. |
| 2500 | In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|. | 2543 | In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|. |
| @@ -2591,6 +2634,8 @@ The function \verb|random|, when called without arguments, | |||
| 2591 | returns a pseudo-random real number in the range \Math{[0,1)}. | 2634 | returns a pseudo-random real number in the range \Math{[0,1)}. |
| 2592 | When called with a number \Math{n}, | 2635 | When called with a number \Math{n}, |
| 2593 | \verb|random| returns a pseudo-random integer in the range \Math{[1,n]}. | 2636 | \verb|random| returns a pseudo-random integer in the range \Math{[1,n]}. |
| 2637 | When called with two arguments, \Math{l} and \Math{u}, | ||
| 2638 | \verb|random| returns a pseudo-random integer in the range \Math{[l,u]}. | ||
| 2594 | 2639 | ||
| 2595 | 2640 | ||
| 2596 | \subsection{I/O Facilities} \label{libio} | 2641 | \subsection{I/O Facilities} \label{libio} |
| @@ -2891,10 +2936,18 @@ then \verb|linedefined| is \Math{-1}, and \verb|filename| is \verb|"(C)"|. | |||
| 2891 | The function \verb|lua_currentline| gives the current line where | 2936 | The function \verb|lua_currentline| gives the current line where |
| 2892 | a given function is executing. | 2937 | a given function is executing. |
| 2893 | It only works if the function has been compiled with debug | 2938 | It only works if the function has been compiled with debug |
| 2894 | information \see{pragma}. | 2939 | information. |
| 2895 | When no line information is available, | 2940 | When no line information is available, |
| 2896 | \verb|lua_currentline| returns \Math{-1}. | 2941 | \verb|lua_currentline| returns \Math{-1}. |
| 2897 | 2942 | ||
| 2943 | The generation of debug information is controled by an internal flag, | ||
| 2944 | which can be switched with | ||
| 2945 | \begin{verbatim} | ||
| 2946 | int lua_setdebug (int debug); | ||
| 2947 | \end{verbatim} | ||
| 2948 | This function sets the flag and returns its previous value. | ||
| 2949 | This flag can also be set from Lua~\see{pragma}. | ||
| 2950 | |||
| 2898 | Function \verb|lua_getobjname| tries to find a reasonable name for | 2951 | Function \verb|lua_getobjname| tries to find a reasonable name for |
| 2899 | a given function. | 2952 | a given function. |
| 2900 | Because functions in Lua are first class values, | 2953 | Because functions in Lua are first class values, |
| @@ -2918,6 +2971,8 @@ The following functions allow the manipulation of the | |||
| 2918 | local variables of a given activation record. | 2971 | local variables of a given activation record. |
| 2919 | They only work if the function has been compiled with debug | 2972 | They only work if the function has been compiled with debug |
| 2920 | information \see{pragma}. | 2973 | information \see{pragma}. |
| 2974 | Moreover, for these functions, a local variable becomes | ||
| 2975 | visible in the line after its definition. | ||
| 2921 | \begin{verbatim} | 2976 | \begin{verbatim} |
| 2922 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name); | 2977 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name); |
| 2923 | int lua_setlocal (lua_Function func, int local_number); | 2978 | int lua_setlocal (lua_Function func, int local_number); |
| @@ -2947,17 +3002,17 @@ then this function fails and returns 0. | |||
| 2947 | The Lua interpreter offers two hooks for debugging purposes: | 3002 | The Lua interpreter offers two hooks for debugging purposes: |
| 2948 | \begin{verbatim} | 3003 | \begin{verbatim} |
| 2949 | typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); | 3004 | typedef void (*lua_CHFunction) (lua_Function func, char *file, int line); |
| 2950 | extern lua_CHFunction lua_callhook; | 3005 | lua_CHFunction lua_setcallhook (lua_CHFunction func); |
| 2951 | 3006 | ||
| 2952 | typedef void (*lua_LHFunction) (int line); | 3007 | typedef void (*lua_LHFunction) (int line); |
| 2953 | extern lua_LHFunction lua_linehook; | 3008 | lua_LHFunction lua_setlinehook (lua_LHFunction func); |
| 2954 | \end{verbatim} | 3009 | \end{verbatim} |
| 2955 | The first one is called whenever the interpreter enters or leaves a | 3010 | The first one is called whenever the interpreter enters or leaves a |
| 2956 | function. | 3011 | function. |
| 2957 | When entering a function, | 3012 | When entering a function, |
| 2958 | its parameters are a handle to the function activation record, | 3013 | its parameters are a handle to the function activation record, |
| 2959 | plus the file and the line where the function is defined (the same | 3014 | plus the file and the line where the function is defined |
| 2960 | information which is provided by \verb|lua_funcinfo|); | 3015 | (the same information which is provided by \verb|lua_funcinfo|); |
| 2961 | when leaving a function, \verb|func| is \verb|LUA_NOOBJECT|, | 3016 | when leaving a function, \verb|func| is \verb|LUA_NOOBJECT|, |
| 2962 | \verb|file| is \verb|"(return)"|, and \verb|line| is 0. | 3017 | \verb|file| is \verb|"(return)"|, and \verb|line| is 0. |
| 2963 | 3018 | ||
| @@ -2971,6 +3026,8 @@ has been compiled with debug information \see{pragma}. | |||
| 2971 | 3026 | ||
| 2972 | A hook is disabled when its value is \verb|NULL|, | 3027 | A hook is disabled when its value is \verb|NULL|, |
| 2973 | which is the initial value of both hooks. | 3028 | which is the initial value of both hooks. |
| 3029 | Both \verb|lua_setcallhook| and \verb|lua_setlinehook| | ||
| 3030 | set their corresponding hooks and return their previous values. | ||
| 2974 | 3031 | ||
| 2975 | 3032 | ||
| 2976 | 3033 | ||
| @@ -3040,6 +3097,18 @@ the previous public versions of Lua, | |||
| 3040 | some differences had to be introduced. | 3097 | some differences had to be introduced. |
| 3041 | Here is a list of all these incompatibilities. | 3098 | Here is a list of all these incompatibilities. |
| 3042 | 3099 | ||
| 3100 | \subsection*{Incompatibilities with \Index{version 3.1}} | ||
| 3101 | \begin{itemize} | ||
| 3102 | \item | ||
| 3103 | In the debug API, the old variables \verb|lua_debug|, | ||
| 3104 | \verb|lua_callhook| and \verb|lua_linehook| now live inside \verb|lua_state|. | ||
| 3105 | Therefore, they are no more directly accessible, and must be | ||
| 3106 | manipulated through the new functions \verb|lua_setdebug|, | ||
| 3107 | \verb|lua_setcallhook| and \verb|lua_setlinehook|. | ||
| 3108 | |||
| 3109 | \item Old pre-compiled code is obsolete, and must be re-compiled. | ||
| 3110 | \end{itemize} | ||
| 3111 | |||
| 3043 | \subsection*{Incompatibilities with \Index{version 3.0}} | 3112 | \subsection*{Incompatibilities with \Index{version 3.0}} |
| 3044 | \begin{itemize} | 3113 | \begin{itemize} |
| 3045 | 3114 | ||
