diff options
Diffstat (limited to 'manual.tex')
-rw-r--r-- | manual.tex | 99 |
1 files changed, 47 insertions, 52 deletions
@@ -1,8 +1,10 @@ | |||
1 | % $Id: manual.tex,v 1.16 1998/06/19 18:47:06 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.17 1998/06/29 18:09:28 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentclass[11pt]{article} | 3 | \documentclass[11pt]{article} |
4 | \usepackage{fullpage,bnf} | 4 | \usepackage{fullpage,bnf} |
5 | 5 | ||
6 | \catcode`\_=12 | ||
7 | |||
6 | \newcommand{\See}[1]{Section~\ref{#1}} | 8 | \newcommand{\See}[1]{Section~\ref{#1}} |
7 | \newcommand{\see}[1]{(see \See{#1})} | 9 | \newcommand{\see}[1]{(see \See{#1})} |
8 | \newcommand{\M}[1]{\emph{#1}} | 10 | \newcommand{\M}[1]{\emph{#1}} |
@@ -19,7 +21,7 @@ | |||
19 | 21 | ||
20 | \newcommand{\ff}{$\bullet$\ } | 22 | \newcommand{\ff}{$\bullet$\ } |
21 | 23 | ||
22 | \newcommand{\Version}{3.1} | 24 | \newcommand{\Version}{3.2 (alpha)} |
23 | 25 | ||
24 | \makeindex | 26 | \makeindex |
25 | 27 | ||
@@ -39,7 +41,7 @@ Waldemar Celes | |||
39 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 41 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
40 | } | 42 | } |
41 | 43 | ||
42 | %\date{\small \verb$Date: 1998/06/19 18:47:06 $} | 44 | %\date{\small \verb$Date: 1998/06/29 18:09:28 $} |
43 | 45 | ||
44 | \maketitle | 46 | \maketitle |
45 | 47 | ||
@@ -810,7 +812,7 @@ If the function is called in a place that can hold many values | |||
810 | (syntactically denoted by the non-terminal \M{exp}), | 812 | (syntactically denoted by the non-terminal \M{exp}), |
811 | then no adjustment is made. | 813 | then no adjustment is made. |
812 | Note that the only place that can hold many values | 814 | Note that the only place that can hold many values |
813 | is the last expression (or the only one) in an assignment | 815 | is the last (or the only) expression in an assignment |
814 | or in a return statement; see examples below. | 816 | or in a return statement; see examples below. |
815 | \begin{verbatim} | 817 | \begin{verbatim} |
816 | f(); -- adjusted to 0 | 818 | f(); -- adjusted to 0 |
@@ -1263,22 +1265,20 @@ Because Lua is an extension language, | |||
1263 | all Lua actions start from C code in the host program | 1265 | all Lua actions start from C code in the host program |
1264 | calling a function from the Lua library. | 1266 | calling a function from the Lua library. |
1265 | Whenever an error occurs during Lua compilation or execution, | 1267 | Whenever an error occurs during Lua compilation or execution, |
1266 | the \Def{error method} is called, | 1268 | function \verb|_ERRORMESSAGE| is called \Deffunc{_ERRORMESSAGE} |
1269 | (provided it is different from \nil), | ||
1267 | and then the corresponding function from the library | 1270 | and then the corresponding function from the library |
1268 | (\verb|lua_dofile|, \verb|lua_dostring|, | 1271 | (\verb|lua_dofile|, \verb|lua_dostring|, |
1269 | \verb|lua_dobuffer|, or \verb|lua_callfunction|) | 1272 | \verb|lua_dobuffer|, or \verb|lua_callfunction|) |
1270 | is terminated, returning an error condition. | 1273 | is terminated, returning an error condition. |
1271 | 1274 | ||
1272 | The only argument to the error method is a string | 1275 | The only argument to \verb|_ERRORMESSAGE| is a string |
1273 | describing the error. | 1276 | describing the error. |
1274 | The default method prints this message to \verb|stderr|. | 1277 | The default definition for this function calls \verb|_ALERT|, |
1275 | If needed, it is possible to change the error method with the | 1278 | which prints the message to \verb|stderr| \see{alert}. |
1276 | function \verb|seterrormethod|, | 1279 | The standard I/O library redefines \verb|_ERRORMESSAGE|, |
1277 | which gets the new error handler as its only parameter | 1280 | and uses the debug facilities \see{debugI} |
1278 | \see{pdf-seterrormethod}. | 1281 | to print some extra information, |
1279 | The standard I/O library uses this facility to redefine the error method, | ||
1280 | using the debug facilities \see{debugI}, | ||
1281 | in order to print some extra information, | ||
1282 | such as the call stack. | 1282 | such as the call stack. |
1283 | 1283 | ||
1284 | To provide more information about errors, | 1284 | To provide more information about errors, |
@@ -1347,11 +1347,11 @@ For that, you must set \verb|lua_state| back to \verb|NULL| before | |||
1347 | calling \verb|lua_open|. | 1347 | calling \verb|lua_open|. |
1348 | An easy way to do that is defining an auxiliary function: | 1348 | An easy way to do that is defining an auxiliary function: |
1349 | \begin{verbatim} | 1349 | \begin{verbatim} |
1350 | lua_State *lua_newstate (void) { | 1350 | lua_State *lua_newstate (void) { |
1351 | lua_State *old = lua_setstate(NULL); | 1351 | lua_State *old = lua_setstate(NULL); |
1352 | lua_open(); | 1352 | lua_open(); |
1353 | return lua_setstate(old); | 1353 | return lua_setstate(old); |
1354 | } | 1354 | } |
1355 | \end{verbatim} | 1355 | \end{verbatim} |
1356 | This function creates a new state without changing the current state | 1356 | This function creates a new state without changing the current state |
1357 | of the interpreter. | 1357 | of the interpreter. |
@@ -1373,14 +1373,14 @@ If \verb|lua_state| is already \verb|NULL|, | |||
1373 | \verb|lua_close| has no effect. | 1373 | \verb|lua_close| has no effect. |
1374 | 1374 | ||
1375 | If you are using multiple states, | 1375 | If you are using multiple states, |
1376 | you may find useful the following function, | 1376 | you may find useful to define the following function, |
1377 | which releases a given state: | 1377 | which releases a given state: |
1378 | \begin{verbatim} | 1378 | \begin{verbatim} |
1379 | void lua_freestate (lua_State *st) { | 1379 | void lua_freestate (lua_State *st) { |
1380 | lua_State *old = lua_setstate(st); | 1380 | lua_State *old = lua_setstate(st); |
1381 | lua_close(); | 1381 | lua_close(); |
1382 | if (old != st) lua_setstate(old); | 1382 | if (old != st) lua_setstate(old); |
1383 | } | 1383 | } |
1384 | \end{verbatim} | 1384 | \end{verbatim} |
1385 | 1385 | ||
1386 | \subsection{Exchanging Values between C and Lua} \label{valuesCLua} | 1386 | \subsection{Exchanging Values between C and Lua} \label{valuesCLua} |
@@ -1736,18 +1736,10 @@ If the C function has been called from Lua, | |||
1736 | then the corresponding Lua execution terminates, | 1736 | then the corresponding Lua execution terminates, |
1737 | as if an error had occurred inside Lua code. | 1737 | as if an error had occurred inside Lua code. |
1738 | Otherwise, the whole program terminates with a call to \verb|exit(1)|. | 1738 | Otherwise, the whole program terminates with a call to \verb|exit(1)|. |
1739 | The \verb|message| is passed to the error handler method. | 1739 | The \verb|message| is passed to the error handler function, |
1740 | \verb|_ERRORMESSAGE|. | ||
1740 | If \verb|message| is \verb|NULL|, | 1741 | If \verb|message| is \verb|NULL|, |
1741 | the error handler method is not called. | 1742 | \verb|_ERRORMESSAGE| is not called. |
1742 | |||
1743 | The error handler method \see{error} can be | ||
1744 | changed with: \Deffunc{lua_seterrormethod} | ||
1745 | \begin{verbatim} | ||
1746 | lua_Object lua_seterrormethod (void); | ||
1747 | \end{verbatim} | ||
1748 | This function sets the object at the top of C2lua | ||
1749 | as the new error method, | ||
1750 | and returns the old error method value. | ||
1751 | 1743 | ||
1752 | Tag methods can be changed with: \Deffunc{lua_settagmethod} | 1744 | Tag methods can be changed with: \Deffunc{lua_settagmethod} |
1753 | \begin{verbatim} | 1745 | \begin{verbatim} |
@@ -1885,7 +1877,7 @@ and \verb|lua_iolibopen|, declared in \verb|lualib.h|. | |||
1885 | 1877 | ||
1886 | \subsection{Predefined Functions} \label{predefined} | 1878 | \subsection{Predefined Functions} \label{predefined} |
1887 | 1879 | ||
1888 | \subsubsection*{\ff \T{call (func, arg [, mode [, errmethod]])}}\Deffunc{call} | 1880 | \subsubsection*{\ff \T{call (func, arg [, mode [, errhandler]])}}\Deffunc{call} |
1889 | \label{pdf-call} | 1881 | \label{pdf-call} |
1890 | This function calls function \verb|func| with | 1882 | This function calls function \verb|func| with |
1891 | the arguments given by the table \verb|arg|. | 1883 | the arguments given by the table \verb|arg|. |
@@ -1917,14 +1909,15 @@ if an error occurs during the function call, | |||
1917 | the error is propagated. | 1909 | the error is propagated. |
1918 | If the string \verb|mode| contains \verb|"x"|, | 1910 | If the string \verb|mode| contains \verb|"x"|, |
1919 | then the call is \emph{protected}.\index{protected calls} | 1911 | then the call is \emph{protected}.\index{protected calls} |
1920 | In this mode, function \verb|call| does not generate an error, | 1912 | In this mode, function \verb|call| does not propagate an error, |
1921 | whatever happens during the call. | 1913 | whatever happens during the call. |
1922 | Instead, it returns \nil\ to signal the error | 1914 | Instead, it returns \nil\ to signal the error |
1923 | (besides calling the appropriated error method). | 1915 | (besides calling the appropriated error handler). |
1924 | 1916 | ||
1925 | If provided, \verb|errmethod| is temporarily set as the error method, | 1917 | If provided, |
1926 | while \verb|func| runs. | 1918 | \verb|errhandler| is temporarily set as the error function |
1927 | As a particular case, if \verb|errmethod| is \nil, | 1919 | \verb|_ERRORMESSAGE|, while \verb|func| runs. |
1920 | As a particular example, if \verb|errhandler| is \nil, | ||
1928 | no error messages will be issued during the execution of the called function. | 1921 | no error messages will be issued during the execution of the called function. |
1929 | 1922 | ||
1930 | \subsubsection*{\ff \T{collectgarbage ([limit])}}\Deffunc{collectgarbage} | 1923 | \subsubsection*{\ff \T{collectgarbage ([limit])}}\Deffunc{collectgarbage} |
@@ -2055,9 +2048,16 @@ This function receives any number of arguments, | |||
2055 | and prints their values using the strings returned by \verb|tostring|. | 2048 | and prints their values using the strings returned by \verb|tostring|. |
2056 | This function is not intended for formatted output, | 2049 | This function is not intended for formatted output, |
2057 | but only as a quick way to show a value, | 2050 | but only as a quick way to show a value, |
2058 | for instance for error messages or debugging. | 2051 | for instance for debugging. |
2059 | See \See{libio} for functions for formatted output. | 2052 | See \See{libio} for functions for formatted output. |
2060 | 2053 | ||
2054 | \subsubsection*{\ff \T{_ALERT (message)}}\Deffunc{alert}\label{alert} | ||
2055 | This function prints its only string argument to \IndexVerb{stderr}. | ||
2056 | All error messages in Lua are printed through this function. | ||
2057 | Therefore, a program may redefine it | ||
2058 | to change the way such messages are shown | ||
2059 | (for instance, for systems without \verb|stderr|). | ||
2060 | |||
2061 | \subsubsection*{\ff \T{tonumber (e [, base])}}\Deffunc{tonumber} | 2061 | \subsubsection*{\ff \T{tonumber (e [, base])}}\Deffunc{tonumber} |
2062 | This function receives one argument, | 2062 | This function receives one argument, |
2063 | and tries to convert it to a number. | 2063 | and tries to convert it to a number. |
@@ -2164,13 +2164,6 @@ Its full semantics is explained in \See{tag-method}. | |||
2164 | The string \verb|name| does not need to be a | 2164 | The string \verb|name| does not need to be a |
2165 | syntactically valid variable name. | 2165 | syntactically valid variable name. |
2166 | 2166 | ||
2167 | \subsubsection*{\ff \T{seterrormethod (newmethod)}} | ||
2168 | \label{pdf-seterrormethod} | ||
2169 | Sets the error handler \see{error}. | ||
2170 | \verb|newmethod| must be a function or \nil, | ||
2171 | in which case the error handler does nothing. | ||
2172 | Returns the old error handler. | ||
2173 | |||
2174 | \subsubsection*{\ff \T{settagmethod (tag, event, newmethod)}} | 2167 | \subsubsection*{\ff \T{settagmethod (tag, event, newmethod)}} |
2175 | \Deffunc{settagmethod} | 2168 | \Deffunc{settagmethod} |
2176 | This function sets a new tag method to the given pair \M{(tag, event)}. | 2169 | This function sets a new tag method to the given pair \M{(tag, event)}. |
@@ -2930,7 +2923,7 @@ so any existing program that opens at least one standard | |||
2930 | library before calling Lua does not need to be modified. | 2923 | library before calling Lua does not need to be modified. |
2931 | 2924 | ||
2932 | \item Function \verb|dostring| no longer accepts an optional second argument, | 2925 | \item Function \verb|dostring| no longer accepts an optional second argument, |
2933 | with a temporary error method. | 2926 | with a temporary error handler. |
2934 | This facility is now provided by function \verb|call|. | 2927 | This facility is now provided by function \verb|call|. |
2935 | 2928 | ||
2936 | \item Function \verb|gsub| no longer accepts an optional fourth argument | 2929 | \item Function \verb|gsub| no longer accepts an optional fourth argument |
@@ -2951,8 +2944,10 @@ programs should use an explicit assignment instead, such as | |||
2951 | 2944 | ||
2952 | \end{itemize} | 2945 | \end{itemize} |
2953 | 2946 | ||
2947 | % restore underscore to usual meaning | ||
2948 | \catcode`\_=8 | ||
2949 | |||
2954 | \newcommand{\indexentry}[2]{\item {#1} #2} | 2950 | \newcommand{\indexentry}[2]{\item {#1} #2} |
2955 | %\catcode`\_=12 | ||
2956 | \begin{theindex} | 2951 | \begin{theindex} |
2957 | \input{manual.id} | 2952 | \input{manual.id} |
2958 | \end{theindex} | 2953 | \end{theindex} |