diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-12 14:43:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-12 14:43:35 -0300 |
| commit | 27f8a4a69e15bc9e1ca98db87d10b19c582c6fd3 (patch) | |
| tree | 22dccfd50baadec8017676587e1baacbf007fd5e | |
| parent | 8e4ac679ffce4a2d59b0a404473275411854f598 (diff) | |
| download | lua-27f8a4a69e15bc9e1ca98db87d10b19c582c6fd3.tar.gz lua-27f8a4a69e15bc9e1ca98db87d10b19c582c6fd3.tar.bz2 lua-27f8a4a69e15bc9e1ca98db87d10b19c582c6fd3.zip | |
towards 5.0 (one more step)...
| -rw-r--r-- | manual.tex | 125 |
1 files changed, 72 insertions, 53 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | % $Id: manual.tex,v 1.57 2002/08/06 19:10:44 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.58 2002/08/09 21:03:19 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | \documentclass[11pt,twoside,draft]{article} | 3 | \documentclass[11pt,twoside,draft]{article} |
| 4 | \usepackage{fullpage} | 4 | \usepackage{fullpage} |
| @@ -133,7 +133,7 @@ Waldemar Celes | |||
| 133 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 133 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | %\date{{\small \tt\$Date: 2002/08/06 19:10:44 $ $}} | 136 | %\date{{\small \tt\$Date: 2002/08/09 21:03:19 $ $}} |
| 137 | 137 | ||
| 138 | \maketitle | 138 | \maketitle |
| 139 | 139 | ||
| @@ -2616,14 +2616,14 @@ The structure \verb|lua_Debug| is used to carry different pieces of | |||
| 2616 | information about an active function: | 2616 | information about an active function: |
| 2617 | \begin{verbatim} | 2617 | \begin{verbatim} |
| 2618 | typedef struct lua_Debug { | 2618 | typedef struct lua_Debug { |
| 2619 | const char *event; /* "call", "return" */ | 2619 | lua_Hookevent event; |
| 2620 | int currentline; /* (l) */ | ||
| 2621 | const char *name; /* (n) */ | 2620 | const char *name; /* (n) */ |
| 2622 | const char *namewhat; /* (n) `global', `local', `field', `method' */ | 2621 | const char *namewhat; /* (n) `global', `local', `field', `method' */ |
| 2622 | const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ | ||
| 2623 | const char *source; /* (S) */ | ||
| 2624 | int currentline; /* (l) */ | ||
| 2623 | int nups; /* (u) number of upvalues */ | 2625 | int nups; /* (u) number of upvalues */ |
| 2624 | int linedefined; /* (S) */ | 2626 | int linedefined; /* (S) */ |
| 2625 | const char *what; /* (S) "Lua" function, "C" function, Lua "main" */ | ||
| 2626 | const char *source; /* (S) */ | ||
| 2627 | char short_src[LUA_IDSIZE]; /* (S) */ | 2627 | char short_src[LUA_IDSIZE]; /* (S) */ |
| 2628 | 2628 | ||
| 2629 | /* private part */ | 2629 | /* private part */ |
| @@ -2760,38 +2760,53 @@ local variables for a function at a given level of the stack: | |||
| 2760 | 2760 | ||
| 2761 | \subsection{Hooks}\label{sub-hooks} | 2761 | \subsection{Hooks}\label{sub-hooks} |
| 2762 | 2762 | ||
| 2763 | The Lua interpreter offers two hooks for debugging purposes: | 2763 | The Lua interpreter offers a mechanism of hooks: |
| 2764 | a \emph{call} hook and a \emph{line} hook. | 2764 | user-defined C functions that are called during the program execution. |
| 2765 | Both have type \verb|lua_Hook|, defined as follows: | 2765 | A hook may be called in four different events: |
| 2766 | a \emph{call} event, when Lua calls a function; | ||
| 2767 | a \emph{return} event, when Lua returns from a function; | ||
| 2768 | a \emph{line} event, when Lua starts executing a new line of code; | ||
| 2769 | and a \emph{count} event, that happens every ``count'' instructions. | ||
| 2770 | Lua identifies them with the following enumeration: | ||
| 2771 | \begin{verbatim} | ||
| 2772 | typedef enum lua_Hookevent { | ||
| 2773 | LUA_HOOKCALL, LUA_HOOKRET, LUA_HOOKLINE, LUA_HOOKCOUNT | ||
| 2774 | } lua_Hookevent; | ||
| 2775 | \end{verbatim} | ||
| 2776 | |||
| 2777 | A hook has type \verb|lua_Hook|, defined as follows: | ||
| 2766 | \begin{verbatim} | 2778 | \begin{verbatim} |
| 2767 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); | 2779 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); |
| 2768 | \end{verbatim} | 2780 | \end{verbatim} |
| 2769 | \DefAPI{lua_Hook} | 2781 | \DefAPI{lua_Hook} |
| 2770 | You can set the hooks with the following functions: | 2782 | You can set the hook with the following function: |
| 2771 | \begin{verbatim} | 2783 | \begin{verbatim} |
| 2772 | lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); | 2784 | int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask); |
| 2773 | lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); | ||
| 2774 | \end{verbatim} | 2785 | \end{verbatim} |
| 2775 | \DefAPI{lua_setcallhook}\DefAPI{lua_setlinehook} | 2786 | \DefAPI{lua_sethook} |
| 2776 | A hook is disabled when its value is \verb|NULL|, | 2787 | \verb|func| is the hook, |
| 2777 | which is the initial value of both hooks. | 2788 | and \verb|mask| specifies at which events it will be called. |
| 2778 | The functions \verb|lua_setcallhook| and \verb|lua_setlinehook| | 2789 | It is formed by a disjunction of the constants |
| 2779 | set their corresponding hooks and return their previous values. | 2790 | \verb|LUA_MASKCALL|, |
| 2780 | 2791 | \verb|LUA_MASKRET|, | |
| 2781 | The call hook is called whenever the | 2792 | \verb|LUA_MASKLINE|, |
| 2782 | interpreter enters or leaves a function. | 2793 | plus the macro \verb|LUA_MASKCOUNT(count)|. |
| 2783 | The \verb|event| field of \verb|ar| has the string \verb|"call"| | 2794 | %TODO explicar melhor... |
| 2784 | or \verb|"return"|. | 2795 | |
| 2785 | This \verb|ar| can then be used in calls to \verb|lua_getinfo|, | 2796 | A hook is disabled with the mask zero. |
| 2786 | \verb|lua_getlocal|, and \verb|lua_setlocal| | 2797 | |
| 2787 | to get more information about the function and to manipulate its | 2798 | You can get the current hook and the current mask with the next functions: |
| 2788 | local variables. | 2799 | \begin{verbatim} |
| 2789 | 2800 | lua_Hook lua_gethook (lua_State *L); | |
| 2790 | The line hook is called every time the interpreter changes | 2801 | unsigned long lua_gethookmask (lua_State *L); |
| 2791 | the line of code it is executing. | 2802 | \end{verbatim} |
| 2792 | The \verb|event| field of \verb|ar| has the string \verb|"line"|, | 2803 | \DefAPI{lua_gethook}\DefAPI{lua_gethookmask} |
| 2793 | and the \verb|currentline| field has the new line number. | 2804 | You can get the count inside a mask with the macro \verb|lua_getmaskcount|. |
| 2794 | Again, you can use this \verb|ar| in other calls to the debug API. | 2805 | |
| 2806 | Whenever a hook is called, its \verb|ar| argument has its field | ||
| 2807 | \verb|event| set to the specific event that triggered the hook. | ||
| 2808 | Moreover, for line events, the field \verb|currentline| is also set. | ||
| 2809 | For the value of any other field, the hook must call \verb|lua_getinfo|. | ||
| 2795 | 2810 | ||
| 2796 | While Lua is running a hook, it disables other calls to hooks. | 2811 | While Lua is running a hook, it disables other calls to hooks. |
| 2797 | Therefore, if a hook calls Lua to execute a function or a chunk, | 2812 | Therefore, if a hook calls Lua to execute a function or a chunk, |
| @@ -4037,37 +4052,38 @@ specially the head of the group, Marcelo Gattass. | |||
| 4037 | At the risk of omitting several names, | 4052 | At the risk of omitting several names, |
| 4038 | we also thank the following individuals for supporting, | 4053 | we also thank the following individuals for supporting, |
| 4039 | contributing to, and spreading the word about Lua: | 4054 | contributing to, and spreading the word about Lua: |
| 4040 | Alan Watson, | 4055 | Mark Ian Barlow, |
| 4056 | John Belmonte, | ||
| 4057 | Renato Borges, | ||
| 4058 | Carlos Cassino, | ||
| 4059 | Renato Cerqueira, | ||
| 4041 | Andr\'e Clinio, | 4060 | Andr\'e Clinio, |
| 4042 | Andr\'e Costa, | 4061 | Andr\'e Costa, |
| 4043 | Bret Mogilefsky, | 4062 | Steve Dekorte, |
| 4063 | Jon Erickson, | ||
| 4064 | Tom\'as Gorham, | ||
| 4065 | Stephan Herrmann, | ||
| 4066 | Erik Hougaard, | ||
| 4067 | David Jeske, | ||
| 4068 | Jon Kleiser, | ||
| 4044 | Cameron Laird, | 4069 | Cameron Laird, |
| 4045 | Carlos Cassino, | ||
| 4046 | Carlos Henrique Levy, | 4070 | Carlos Henrique Levy, |
| 4047 | Claudio Terra, | 4071 | Philippe Lhost, |
| 4048 | David Jeske, | ||
| 4049 | Edgar Toernig, | ||
| 4050 | Erik Hougaard, | ||
| 4051 | Jim Mathies, | 4072 | Jim Mathies, |
| 4052 | John Belmonte, | 4073 | Bret Mogilefsky, |
| 4053 | John Passaniti, | 4074 | John Passaniti, |
| 4054 | John Roll, | 4075 | Vincent Penquerc'h, |
| 4055 | Jon Erickson, | ||
| 4056 | Jon Kleiser, | ||
| 4057 | Mark Ian Barlow, | ||
| 4058 | Nick Trout, | ||
| 4059 | Noemi Rodriguez, | ||
| 4060 | Norman Ramsey, | 4076 | Norman Ramsey, |
| 4061 | Philippe Lhost, | ||
| 4062 | Renata Ratton, | 4077 | Renata Ratton, |
| 4063 | Renato Borges, | 4078 | Noemi Rodriguez, |
| 4064 | Renato Cerqueira, | 4079 | John Roll, |
| 4080 | Antonio Scuri, | ||
| 4081 | Claudio Terra, | ||
| 4065 | Reuben Thomas, | 4082 | Reuben Thomas, |
| 4066 | Stephan Herrmann, | 4083 | Edgar Toernig, |
| 4067 | Steve Dekorte, | 4084 | Nick Trout, |
| 4068 | Thatcher Ulrich, | 4085 | Thatcher Ulrich, |
| 4069 | Tom\'as Gorham, | 4086 | Alan Watson. |
| 4070 | Vincent Penquerc'h. | ||
| 4071 | Thank you! | 4087 | Thank you! |
| 4072 | 4088 | ||
| 4073 | 4089 | ||
| @@ -4089,6 +4105,9 @@ A function call as the last expression in a list constructor | |||
| 4089 | (like \verb|{a,b,f()}}|) has all its return values inserted in the list. | 4105 | (like \verb|{a,b,f()}}|) has all its return values inserted in the list. |
| 4090 | 4106 | ||
| 4091 | \item | 4107 | \item |
| 4108 | The precedence of \rwd{or} is smaller than the precedence of \rwd{and}. | ||
| 4109 | |||
| 4110 | \item | ||
| 4092 | \rwd{in} is a reserved word. | 4111 | \rwd{in} is a reserved word. |
| 4093 | 4112 | ||
| 4094 | \item | 4113 | \item |
