diff --git a/lundump.c b/lundump.c index 022b25ba..a8d06106 100644 --- a/lundump.c +++ b/lundump.c @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 1.32 2000/09/21 03:15:36 lhf Exp lhf $ +** $Id: lundump.c,v 1.33 2000/10/31 16:57:23 lhf Exp $ ** load bytecodes from files ** See Copyright Notice in lua.h */ @@ -178,7 +178,7 @@ static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) int r=ezgetc(L,Z); if (r!=s) luaO_verror(L,"virtual machine mismatch in `%.99s':\n" - " %s is %d but read %d",ZNAME(Z),what,s,r); + " %.20s is %d but read %d",ZNAME(Z),what,s,r); } #define TESTSIZE(s) TestSize(L,s,#s,Z) diff --git a/lundump.h b/lundump.h index 703a3e34..446d2de9 100644 --- a/lundump.h +++ b/lundump.h @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.20 2000/09/18 20:03:46 lhf Exp lhf $ +** $Id: lundump.h,v 1.21 2000/10/31 16:57:23 lhf Exp $ ** load pre-compiled Lua chunks ** See Copyright Notice in lua.h */ @@ -23,10 +23,10 @@ int luaU_endianess (void); #define SIGNATURE "Lua" /* ...followed by this signature */ /* formats for error messages */ -#define xSOURCE "<%d:%.255s>" -#define SOURCE "<%.255s:%d>" -#define IN " in %p " SOURCE -#define INLOC tf,tf->source->str,tf->lineDefined +#define SOURCE_FMT "<%d:%.99s>" +#define SOURCE tf->lineDefined,tf->source->str +#define IN_FMT " in %p " SOURCE_FMT +#define IN tf,SOURCE /* a multiple of PI for testing native format */ /* multiplying by 1E8 gives non-trivial integer values */ diff --git a/manual.tex b/manual.tex index 817f17ad..cac5d19c 100644 --- a/manual.tex +++ b/manual.tex @@ -1,25 +1,31 @@ -% $Id: manual.tex,v 1.44 2000/09/20 17:21:20 roberto Exp roberto $ +% $Id: manual.tex,v 1.45 2000/10/31 18:20:01 roberto Exp roberto $ \documentclass[11pt]{article} -\usepackage{fullpage,bnf} +\usepackage{fullpage} +\usepackage{bnf} \usepackage{graphicx} %\usepackage{times} \catcode`\_=12 -\newcommand{\See}[1]{Section~\ref{#1}} -\newcommand{\see}[1]{(see \See{#1})} -\newcommand{\M}[1]{\rm\emph{#1}} +%\newcommand{\See}[1]{Section~\ref{#1}} +\newcommand{\See}[1]{\S\ref{#1}} +\newcommand{\see}[1]{(see~\See{#1})} +\newcommand{\M}[1]{{\rm\emph{#1}}} \newcommand{\T}[1]{{\tt #1}} \newcommand{\Math}[1]{$#1$} \newcommand{\nil}{{\bf nil}} \def\tecgraf{{\sf TeC\kern-.21em\lower.7ex\hbox{Graf}}} -\newcommand{\Index}[1]{#1\index{#1}} -\newcommand{\IndexVerb}[1]{\T{#1}\index{#1}} -\newcommand{\IndexEmph}[1]{\emph{#1}\index{#1}} +\newcommand{\Index}[1]{#1\index{#1@{\lowercase{#1}}}} +\newcommand{\IndexVerb}[1]{\T{#1}\index{#1@{\tt #1}}} +\newcommand{\IndexEmph}[1]{\emph{#1}\index{#1@{\lowercase{#1}}}} +\newcommand{\IndexTM}[1]{\index{#1 event@{``#1'' event}}\index{tag method!#1}} \newcommand{\Def}[1]{\emph{#1}\index{#1}} -\newcommand{\Deffunc}[1]{\index{#1}} +\newcommand{\IndexAPI}[1]{\T{#1}\DefAPI{#1}} +\newcommand{\IndexLIB}[1]{\T{#1}\DefLIB{#1}} +\newcommand{\DefLIB}[1]{\index{#1@{\tt #1}}} +\newcommand{\DefAPI}[1]{\index{C API!#1@{\tt #1}}} \newcommand{\ff}{$\bullet$\ } @@ -27,7 +33,6 @@ % LHF \renewcommand{\ter}[1]{{\rm`{\tt#1}'}} -\newcommand{\Nter}[1]{{\rm{\tt#1}}} \newcommand{\NOTE}{\par\medskip\noindent\emph{NOTE}: } \makeindex @@ -97,8 +102,8 @@ and its documentation. \noindent The Lua language and this implementation have been entirely designed and -written by Waldemar Celes, Roberto Ierusalimschy and Luiz Henrique de -Figueiredo at TeCGraf, PUC-Rio. +written by Waldemar Celes, Roberto Ierusalimschy, and Luiz Henrique de +Figueiredo at TeCGraf, PUC-Rio in Brazil. \noindent This implementation contains no third-party code. @@ -129,16 +134,13 @@ Waldemar Celes \tecgraf\ --- Computer Science Department --- PUC-Rio } -\date{{\small \tt\$Date: 2000/09/20 17:21:20 $ $}} +\date{{\small \tt\$Date: 2000/10/31 18:20:01 $ $}} \maketitle \pagestyle{plain} \pagenumbering{roman} -%\thispagestyle{empty} -%\pagestyle{empty} - \begin{abstract} \noindent Lua is a powerful, light-weight programming language @@ -197,8 +199,8 @@ a intera\c{c}\~ao entre programas Lua e programas C~hospedeiros. \newpage \setcounter{page}{1} -\pagenumbering{arabic} \pagestyle{plain} +\pagenumbering{arabic} \section{Introduction} @@ -269,8 +271,8 @@ using API functions from the library that implements Lua. \Index{Global variables} in Lua do not need to be declared. Any variable is assumed to be global unless explicitly declared local \see{localvar}. -Before the first assignment, the value of a global variable is \nil; -this default can be changed \see{tag-method}. +Before the first assignment, the value of a global variable is \nil\ % +(this default can be changed; see \See{tag-method}). A table is used to keep all global names and values (tables are explained in \See{TypesSec}). @@ -291,11 +293,12 @@ The complete syntax of Lua is given on page~\pageref{BNF}.) A chunk may be stored in a file or in a string inside the host program. When a chunk is executed, first it is pre-compiled into bytecodes for -a virtual machine, and then the statements are executed in sequential order. +a virtual machine, and then the statements are executed in sequential order, +by simulating the virtual machine. All modifications a chunk effects on the global environment persist after the chunk ends. -Chunks may also be pre-compiled into binary form; +Chunks may also be pre-compiled into binary form and stored in files; see program \IndexVerb{luac} for details. Text files with chunks and their binary pre-compiled forms are interchangeable. @@ -320,7 +323,7 @@ while \emph{string} has the usual meaning. \index{eight-bit clean} Lua is 8-bit clean, and so strings may contain any 8-bit character, -\emph{including} embedded zeros (\verb|'\0'|) \see{lexical}. +including embedded zeros (\verb|'\0'|) \see{lexical}. The \verb|type| function returns a string describing the type of a given value \see{pdf-type}. @@ -329,7 +332,7 @@ This means that functions can be stored in variables, passed as arguments to other functions, and returned as results. Lua can call (and manipulate) functions written in Lua and functions written in C. -The kinds of functions can be distinguished by their tags: +The two kinds of functions can be distinguished by their tags: all Lua functions have the same tag, and all C~functions have the same tag, which is different from the tag of Lua functions. @@ -337,10 +340,10 @@ The \verb|tag| function returns the tag of a given value \see{pdf-tag}. The type \emph{userdata} is provided to allow -arbitrary \Index{C pointers} to be stored in Lua variables. +arbitrary \Index{C~pointers} to be stored in Lua variables. This type corresponds to a \verb|void*| and has no pre-defined operations in Lua, -except for assignment and equality test. +except assignment and equality test. However, by using \emph{tag methods}, the programmer can define operations for \emph{userdata} values \see{tag-method}. @@ -349,7 +352,7 @@ The type \emph{table} implements \Index{associative arrays}, that is, \Index{arrays} that can be indexed not only with numbers, but with any value (except \nil). Therefore, this type may be used not only to represent ordinary arrays, -but also symbol tables, sets, records, etc. +but also symbol tables, sets, records, graphs, trees, etc. Tables are the main data structuring mechanism in Lua. To represent \Index{records}, Lua uses the field name as an index. The language supports this representation by @@ -370,17 +373,17 @@ Moreover, tables must be explicitly created before used Each of the types \M{nil}, \M{number}, and \M{string} has a different tag. All values of each of these types have the same pre-defined tag. -Values of type \M{function} can have two different tags, +As explained above, +values of type \M{function} can have two different tags, depending on whether they are Lua functions or C~functions. Finally, values of type \M{userdata} and \M{table} can have variable tags, assigned by the programmer \see{tag-method}. -The function \verb|tag| returns the tag of a given value. -User tags are created with the function \verb|newtag|, -The function \verb|settag| \see{pdf-newtag} -is used to change the tag of a table. -The data of userdata can only be set from~C. - +The \verb|tag| function returns the tag of a given value. +User tags are created with the function \verb|newtag|. +The \verb|settag| function +is used to change the tag of a table \see{pdf-newtag}. +The tag of userdata values can only be set from~C \see{C-tags}. Tags are mainly used to select \emph{tag methods} when some events occur. Tag methods are the main mechanism for extending the @@ -528,12 +531,11 @@ A block may be explicitly delimited: \begin{Produc} \produc{stat}{\rwd{do} block \rwd{end}} \end{Produc}% -This is useful to control the scope of local variables \see{localvar}, -and to add a \rwd{return} or \rwd{break} statement in the middle -of another block; for instance, -\begin{verbatim} - do return end -- return is the last statement in this block -\end{verbatim} +Explicit blocks are useful +to control the scope of local variables \see{localvar}. +Explicit blocks are also sometimes used to +add a \rwd{return} or \rwd{break} statement in the middle +of another block \see{control}. \subsubsection{\Index{Assignment}} \label{assignment} Lua allows \Index{multiple assignment}. @@ -548,7 +550,7 @@ The elements in both lists are separated by commas: This statement first evaluates all values on the right side and eventual indices on the left side, and then makes the assignments. -So +So, the code \begin{verbatim} i = 3 i, a[i] = 4, 20 @@ -571,6 +573,7 @@ or a formal parameter: \begin{Produc} \produc{var}{name} \end{Produc}% + Square brackets are used to index a table: \begin{Produc} \produc{var}{varorfunc \ter{[} exp1 \ter{]}} @@ -590,18 +593,21 @@ The meaning of assignments and evaluations of global variables and indexed variables can be changed by tag methods \see{tag-method}. Actually, an assignment \verb|x = val|, where \verb|x| is a global variable, -is equivalent to a call \verb|setglobal("x", val)|; +is equivalent to a call \verb|setglobal("x", val)| and an assignment \verb|t[i] = val| is equivalent to \verb|settable_event(t,i,val)|. -See \See{tag-method} for a complete description of these functions. -(The function \verb|setglobal| is defined in the basic library. -The function \T{settable\_event} is used only for explanatory purposes.) +See \See{tag-method} for a complete description of these functions +(\verb|setglobal| is in the basic library; +\T{settable\_event} is used for explanatory purposes only). -\subsubsection{Control Structures} +\subsubsection{Control Structures}\label{control} The control structures -\index{while-do}\index{repeat-until}\index{if-then-else}% -\T{if}, \T{while}, and \T{repeat} have the usual meaning and -familiar syntax: +\rwd{if}, \rwd{while}, and \rwd{repeat} have the usual meaning and +familiar syntax +%(there is also a \rwd{for} statement; see \See{for}): +\index{while-do statement} +\index{repeat-until statement} +\index{if-then-else statement} \begin{Produc} \produc{stat}{\rwd{while} exp1 \rwd{do} block \rwd{end}} \produc{stat}{\rwd{repeat} block \rwd{until} exp1} @@ -613,34 +619,39 @@ The \Index{condition expression} \M{exp1} of a control structure may return any All values different from \nil\ are considered true; only \nil\ is considered false. -\index{return} The \rwd{return} statement is used to return values from a function or from a chunk. -\label{return} +\label{return}% +\index{return statement}% Because functions or chunks may return more than one value, -the syntax for a \Index{return statement} is +the syntax for the \rwd{return} statement is \begin{Produc} \produc{stat}{\rwd{return} \opt{explist1}} \end{Produc}% -\index{break} The \rwd{break} statement can be used to terminate the execution of a loop, skipping to the next statement after the loop: +\index{break statement} \begin{Produc} \produc{stat}{\rwd{break}} \end{Produc}% A \rwd{break} ends the innermost enclosing loop -(while, repeat, or for). +(\rwd{while}, \rwd{repeat}, or \rwd{for}). \NOTE For syntactic reasons, \rwd{return} and \rwd{break} -statements can only be written as the last statements of a block. +statements can only be written as the \emph{last} statements of a block. +If it is really necessary to \rwd{return} or \rwd{break} in the +middle of a block, +an explicit inner block can used, +as in the idiom `\verb|do return end|', +because now \rwd{return} is last statement in the inner block. -\subsubsection{For Statement} \label{for}\index{for} +\subsubsection{For Statement} \label{for}\index{for statement} The \rwd{for} statement has two forms, one for numbers and one for tables. - +\newpage The numerical \rwd{for} loop has the following syntax: \begin{Produc} \produc{stat}{\rwd{for} name \ter{=} exp1 \ter{,} exp1 \opt{\ter{,} exp1} @@ -667,7 +678,7 @@ Note the following: The names are here for explanatory purposes only. \item The behavior is \emph{undefined} if you assign to \verb|var| inside the block. -\item If the third expression (the step) is absent, then a step of 1 is used. +\item If the third expression (the step) is absent, then a step of~1 is used. \item Both the limit and the step are evaluated only once, before the loop starts. \item The variable \verb|var| is local to the statement; @@ -741,7 +752,7 @@ of a multiple assignment. Otherwise, all variables are initialized with \nil. A chunk is also a block, -so local variables can be declared outside any explicit block. +and so local variables can be declared outside any explicit block. The scope of local variables begins \emph{after} the declaration and lasts until the end of the block. @@ -760,9 +771,9 @@ The basic expressions in Lua are \produc{exp}{\rwd{nil}} \produc{exp}{number} \produc{exp}{literal} -\produc{exp}{function} \produc{exp}{var} \produc{exp}{upvalue} +\produc{exp}{function} \produc{exp}{functioncall} \produc{exp}{tableconstructor} \end{Produc}% @@ -771,17 +782,17 @@ Numbers (numerical constants) and literal strings are explained in \See{lexical}; variables are explained in \See{assignment}; upvalues are explained in \See{upvalue}; -function definitions (\M{function}) are explained in \See{func-def}; +function definitions are explained in \See{func-def}; function calls are explained in \See{functioncall}. Table constructors are explained in \See{tableconstructor}. An access to a global variable \verb|x| is equivalent to a -call \verb|getglobal("x")|; +call \verb|getglobal("x")| and an access to an indexed variable \verb|t[i]| is equivalent to a call \verb|gettable_event(t,i)|. -See \See{tag-method} for a description of these functions. -(Function \verb|getglobal| is defined in the basic library. -Function \T{gettable\_event} is used only for explanatory purposes.) +See \See{tag-method} for a description of these functions +(\verb|getglobal| is in the basic library; +\T{gettable\_event} is used for explanatory purposes only). The non-terminal \M{exp1} is used to indicate that the values returned by an expression must be adjusted to one single value: @@ -849,7 +860,7 @@ if it is different from \nil; otherwise, it returns its second argument. Both \verb|and| and \verb|or| use \Index{short-cut evaluation}, that is, -the second operand is evaluated only when necessary. +the second operand is evaluated only if necessary. There are two useful Lua idioms that use logical operators. The first idiom is @@ -907,7 +918,7 @@ tag methods for these operators. Table \Index{constructors} are expressions that create tables; every time a constructor is evaluated, a new table is created. Constructors can be used to create empty tables, -or to create a table and initialize some fields. +or to create a table and initialize some of its fields. The general syntax for constructors is \begin{Produc} \produc{tableconstructor}{\ter{\{} fieldlist \ter{\}}} @@ -922,7 +933,7 @@ The form \emph{lfieldlist1} is used to initialize lists: \produc{lfieldlist1}{exp \rep{\ter{,} exp} \opt{\ter{,}}} \end{Produc}% The expressions in the list are assigned to consecutive numerical indices, -starting with 1. +starting with~1. For example, \begin{verbatim} a = {"v1", "v2", 34} @@ -983,7 +994,8 @@ then this function is called, with the given arguments. Otherwise, the ``function'' tag method is called, having as first parameter the value of \M{varorfunc}, -and then the original call arguments. +and then the original call arguments +\see{tag-method}. The form \begin{Produc} @@ -998,21 +1010,21 @@ Arguments have the following syntax: \begin{Produc} \produc{args}{\ter{(} \opt{explist1} \ter{)}} \produc{args}{tableconstructor} -\produc{args}{\Nter{literal}} +\produc{args}{literal} \produc{explist1}{\rep{exp1 \ter{,}} exp} \end{Produc}% All argument expressions are evaluated before the call. A call of the form \verb|f{...}| is syntactic sugar for \verb|f({...})|, that is, -the parameter list is a single new table. +the argument list is a single new table. A call of the form \verb|f'...'| (or \verb|f"..."| or \verb|f[[...]]|) is syntactic sugar for \verb|f('...')|, that is, -the parameter list is a single literal string. +the argument list is a single literal string. Because a function can return any number of results \see{return}, -the number of results must be adjusted before they are used. +the number of results must be adjusted before they are used \see{adjust}. If the function is called as a statement \see{funcstat}, then its return list is adjusted to~0, thus discarding all returned values. @@ -1025,17 +1037,17 @@ If the function is called in a place that can hold many values then no adjustment is made. The only places that can hold many values is the last (or the only) expression in an assignment, -in an argument list, or in a return statement. +in an argument list, or in the \rwd{return} statement. Here are some examples: \begin{verbatim} - f(); -- adjusted to 0 results - g(f(), x); -- f() is adjusted to 1 result - g(x, f()); -- g gets x plus all values returned by f() - a,b,c = f(), x; -- f() is adjusted to 1 result (and c gets nil) - a,b,c = x, f(); -- f() is adjusted to 2 - a,b,c = f(); -- f() is adjusted to 3 - return f(); -- returns all values returned by f() - return x,y,f(); -- returns a, b, and all values returned by f() + f() -- adjusted to 0 results + g(f(), x) -- f() is adjusted to 1 result + g(x, f()) -- g gets x plus all values returned by f() + a,b,c = f(), x -- f() is adjusted to 1 result (and c gets nil) + a,b,c = x, f() -- f() is adjusted to 2 + a,b,c = f() -- f() is adjusted to 3 + return f() -- returns all values returned by f() + return x,y,f() -- returns a, b, and all values returned by f() \end{verbatim} \subsubsection{\Index{Function Definitions}} \label{func-def} @@ -1050,19 +1062,19 @@ The syntax for function definition is \end{Produc}% The statement \begin{verbatim} - function f () ... end + function f () ... end \end{verbatim} is just syntactic sugar for \begin{verbatim} - f = function () ... end + f = function () ... end \end{verbatim} and the statement \begin{verbatim} - function v.f () ... end + function v.f () ... end \end{verbatim} is syntactic sugar for \begin{verbatim} - v.f = function () ... end + v.f = function () ... end \end{verbatim} A function definition is an executable expression, @@ -1083,19 +1095,19 @@ initialized with the argument values: \produc{parlist1}{\ter{\ldots}} \produc{parlist1}{name \rep{\ter{,} name} \opt{\ter{,} \ter{\ldots}}} \end{Produc}% -\label{vararg} +\label{vararg}% When a function is called, the list of \Index{arguments} is adjusted to the length of the list of parameters \see{adjust}, -unless the function is a \Def{vararg} function, +unless the function is a \Def{vararg function}, which is indicated by three dots (`\verb|...|') at the end of its parameter list. A vararg function does not adjust its argument list; instead, it collects all extra arguments into an implicit parameter, -called \IndexVerb{arg}. +called \IndexLIB{arg}. The value of \verb|arg| is a table, with a field~\verb|n| whose value is the number of extra arguments, -and the extra arguments at positions 1,~2,~\ldots,\M{n}. +and the extra arguments at positions 1,~2,~\ldots,~\verb|n|. As an example, consider the following definitions: \begin{verbatim} @@ -1129,27 +1141,26 @@ The syntax \produc{funcname}{name \ter{:} name} \end{Produc}% is used for defining \IndexEmph{methods}, -that is, functions that have an implicit extra parameter \IndexVerb{self}: -Thus, the statement +that is, functions that have an implicit extra parameter \IndexVerb{self}. + +The statement \begin{verbatim} - function v:f (...) ... end + function v:f (...) ... end \end{verbatim} -is equivalent to +is just syntactic sugar for \begin{verbatim} - v.f = function (self, ...) ... end + v.f = function (self, ...) ... end \end{verbatim} Note that the function gets an extra formal parameter called \verb|self|. -Note also that \verb|v| must have been -previously initialized with a table value. \subsection{Visibility and Upvalues} \label{upvalue} -\index{Visibility} \index{Upvalues} +\index{visibility}\index{upvalues} A function body may refer to its own local variables (which include its parameters) and to global variables, as long as they are not \emph{shadowed} by local -variables from enclosing functions. +variables with the same name from enclosing functions. A function \emph{cannot} access a local variable from an enclosing function, since such variables may no longer exist when the function is called. @@ -1159,13 +1170,15 @@ whose syntax is \begin{Produc} \produc{upvalue}{\ter{\%} name} \end{Produc}% + An upvalue is somewhat similar to a variable expression, but whose value is \emph{frozen} when the function wherein it appears is instantiated. The name used in an upvalue may be the name of any variable visible at the point where the function is defined, that is, -global variables and local variables from the immediately enclosing function. +global variables and local variables +from the \emph{immediately enclosing} function. Note that when the upvalue is a table, only the \emph{reference} to that table (which is the value of the upvalue) is frozen; @@ -1178,7 +1191,7 @@ Here are some examples: a,b,c = 1,2,3 -- global variables local d function f (x) - local b = {} -- x and b are local to f; b shadows the global b + local b = {} -- x and b are local to f; b shadows the global b local g = function (a) local y -- a and y are local to g p = a -- OK, access local `a' @@ -1201,11 +1214,11 @@ Because Lua is an extension language, all Lua actions start from C~code in the host program calling a function from the Lua library. Whenever an error occurs during Lua compilation or execution, -the function \verb|_ERRORMESSAGE| is called \Deffunc{_ERRORMESSAGE} +the function \verb|_ERRORMESSAGE| is called \DefLIB{_ERRORMESSAGE} (provided it is different from \nil), and then the corresponding function from the library (\verb|lua_dofile|, \verb|lua_dostring|, -\verb|lua_dobuffer|, or \verb|lua_callfunction|) +\verb|lua_dobuffer|, or \verb|lua_call|) is terminated, returning an error condition. Memory allocation errors are an exception to the previous rule. @@ -1215,12 +1228,13 @@ So, for this kind of error, Lua does not call the \verb|_ERRORMESSAGE| function; instead, the corresponding function from the library returns immediately with a special error code (\verb|LUA_ERRMEM|). -This and other error codes are defined in \verb|lua.h|. +This and other error codes are defined in \verb|lua.h|; +\See{luado}. The only argument to \verb|_ERRORMESSAGE| is a string describing the error. The default definition for -this function calls \verb|_ALERT|, \Deffunc{_ALERT} +this function calls \verb|_ALERT|, \DefLIB{_ALERT} which prints the message to \verb|stderr| \see{alert}. The standard I/O library redefines \verb|_ERRORMESSAGE| and uses the debug facilities \see{debugI} @@ -1233,26 +1247,26 @@ Lua code can ``catch'' an error using the function \verb|call| \see{pdf-call}. -\subsection{Tag Methods} \label{tag-method} +\subsection{Tag Methods} \label{tag-method}\index{tag method} Lua provides a powerful mechanism to extend its semantics, -called \Def{tag methods}. +called \emph{tag methods}. A tag method is a programmer-defined function -that is called at specific key points during the evaluation of a program, +that is called at specific key points during the execution of a Lua program, allowing the programmer to change the standard Lua behavior at these points. Each of these points is called an \Def{event}. The tag method called for any specific event is selected according to the tag of the values involved in the event \see{TypesSec}. -The function \IndexVerb{settagmethod} changes the tag method +The function \IndexLIB{settagmethod} changes the tag method associated with a given pair \M{(tag, event)}. Its first parameter is the tag, the second parameter is the event name (a string; see below), and the third parameter is the new method (a function), or \nil\ to restore the default behavior for the pair. The \verb|settagmethod| function returns the previous tag method for that pair. -A companion function \IndexVerb{gettagmethod} +A companion function \IndexLIB{gettagmethod} receives a tag and an event name and returns the current method associated with the pair. @@ -1271,7 +1285,7 @@ are described in \See{predefined}. \begin{description} -\item[``add'':]\index{add event} +\item[``add'':]\IndexTM{add} called when a \verb|+| operation is applied to non-numerical operands. The function \verb|getbinmethod| below defines how Lua chooses a tag method @@ -1307,19 +1321,19 @@ the tag method for the ``add'' event is end \end{verbatim} -\item[``sub'':]\index{sub event} +\item[``sub'':]\IndexTM{sub} called when a \verb|-| operation is applied to non-numerical operands. Behavior similar to the ``add'' event. -\item[``mul'':]\index{mul event} +\item[``mul'':]\IndexTM{mul} called when a \verb|*| operation is applied to non-numerical operands. Behavior similar to the ``add'' event. -\item[``div'':]\index{div event} +\item[``div'':]\IndexTM{div} called when a \verb|/| operation is applied to non-numerical operands. Behavior similar to the ``add'' event. -\item[``pow'':]\index{pow event} +\item[``pow'':]\IndexTM{pow} called when a \verb|^| operation (exponentiation) is applied, even for numerical operands. \begin{verbatim} @@ -1335,7 +1349,7 @@ even for numerical operands. end \end{verbatim} -\item[``unm'':]\index{unm event} +\item[``unm'':]\IndexTM{unm} called when a unary \verb|-| operation is applied to a non-numerical operand. \begin{verbatim} function unm_event (op) @@ -1358,7 +1372,7 @@ called when a unary \verb|-| operation is applied to a non-numerical operand. end \end{verbatim} -\item[``lt'':]\index{lt event} +\item[``lt'':]\IndexTM{lt} called when an order operation is applied to non-numerical or non-string operands. It corresponds to the \verb|<| operator. @@ -1386,7 +1400,7 @@ usual equivalences: a>=b <=> not (a