aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 14:37:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 14:37:58 -0200
commitf4d67761f1ee3de81ae720703011f5c03f1bfb47 (patch)
treea8bd8d450b18446f3be3eb9f57cacc4d875822b2
parent369c5fe3c056f80dc29a59a21535d2984c880b24 (diff)
downloadlua-f4d67761f1ee3de81ae720703011f5c03f1bfb47.tar.gz
lua-f4d67761f1ee3de81ae720703011f5c03f1bfb47.tar.bz2
lua-f4d67761f1ee3de81ae720703011f5c03f1bfb47.zip
new section describing the debug interface.
-rw-r--r--manual.tex151
1 files changed, 142 insertions, 9 deletions
diff --git a/manual.tex b/manual.tex
index a3b9309e..e210a039 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.5 1996/02/05 14:52:47 roberto Exp roberto $ 1% $Id: manual.tex,v 1.6 1996/02/05 21:32:19 roberto Exp roberto $
2 2
3\documentstyle[A4,11pt,bnf]{article} 3\documentstyle[A4,11pt,bnf]{article}
4 4
@@ -32,11 +32,10 @@ Waldemar Celes Filho
32Departamento de Inform\'atica --- PUC-Rio 32Departamento de Inform\'atica --- PUC-Rio
33} 33}
34 34
35\date{\small \verb$Date: 1996/02/05 14:52:47 $} 35\date{\small \verb$Date: 1996/02/05 21:32:19 $}
36 36
37\maketitle 37\maketitle
38 38
39
40\begin{abstract} 39\begin{abstract}
41\noindent 40\noindent
42Lua is an extension programming language designed to be used 41Lua is an extension programming language designed to be used
@@ -572,7 +571,7 @@ into the variable \verb'var'.
572Parameters act as local variables, 571Parameters act as local variables,
573initialized with the argument values. 572initialized with the argument values.
574\begin{Produc} 573\begin{Produc}
575\produc{parlist1}{'name' \rep{\ter{,} name}} 574\produc{parlist1}{name \rep{\ter{,} name}}
576\end{Produc} 575\end{Produc}
577 576
578Results are returned using the \verb'return' statement (\see{return}). 577Results are returned using the \verb'return' statement (\see{return}).
@@ -704,11 +703,12 @@ is terminated returning an error condition.
704The only argument to the error fallback function is a string describing 703The only argument to the error fallback function is a string describing
705the error. 704the error.
706The standard I/O library redefines this fallback, 705The standard I/O library redefines this fallback,
707using the debug API, in order to print some extra informations, 706using the debug facilities (\see{debugI},
707in order to print some extra informations,
708like the stack of calls. 708like the stack of calls.
709For more information about an error, 709For more information about an error,
710the Lua program can include the compilation pragma \verb'$debug'. 710the Lua program can include the compilation pragma \verb'$debug'.
711\index{debug pragma} 711\index{debug pragma}\label{pragma}
712This pragma must be written in a line by itself. 712This pragma must be written in a line by itself.
713When an error occurs in a program compiled with this option, 713When an error occurs in a program compiled with this option,
714the error routine is able to print also the lines where the calls 714the error routine is able to print also the lines where the calls
@@ -1454,6 +1454,135 @@ hours ([0-23]), minutes, and seconds.
1454% This function then returns and the execution of the program continues. 1454% This function then returns and the execution of the program continues.
1455 1455
1456 1456
1457
1458\section{The Debuger Interface} \label{debugI}
1459
1460Lua has no built in debuger facilities.
1461Instead, it offers a special interface,
1462by means of functions and {\em hooks},
1463which allows the construction of different
1464kinds of debugers, profiles, and other tools
1465that need ``inside'' information from the interpreter.
1466This interface is declared in the file \verb'luadebug.h'.
1467
1468\subsection{Stack and Function Information}
1469
1470The main function to get information about the interpreter stack
1471is
1472\begin{verbatim}
1473lua_Function lua_stackedfunction (int level);
1474\end{verbatim}
1475It returns a handle (\verb'lua_Function') to the {\em activation record}
1476of the function executing at a given level.
1477Level 0 is the current running function,
1478while level $n+1$ is the function that has called level $n$.
1479When called with a level greater than the stack depth,
1480\verb'lua_stackedfunction' returns \verb'LUA_NOOBJECT'.
1481
1482The type \verb'lua_Function' is just another name
1483to \verb'lua_Object'.
1484Although, in this library,
1485a \verb'lua_Function' can be used wherever a \verb'lua_Object' is required,
1486a parameter \verb'lua_Function' accepts only a handle returned by
1487\verb'lua_stackedfunction'.
1488
1489Three other functions produce extra information about a function:
1490\begin{verbatim}
1491void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
1492int lua_currentline (lua_Function func);
1493char *lua_getobjname (lua_Object o, char **name);
1494\end{verbatim}
1495\verb'lua_funcinfo' gives the file name and the line where the
1496given function has been defined.
1497If the ``function'' is in fact the main code of a chunk,
1498\verb'linedefined' is 0.
1499If the function is a C function,
1500\verb'linedefined' is -1, and \verb'filename' is \verb'"(C)"'.
1501
1502The function \verb'lua_currentline' gives the current line where
1503a given function is executing.
1504It only works if the function has been pre-compiled with debug
1505information (\see{pragma}).
1506When no line information is available, it returns -1.
1507
1508Function \verb'lua_getobjname' tries to find a reasonable name for
1509a given function.
1510Because functions in Lua are first class values,
1511they do not have a fixed name.
1512Some functions may be the value of many global variables,
1513while others may be stored only in a table field.
1514Function \verb'lua_getobjname' first checks whether the given
1515function is a fallback.
1516If so, it returns the string \verb'"fallback"',
1517and \verb'name' is set to point to the fallback name.
1518Otherwise, if the given function is the value of a global variable,
1519\verb'lua_getobjname' returns the string \verb'"global"',
1520while \verb'name' points to the variable name.
1521If the given function is neither a fallback nor a global variable,
1522\verb'lua_getobjname' returns the empty string,
1523and \verb'name' is set to \verb'NULL'.
1524
1525\subsection{Manipulating Local Variables}
1526
1527The following functions allow the manipulation of the
1528local variables of a given activation record.
1529They only work if the function has been pre-compiled with debug
1530information (\see{pragma}).
1531\begin{verbatim}
1532lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
1533int lua_setlocal (lua_Function func, int local_number);
1534\end{verbatim}
1535The first one returns the value of a local variable,
1536and sets \verb'name' to point to the variable name.
1537\verb'local_number' is an index for local variables.
1538The first parameter has index 1, and so on, until the
1539last active local variable.
1540When called with a \verb'local_number' greater than the
1541number of active local variables,
1542or if the activation record has no debug information,
1543\verb'lua_getlocal' returns \verb'LUA_NOOBJECT'.
1544
1545The function \verb'lua_setlocal' sets the local variable
1546\verb'local_number' to the value previously pushed on the stack
1547(\see{valuesCLua}).
1548If the function succeeds it returns 1.
1549If \verb'local_number' is greater than the number
1550of active local variables,
1551or if the activation record has no debug information,
1552this function fails and returns 0.
1553
1554\subsection{Hooks}
1555
1556The Lua interpreter offers two hooks for debug purposes:
1557\begin{verbatim}
1558typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
1559typedef void (*lua_LHFunction) (int line);
1560\end{verbatim}
1561The first one is called whenever the interpreter enters or leaves a
1562function.
1563When entering a function,
1564its parameters are a handle to the function activation record,
1565plus the file and the line where the function is defined (the same
1566information which is provided by \verb'lua_funcinfo');
1567when leaving a function, \verb'func' is \verb'LUA_NOOBJECT',
1568\verb'file' is \verb'"(return)"', and \verb'line' is 0.
1569
1570The other hook is called every time the interpreter changes
1571the line of code it is executing.
1572Its only parameter is the line number
1573(the same information which is provided by the call
1574\verb'lua_currentline(lua_stackedfunction(0))').
1575This second hook is only called if the active function
1576has been pre-compiled with debug information (\see{pragma}).
1577
1578To set these hooks, there are the functions:
1579\begin{verbatim}
1580lua_LHFunction lua_setlinehook (lua_LHFunction hook);
1581lua_CHFunction lua_setcallhook (lua_CHFunction hook);
1582\end{verbatim}
1583Both return the previous hook.
1584
1585
1457\section{Some Examples} 1586\section{Some Examples}
1458 1587
1459This section gives examples showing some features of Lua. 1588This section gives examples showing some features of Lua.
@@ -1473,7 +1602,8 @@ Arrays can be indexed by 0, negative numbers, or any other value (but \nil).
1473Records are also trivially implemented by the syntactic sugar 1602Records are also trivially implemented by the syntactic sugar
1474\verb'a.x'. 1603\verb'a.x'.
1475 1604
1476The best way to implement a set is to use the indices of a table. 1605The best way to implement a set is to store
1606its elements as indices of a table.
1477The statement \verb's = {}' creates an empty set \verb's'. 1607The statement \verb's = {}' creates an empty set \verb's'.
1478The statement \verb's[x] = 1' inserts the value of \verb'x' into 1608The statement \verb's[x] = 1' inserts the value of \verb'x' into
1479the set \verb's'. 1609the set \verb's'.
@@ -1874,8 +2004,8 @@ The authors would like to thank CENPES/PETROBR\'AS which,
1874jointly with TeCGraf, used extensively early versions of 2004jointly with TeCGraf, used extensively early versions of
1875this system and gave valuable comments. 2005this system and gave valuable comments.
1876The authors would also like to thank Carlos Henrique Levy, 2006The authors would also like to thank Carlos Henrique Levy,
1877who found the name of the game% 2007who found the name of the game.
1878\footnote{BTW, Lua means {\em moon} in Portuguese.}. 2008Lua means {\em moon} in Portuguese.
1879 2009
1880 2010
1881 2011
@@ -1945,7 +2075,10 @@ Special care should be taken with macros like
1945\verb'lua_getindexed' and \verb'lua_getfield'. 2075\verb'lua_getindexed' and \verb'lua_getfield'.
1946\end{itemize} 2076\end{itemize}
1947 2077
2078\pagebreak
2079\tableofcontents
1948\newcommand{\indexentry}[2]{\item {#1} #2} 2080\newcommand{\indexentry}[2]{\item {#1} #2}
2081%\catcode`\_=12
1949\begin{theindex} 2082\begin{theindex}
1950\input{manual.idx} 2083\input{manual.idx}
1951\end{theindex} 2084\end{theindex}