aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-03-29 11:21:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-03-29 11:21:37 -0300
commite0ff4e5d22bd2dbe74dd588f0710c18ae8a671ab (patch)
tree8e6d13aecaef1cd40a0a95b14201572becdeb43e
parentbf7f85d609291023bcc53df862198f5877ca00d6 (diff)
downloadlua-e0ff4e5d22bd2dbe74dd588f0710c18ae8a671ab.tar.gz
lua-e0ff4e5d22bd2dbe74dd588f0710c18ae8a671ab.tar.bz2
lua-e0ff4e5d22bd2dbe74dd588f0710c18ae8a671ab.zip
first version about Lua debug library.
-rw-r--r--manual.tex210
1 files changed, 172 insertions, 38 deletions
diff --git a/manual.tex b/manual.tex
index 3c550cd7..90fa12a2 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.26 1999/03/10 14:09:45 roberto Exp roberto $ 1% $Id: manual.tex,v 1.27 1999/03/11 19:00:12 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: 1999/03/10 14:09:45 $} 44%\date{\small \verb$Date: 1999/03/11 19:00:12 $}
45 45
46\maketitle 46\maketitle
47 47
@@ -2624,8 +2624,8 @@ When called with two arguments, \Math{l} and \Math{u},
2624 2624
2625\subsection{I/O Facilities} \label{libio} 2625\subsection{I/O Facilities} \label{libio}
2626 2626
2627All input and output operations in Lua are done over two 2627All input and output operations in Lua are done, by default,
2628\Def{file handles}, one for reading and one for writing. 2628over two \Def{file handles}, one for reading and one for writing.
2629These handles are stored in two Lua global variables, 2629These handles are stored in two Lua global variables,
2630called \verb|_INPUT| and \verb|_OUTPUT|. 2630called \verb|_INPUT| and \verb|_OUTPUT|.
2631The global variables 2631The global variables
@@ -2638,20 +2638,45 @@ Initially, \verb|_INPUT=_STDIN| and \verb|_OUTPUT=_STDOUT|.
2638 2638
2639A file handle is a userdata containing the file stream \verb|FILE*|, 2639A file handle is a userdata containing the file stream \verb|FILE*|,
2640and with a distinctive tag created by the I/O library. 2640and with a distinctive tag created by the I/O library.
2641 2641Whenever a file handle is collected by the garbage collector,
2642its correspondent stream is automatically closed.
2642 2643
2643Unless otherwise stated, 2644Unless otherwise stated,
2644all I/O functions return \nil\ on failure and 2645all I/O functions return \nil\ on failure and
2645some value different from \nil\ on success. 2646some value different from \nil\ on success.
2646 2647
2647\subsubsection*{\ff \T{readfrom (filename [, mode])}}\Deffunc{readfrom} 2648\subsubsection*{\ff \T{openfile (filename, mode)}}\Deffunc{openfile}
2649
2650This function opens a file,
2651in the mode specified in the string \verb|mode|.
2652It returns a new file handle,
2653or, in case of errors, \nil\ plus a string describing the error.
2654This function does not modify neither \verb|_INPUT| nor \verb|_OUTPUT|.
2655
2656The string mode can be any of the following:
2657\begin{description}
2658\item["r"] read mode;
2659\item["w"] write mode;
2660\item["a"] append mode;
2661\item["r+"] update mode, all previous data is preserved;
2662\item["w+"] update mode, all previous data is erased;
2663\item["a+"] append update mode, previous data is preserved,
2664 writing is only allowed at the end of file.
2665\end{description}
2666The string mode may also have a \verb|b| at the end,
2667which is needed in some systems to open the file in binary mode.
2668
2669\subsubsection*{\ff \T{closefile (handle)}}\Deffunc{closefile}
2670
2671This function closes the given file.
2672It does not modify neither \verb|_INPUT| nor \verb|_OUTPUT|.
2673
2674\subsubsection*{\ff \T{readfrom (filename)}}\Deffunc{readfrom}
2648 2675
2649This function may be called in two ways. 2676This function may be called in two ways.
2650When called with a file name, it opens the named file, 2677When called with a file name, it opens the named file,
2651sets its handle as the value of \verb|_INPUT|, 2678sets its handle as the value of \verb|_INPUT|,
2652and returns this value. 2679and returns this value.
2653An optional \verb|mode| argument with the string \verb|"binary"|
2654opens file in binary mode (where this applies).
2655It does not close the current input file. 2680It does not close the current input file.
2656When called without parameters, 2681When called without parameters,
2657it closes the \verb|_INPUT| file, 2682it closes the \verb|_INPUT| file,
@@ -2670,15 +2695,13 @@ the number of files that can be open at the same time is
2670usually limited and depends on the system. 2695usually limited and depends on the system.
2671\end{quotation} 2696\end{quotation}
2672 2697
2673\subsubsection*{\ff \T{writeto (filename [, mode])}}\Deffunc{writeto} 2698\subsubsection*{\ff \T{writeto (filename)}}\Deffunc{writeto}
2674 2699
2675This function may be called in two ways. 2700This function may be called in two ways.
2676When called with a file name, 2701When called with a file name,
2677it opens the named file, 2702it opens the named file,
2678sets its handle as the value of \verb|_OUTPUT|, 2703sets its handle as the value of \verb|_OUTPUT|,
2679and returns this value. 2704and returns this value.
2680An optional \verb|mode| argument with the string \verb|"binary"|
2681opens file in binary mode (where this applies).
2682It does not close the current output file. 2705It does not close the current output file.
2683Note that, if the file already exists, 2706Note that, if the file already exists,
2684then it will be \emph{completely erased} with this operation. 2707then it will be \emph{completely erased} with this operation.
@@ -2700,20 +2723,15 @@ the number of files that can be open at the same time is
2700usually limited and depends on the system. 2723usually limited and depends on the system.
2701\end{quotation} 2724\end{quotation}
2702 2725
2703\subsubsection*{\ff \T{appendto (filename [, mode])}}\Deffunc{appendto} 2726\subsubsection*{\ff \T{appendto (filename)}}\Deffunc{appendto}
2704 2727
2705Opens a file named \verb|filename| and sets it as the 2728Opens a file named \verb|filename| and sets it as the
2706value of \verb|_OUTPUT|. 2729value of \verb|_OUTPUT|.
2707An optional \verb|mode| argument with the string \verb|"binary"|
2708opens file in binary mode (where this applies).
2709Unlike the \verb|writeto| operation, 2730Unlike the \verb|writeto| operation,
2710this function does not erase any previous content of the file. 2731this function does not erase any previous content of the file.
2711If this function fails, it returns \nil, 2732If this function fails, it returns \nil,
2712plus a string describing the error. 2733plus a string describing the error.
2713 2734
2714Note that function \verb|writeto| is
2715available to close an output file opened by \verb|appendto|.
2716
2717\subsubsection*{\ff \T{remove (filename)}}\Deffunc{remove} 2735\subsubsection*{\ff \T{remove (filename)}}\Deffunc{remove}
2718 2736
2719Deletes the file with the given name. 2737Deletes the file with the given name.
@@ -2741,9 +2759,9 @@ measured in bytes from the beginning of the file,
2741to the position given by \verb|offset| plus a base 2759to the position given by \verb|offset| plus a base
2742specified by the string \verb|whence|, as follows: 2760specified by the string \verb|whence|, as follows:
2743\begin{description} 2761\begin{description}
2744\item[\tt "set"] base is position 0 (beginning of the file); 2762\item["set"] base is position 0 (beginning of the file);
2745\item[\tt "cur"] base is current position; 2763\item["cur"] base is current position;
2746\item[\tt "end"] base is end of file; 2764\item["end"] base is end of file;
2747\end{description} 2765\end{description}
2748In case of success, function \verb|seek| returns the final file position, 2766In case of success, function \verb|seek| returns the final file position,
2749measured in bytes from the beginning of the file. 2767measured in bytes from the beginning of the file.
@@ -2765,18 +2783,17 @@ Returns a string with a file name that can safely
2765be used for a temporary file. 2783be used for a temporary file.
2766The file must be explicitly removed when no longer needed. 2784The file must be explicitly removed when no longer needed.
2767 2785
2768\subsubsection*{\ff \T{read ([filehandle] [readpattern])}}\Deffunc{read} 2786\subsubsection*{\ff \T{read ([filehandle] {readpattern})}}\Deffunc{read}
2769 2787
2770Reads file \verb|_INPUT|, 2788Reads file \verb|_INPUT|,
2771or \verb|filehandle| if this argument is given, 2789or \verb|filehandle| if this argument is given,
2772according to a read pattern, which specifies how much to read; 2790according to read patterns, which specify how much to read.
2773characters are read from the input file until 2791For each pattern,
2774the read pattern fails or ends. 2792the function returns a string with the characters read,
2775The function \verb|read| returns a string with the characters read,
2776even if the pattern succeeds only partially, 2793even if the pattern succeeds only partially,
2777or \nil\ if the read pattern fails \emph{and} 2794or \nil\ if the read pattern fails \emph{and}
2778the result string would be empty. 2795the result string would be empty.
2779When called without parameters, 2796When called without patterns,
2780it uses a default pattern that reads the next line 2797it uses a default pattern that reads the next line
2781(see below). 2798(see below).
2782 2799
@@ -2803,20 +2820,21 @@ that describe \Def{skips}.
2803Characters matching a skip are read, 2820Characters matching a skip are read,
2804but are not included in the resulting string. 2821but are not included in the resulting string.
2805 2822
2806Following are some examples of read patterns and their meanings: 2823There are some predefined patterns, as follows:
2807\begin{itemize} 2824\begin{description}
2808\item \verb|"."| returns the next character, or \nil\ on end of file. 2825\item["*n"] reads a number;
2809\item \verb|".*"| reads the whole file. 2826this is the only pattern that returns a number instead of a string.
2810\item \verb|"[^\n]*{\n}"| returns the next line 2827\item["*l"] returns the next line
2811(skipping the end of line), or \nil\ on end of file. 2828(skipping the end of line), or \nil\ on end of file.
2812This is the default pattern. 2829This is the default pattern.
2813\item \verb|"{%s*}%S%S*"| returns the next word 2830It is equivalent to the pattern \verb|"[^\n]*{\n}"|.
2831\item["*a"] reads the whole file.
2832It is equivalent to the pattern \verb|".*"|.
2833\item["*w"] returns the next word
2814(maximal sequence of non white-space characters), 2834(maximal sequence of non white-space characters),
2815skipping spaces if necessary, 2835skipping spaces if necessary, or \nil\ on end of file.
2816or \nil\ on end of file. 2836It is equivalent to the pattern \verb|"{%s*}%S%S*"|.
2817\item \verb|"{%s*}[+-]?%d%d*"| returns the next integer 2837\end{description}
2818or \nil\ if the next characters do not conform to an integer format.
2819\end{itemize}
2820 2838
2821\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write} 2839\subsubsection*{\ff \T{write ([filehandle, ] value1, ...)}}\Deffunc{write}
2822 2840
@@ -3010,7 +3028,7 @@ the line of code it is executing.
3010Its only parameter is the line number 3028Its only parameter is the line number
3011(the same information which is provided by the call 3029(the same information which is provided by the call
3012\verb|lua_currentline(lua_stackedfunction(0))|). 3030\verb|lua_currentline(lua_stackedfunction(0))|).
3013This second hook is only called if the active function 3031This second hook is called only if the active function
3014has been compiled with debug information \see{pragma}. 3032has been compiled with debug information \see{pragma}.
3015 3033
3016A hook is disabled when its value is \verb|NULL|, 3034A hook is disabled when its value is \verb|NULL|,
@@ -3020,6 +3038,122 @@ set their corresponding hooks and return their previous values.
3020 3038
3021 3039
3022 3040
3041\subsection{The Reflexive Debugger Interface}
3042
3043The library \verb|ldblib| provides
3044the functionallity of the debugger interface to Lua programs.
3045If you want to use this library,
3046your host application must open it first,
3047calling \verb|lua_dblibopen|.
3048
3049You should exert great care when using this library.
3050Functions provided here should be used exclusively for debugging
3051and similar tasks (e.g. profiling):
3052Please resist the temptation to use them as a
3053usual programming tool.
3054They are slow and violate some (otherwise) secure aspects of the
3055language (e.g. privacy of local variables).
3056As a general rule, if your program does not need this library,
3057do not open it.
3058
3059
3060\subsubsection*{\ff \T{funcinfo (function)}}\Deffunc{funcinfo}
3061
3062This function returns a table with information about the given function.
3063The table contains the following fields:
3064\begin{description}
3065\item[kind]: may be \verb|"C"|, if this is a C function,
3066\verb|"chunk"|, if this is the main part of a chunk,
3067or \verb|"Lua"| if this is a Lua function.
3068
3069\item[source] the source where the function was defined.
3070If the function was defined in a string,
3071\verb|source| is that string;
3072If the function was defined in a file,
3073\verb|source| starts with a \verb|@| followed by the file name.
3074
3075\item[def_line] the line where the function was defined in the source
3076(only valid if this is a Lua function).
3077
3078\item[where] can be \verb|"global"| if this function has a global name,
3079or \verb|"tag-method"| if this function is a tag method handler.
3080
3081\item[name] if \verb|where| = \verb|global|,
3082\verb|name| is the global name of the function;
3083if \verb|where| = \verb|tag-method|,
3084\verb|name| is the event name of the tag method.
3085\end{description}
3086
3087\subsubsection*{\ff \T{getstack (index)}}\Deffunc{getstack}
3088
3089This function returns a table with informations about the function
3090running at level \verb|index| of the stack.
3091Index 0 is the current function (\verb|getstack| itself).
3092If \verb|index| is bigger than the number of active functions,
3093the function returns \nil.
3094The table contains all the fields returned by \verb|funcinfo|,
3095plus the following:
3096\begin{description}
3097\item[func] the function at that level.
3098\item[current] the current line on the function execution;
3099this will be available only when the function is
3100precompiled with debug information.
3101\end{description}
3102
3103\subsubsection*{\ff \T{getlocal (index [, local])}}\Deffunc{getlocal}
3104
3105This function returns information about the local variables of the
3106function at level \verb|index| of the stack.
3107It can be called in three ways.
3108When called without a \verb|local| argument,
3109it returns a table, which associates variable names to their values.
3110When called with a name (a string) as \verb|local|,
3111it returns the value of the local variable with that name.
3112Finally, when called with an index (a number),
3113it returns the value and the name of the local variable
3114with that index.
3115(The first parameter has index 1, and so on,
3116until the last active local variable.)
3117In that case, the function returns \nil\ if there is no local
3118variable with the given index.
3119The specification by index is the only way to distinguish
3120homonym variables in a function.
3121
3122\subsubsection*{\ff \T{setlocal (index, local, newvalue)}}\Deffunc{setlocal}
3123
3124This function changes the values of the local variables of the
3125function at level \verb|index| of the stack.
3126The local variable can be specified by name or by index;
3127see function \verb|getlocal|.
3128
3129\subsubsection*{\ff \T{setcallhook (hook)}}\Deffunc{setcallhook}
3130
3131Sets the function \verb|hook| as the call hook;
3132this hook will be called every time the interpreter starts and
3133exits the execution of a function.
3134When Lua enters a function,
3135the hook is called with the function been called,
3136plus the source and the line where the function is defined.
3137When Lua exits a function,
3138the hook is called with no arguments.
3139
3140When called without arguments,
3141this function turns off call hooks.
3142
3143\subsubsection*{\ff \T{setlinehook (hook)}}\Deffunc{setlinehook}
3144
3145Sets the function \verb|hook| as the line hook;
3146this hook will be called every time the interpreter changes
3147the line of code it is executing.
3148The only argument to the hook is the line number the interpreter
3149is about to execut.
3150This hook is called only if the active function
3151has been compiled with debug information \see{pragma}.
3152
3153When called without arguments,
3154this function turns off line hooks.
3155
3156
3023\section{\Index{Lua Stand-alone}} \label{lua-sa} 3157\section{\Index{Lua Stand-alone}} \label{lua-sa}
3024 3158
3025Although Lua has been designed as an extension language, 3159Although Lua has been designed as an extension language,