aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 15:25:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 15:25:45 -0200
commita907aeeb1e4850cb6509a61bdf6a16bc42d68c4f (patch)
tree8816080c594b975080df3c6becfcb5c092e34199
parent76f62fc5a140170164857a318eabc564fad3de6b (diff)
downloadlua-a907aeeb1e4850cb6509a61bdf6a16bc42d68c4f.tar.gz
lua-a907aeeb1e4850cb6509a61bdf6a16bc42d68c4f.tar.bz2
lua-a907aeeb1e4850cb6509a61bdf6a16bc42d68c4f.zip
general corrections
-rw-r--r--manual.tex179
1 files changed, 90 insertions, 89 deletions
diff --git a/manual.tex b/manual.tex
index cac5d19c..068fd363 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.45 2000/10/31 18:20:01 roberto Exp roberto $ 1% $Id: manual.tex,v 1.47 2000/11/14 18:46:09 roberto Exp roberto $
2 2
3\documentclass[11pt]{article} 3\documentclass[11pt]{article}
4\usepackage{fullpage} 4\usepackage{fullpage}
@@ -134,7 +134,7 @@ Waldemar Celes
134\tecgraf\ --- Computer Science Department --- PUC-Rio 134\tecgraf\ --- Computer Science Department --- PUC-Rio
135} 135}
136 136
137\date{{\small \tt\$Date: 2000/10/31 18:20:01 $ $}} 137\date{{\small \tt\$Date: 2000/11/14 18:46:09 $ $}}
138 138
139\maketitle 139\maketitle
140 140
@@ -332,12 +332,6 @@ This means that functions can be stored in variables,
332passed as arguments to other functions, and returned as results. 332passed as arguments to other functions, and returned as results.
333Lua can call (and manipulate) functions written in Lua and 333Lua can call (and manipulate) functions written in Lua and
334functions written in C. 334functions written in C.
335The two kinds of functions can be distinguished by their tags:
336all Lua functions have the same tag,
337and all C~functions have the same tag,
338which is different from the tag of Lua functions.
339The \verb|tag| function returns the tag
340of a given value \see{pdf-tag}.
341 335
342The type \emph{userdata} is provided to allow 336The type \emph{userdata} is provided to allow
343arbitrary \Index{C~pointers} to be stored in Lua variables. 337arbitrary \Index{C~pointers} to be stored in Lua variables.
@@ -422,8 +416,10 @@ are reserved for internal variables.
422 416
423The following strings denote other \Index{tokens}: 417The following strings denote other \Index{tokens}:
424\begin{verbatim} 418\begin{verbatim}
425 ~= <= >= < > == = + - * / % 419 + - * / ^ %
426 ( ) { } [ ] ; , . .. ... 420 ~= <= >= < > == =
421 ( ) { } [ ]
422 ; : , . .. ...
427\end{verbatim} 423\end{verbatim}
428 424
429\IndexEmph{Literal strings} 425\IndexEmph{Literal strings}
@@ -659,7 +655,7 @@ The numerical \rwd{for} loop has the following syntax:
659\end{Produc}% 655\end{Produc}%
660A \rwd{for} statement like 656A \rwd{for} statement like
661\begin{verbatim} 657\begin{verbatim}
662 for var = e1 ,e2, e3 do block end 658 for var = e1, e2, e3 do block end
663\end{verbatim} 659\end{verbatim}
664is equivalent to the code: 660is equivalent to the code:
665\begin{verbatim} 661\begin{verbatim}
@@ -1568,16 +1564,17 @@ it does not have any global variables.
1568\index{state} 1564\index{state}
1569The whole state of the Lua interpreter 1565The whole state of the Lua interpreter
1570(global variables, stack, tag methods, etc.) 1566(global variables, stack, tag methods, etc.)
1571is stored in a dynamically allocated structure of type \verb|lua_State|; \DefAPI{lua_State} 1567is stored in a dynamically allocated structure of type \verb|lua_State|;
1568\DefAPI{lua_State}
1572this state must be passed as the first argument to 1569this state must be passed as the first argument to
1573every function in the library (except \verb|lua_open| below). 1570every function in the library (except \verb|lua_open| below).
1574 1571
1575Before calling any API function, 1572Before calling any API function,
1576you must create a state by calling 1573you must create a state by calling
1577\DefAPI{lua_open}
1578\begin{verbatim} 1574\begin{verbatim}
1579 lua_State *lua_open (int stacksize); 1575 lua_State *lua_open (int stacksize);
1580\end{verbatim} 1576\end{verbatim}
1577\DefAPI{lua_open}
1581The sole argument to this function is the stack size for the interpreter. 1578The sole argument to this function is the stack size for the interpreter.
1582(Each function call needs one stack position for each argument, local variable, 1579(Each function call needs one stack position for each argument, local variable,
1583and temporary value, plus one position for book-keeping. 1580and temporary value, plus one position for book-keeping.
@@ -1588,10 +1585,10 @@ If \verb|stacksize| is zero,
1588then a default size of~1024 is used. 1585then a default size of~1024 is used.
1589 1586
1590To release a state created with \verb|lua_open|, call 1587To release a state created with \verb|lua_open|, call
1591\DefAPI{lua_close}
1592\begin{verbatim} 1588\begin{verbatim}
1593 void lua_close (lua_State *L); 1589 void lua_close (lua_State *L);
1594\end{verbatim} 1590\end{verbatim}
1591\DefAPI{lua_close}
1595This function destroys all objects in the given Lua environment 1592This function destroys all objects in the given Lua environment
1596(calling the corresponding garbage-collection tag methods, if any) 1593(calling the corresponding garbage-collection tag methods, if any)
1597and frees all dynamic memory used by that state. 1594and frees all dynamic memory used by that state.
@@ -1628,25 +1625,26 @@ index~\Math{-1} also represents the last element
1628(that is, the element at the top), 1625(that is, the element at the top),
1629and index \Math{-n} represents the first element. 1626and index \Math{-n} represents the first element.
1630We say that an index is \emph{valid} 1627We say that an index is \emph{valid}
1631if it lays between~1 and the stack top 1628if it lies between~1 and the stack top
1632(that is, if \verb|1 <= abs(index) <= top|). 1629(that is, if \verb|1 <= abs(index) <= top|).
1633\index{stack index} \index{valid index} 1630\index{stack index} \index{valid index}
1634 1631
1635At any time, you can get the index of the top element by calling 1632At any time, you can get the index of the top element by calling
1636\DefAPI{lua_gettop}
1637\begin{verbatim} 1633\begin{verbatim}
1638 int lua_gettop (lua_State *L); 1634 int lua_gettop (lua_State *L);
1639\end{verbatim} 1635\end{verbatim}
1636\DefAPI{lua_gettop}
1640Because indices start at~1, 1637Because indices start at~1,
1641the result of \verb|lua_gettop| is equal to the number of elements in the stack 1638the result of \verb|lua_gettop| is equal to the number of elements in the stack
1642(and so 0~means an empty stack). 1639(and so 0~means an empty stack).
1643 1640
1644When you interact with Lua API, 1641When you interact with Lua API,
1645\emph{you are responsible for controlling stack overflow}. 1642\emph{you are responsible for controlling stack overflow}.
1646The function \DefAPI{lua_stackspace} 1643The function
1647\begin{verbatim} 1644\begin{verbatim}
1648 int lua_stackspace (lua_State *L); 1645 int lua_stackspace (lua_State *L);
1649\end{verbatim} 1646\end{verbatim}
1647\DefAPI{lua_stackspace}
1650returns the number of stack positions still available. 1648returns the number of stack positions still available.
1651Whenever Lua calls C, \DefAPI{LUA_MINSTACK} 1649Whenever Lua calls C, \DefAPI{LUA_MINSTACK}
1652it ensures that 1650it ensures that
@@ -1667,14 +1665,14 @@ Note that 0 is not an acceptable index.
1667 1665
1668\subsection{Stack Manipulation} 1666\subsection{Stack Manipulation}
1669The API offers the following functions for basic stack manipulation: 1667The API offers the following functions for basic stack manipulation:
1670\DefAPI{lua_settop}\DefAPI{lua_pushvalue}
1671\DefAPI{lua_remove}\DefAPI{lua_insert}
1672\begin{verbatim} 1668\begin{verbatim}
1673 void lua_settop (lua_State *L, int index); 1669 void lua_settop (lua_State *L, int index);
1674 void lua_pushvalue (lua_State *L, int index); 1670 void lua_pushvalue (lua_State *L, int index);
1675 void lua_remove (lua_State *L, int index); 1671 void lua_remove (lua_State *L, int index);
1676 void lua_insert (lua_State *L, int index); 1672 void lua_insert (lua_State *L, int index);
1677\end{verbatim} 1673\end{verbatim}
1674\DefAPI{lua_settop}\DefAPI{lua_pushvalue}
1675\DefAPI{lua_remove}\DefAPI{lua_insert}
1678 1676
1679\verb|lua_settop| accepts any acceptable index, 1677\verb|lua_settop| accepts any acceptable index,
1680or 0, 1678or 0,
@@ -1686,6 +1684,7 @@ A useful macro defined in the API is
1686\begin{verbatim} 1684\begin{verbatim}
1687 #define lua_pop(L,n) lua_settop(L, -(n)-1) 1685 #define lua_pop(L,n) lua_settop(L, -(n)-1)
1688\end{verbatim} 1686\end{verbatim}
1687\DefAPI{lua_pop}
1689which pops \verb|n| elements from the stack. 1688which pops \verb|n| elements from the stack.
1690 1689
1691\verb|lua_pushvalue| pushes onto the stack a \emph{copy} of the element 1690\verb|lua_pushvalue| pushes onto the stack a \emph{copy} of the element
@@ -1714,10 +1713,6 @@ then
1714 1713
1715To check the type of a stack element, 1714To check the type of a stack element,
1716the following functions are available: 1715the following functions are available:
1717\DefAPI{lua_type}\DefAPI{lua_tag}
1718\DefAPI{lua_isnil}\DefAPI{lua_isnumber}\DefAPI{lua_isstring}
1719\DefAPI{lua_istable}
1720\DefAPI{lua_isfunction}\DefAPI{lua_iscfunction}\DefAPI{lua_isuserdata}
1721\begin{verbatim} 1716\begin{verbatim}
1722 int lua_type (lua_State *L, int index); 1717 int lua_type (lua_State *L, int index);
1723 int lua_tag (lua_State *L, int index); 1718 int lua_tag (lua_State *L, int index);
@@ -1729,7 +1724,13 @@ the following functions are available:
1729 int lua_iscfunction (lua_State *L, int index); 1724 int lua_iscfunction (lua_State *L, int index);
1730 int lua_isuserdata (lua_State *L, int index); 1725 int lua_isuserdata (lua_State *L, int index);
1731\end{verbatim} 1726\end{verbatim}
1727\DefAPI{lua_type}\DefAPI{lua_tag}
1728\DefAPI{lua_isnil}\DefAPI{lua_isnumber}\DefAPI{lua_isstring}
1729\DefAPI{lua_istable}
1730\DefAPI{lua_isfunction}\DefAPI{lua_iscfunction}\DefAPI{lua_isuserdata}
1732These functions can be called with any acceptable index. 1731These functions can be called with any acceptable index.
1732The \verb|lua_isnumber| function may have a side effect of changing the
1733actual value in the stack from a string to a number.
1733 1734
1734\verb|lua_type| returns one of the following constants, 1735\verb|lua_type| returns one of the following constants,
1735according to the type of the given object: 1736according to the type of the given object:
@@ -1743,10 +1744,10 @@ If the index is non-valid
1743(that is, if that stack position is ``empty''), 1744(that is, if that stack position is ``empty''),
1744then \verb|lua_type| returns \verb|LUA_TNONE|. 1745then \verb|lua_type| returns \verb|LUA_TNONE|.
1745These constants can be converted to strings with 1746These constants can be converted to strings with
1746\DefAPI{lua_typename}
1747\begin{verbatim} 1747\begin{verbatim}
1748 const char *lua_typename (lua_State *L, int t); 1748 const char *lua_typename (lua_State *L, int t);
1749\end{verbatim} 1749\end{verbatim}
1750\DefAPI{lua_typename}
1750where \verb|t| is a type returned by \verb|lua_type|. 1751where \verb|t| is a type returned by \verb|lua_type|.
1751The strings returned by \verb|lua_typename| are 1752The strings returned by \verb|lua_typename| are
1752\verb|"nil"|, \verb|"number"|, \verb|"string"|, \verb|"table"|, 1753\verb|"nil"|, \verb|"number"|, \verb|"string"|, \verb|"table"|,
@@ -1754,6 +1755,8 @@ The strings returned by \verb|lua_typename| are
1754 1755
1755\verb|lua_tag| returns the tag of a value, 1756\verb|lua_tag| returns the tag of a value,
1756or \verb|LUA_NOTAG| for a non-valid index. 1757or \verb|LUA_NOTAG| for a non-valid index.
1758The default tag value for all types is equal to the value
1759returned by \verb|lua_type|.
1757 1760
1758The \verb|lua_is*| functions return~1 if the object is compatible 1761The \verb|lua_is*| functions return~1 if the object is compatible
1759with the given type, and 0 otherwise. 1762with the given type, and 0 otherwise.
@@ -1767,12 +1770,11 @@ To distinguish between numbers and numerical strings,
1767you can use \verb|lua_type|. 1770you can use \verb|lua_type|.
1768 1771
1769The API also has functions to compare two values in the stack: 1772The API also has functions to compare two values in the stack:
1770\DefAPI{lua_equal}
1771\DefAPI{lua_lessthan}
1772\begin{verbatim} 1773\begin{verbatim}
1773 int lua_equal (lua_State *L, int index1, int index2); 1774 int lua_equal (lua_State *L, int index1, int index2);
1774 int lua_lessthan (lua_State *L, int index1, int index2); 1775 int lua_lessthan (lua_State *L, int index1, int index2);
1775\end{verbatim} 1776\end{verbatim}
1777\DefAPI{lua_equal} \DefAPI{lua_lessthan}
1776These functions are equivalent to their counterparts in Lua. 1778These functions are equivalent to their counterparts in Lua.
1777Specifically, \verb|lua_lessthan| is equivalent to the \verb|lt_event| 1779Specifically, \verb|lua_lessthan| is equivalent to the \verb|lt_event|
1778described in \See{tag-method}. 1780described in \See{tag-method}.
@@ -1780,8 +1782,6 @@ Both functions return 0 if any of the indices are non-valid.
1780 1782
1781To translate a value in the stack to a specific C~type, 1783To translate a value in the stack to a specific C~type,
1782you can use the following conversion functions: 1784you can use the following conversion functions:
1783\DefAPI{lua_tonumber}\DefAPI{lua_tostring}\DefAPI{lua_strlen}
1784\DefAPI{lua_tocfunction}\DefAPI{lua_touserdata}
1785\begin{verbatim} 1785\begin{verbatim}
1786 double lua_tonumber (lua_State *L, int index); 1786 double lua_tonumber (lua_State *L, int index);
1787 const char *lua_tostring (lua_State *L, int index); 1787 const char *lua_tostring (lua_State *L, int index);
@@ -1789,6 +1789,8 @@ you can use the following conversion functions:
1789 lua_CFunction lua_tocfunction (lua_State *L, int index); 1789 lua_CFunction lua_tocfunction (lua_State *L, int index);
1790 void *lua_touserdata (lua_State *L, int index); 1790 void *lua_touserdata (lua_State *L, int index);
1791\end{verbatim} 1791\end{verbatim}
1792\DefAPI{lua_tonumber}\DefAPI{lua_tostring}\DefAPI{lua_strlen}
1793\DefAPI{lua_tocfunction}\DefAPI{lua_touserdata}
1792These functions can be called with any acceptable index. 1794These functions can be called with any acceptable index.
1793When called with a non-valid index, 1795When called with a non-valid index,
1794they act as if the given value had an incorrect type. 1796they act as if the given value had an incorrect type.
@@ -1797,13 +1799,20 @@ they act as if the given value had an incorrect type.
1797to a floating-point number. 1799to a floating-point number.
1798This value must be a number or a string convertible to number 1800This value must be a number or a string convertible to number
1799\see{coercion}; otherwise, \verb|lua_tonumber| returns~0. 1801\see{coercion}; otherwise, \verb|lua_tonumber| returns~0.
1802If the value is a string,
1803\verb|lua_tonumber| also changes the
1804actual value in the stack to a number.
1800 1805
1801\verb|lua_tostring| converts a Lua value to a string 1806\verb|lua_tostring| converts a Lua value to a string
1802(\verb|const char*|). 1807(\verb|const char*|).
1803This value must be a string or a number; 1808This value must be a string or a number;
1804otherwise, the function returns \verb|NULL|. 1809otherwise, the function returns \verb|NULL|.
1810If the value is a number,
1811\verb|lua_tostring| also changes the
1812actual value in the stack to a string.
1805This function returns a pointer to a string inside the Lua environment. 1813This function returns a pointer to a string inside the Lua environment.
1806Those strings always have a zero (\verb|'\0'|) after their last character (as in C), 1814Those strings always have a zero (\verb|'\0'|)
1815after their last character (as in C),
1807but may contain other zeros in their body. 1816but may contain other zeros in their body.
1808If you do not know whether a string may contain zeros, 1817If you do not know whether a string may contain zeros,
1809you should use \verb|lua_strlen| to get its actual length. 1818you should use \verb|lua_strlen| to get its actual length.
@@ -1826,9 +1835,6 @@ otherwise, \verb|lua_touserdata| returns \verb|NULL|.
1826 1835
1827The API has the following functions to 1836The API has the following functions to
1828push C~values onto the stack: 1837push C~values onto the stack:
1829\DefAPI{lua_pushnumber}\DefAPI{lua_pushlstring}\DefAPI{lua_pushstring}
1830\DefAPI{lua_pushcfunction}\DefAPI{lua_pushusertag}
1831\DefAPI{lua_pushnil}\DefAPI{lua_pushuserdata}\label{pushing}
1832\begin{verbatim} 1838\begin{verbatim}
1833 void lua_pushnumber (lua_State *L, double n); 1839 void lua_pushnumber (lua_State *L, double n);
1834 void lua_pushlstring (lua_State *L, const char *s, size_t len); 1840 void lua_pushlstring (lua_State *L, const char *s, size_t len);
@@ -1837,6 +1843,9 @@ push C~values onto the stack:
1837 void lua_pushnil (lua_State *L); 1843 void lua_pushnil (lua_State *L);
1838 void lua_pushcfunction (lua_State *L, lua_CFunction f); 1844 void lua_pushcfunction (lua_State *L, lua_CFunction f);
1839\end{verbatim} 1845\end{verbatim}
1846\DefAPI{lua_pushnumber}\DefAPI{lua_pushlstring}\DefAPI{lua_pushstring}
1847\DefAPI{lua_pushcfunction}\DefAPI{lua_pushusertag}
1848\DefAPI{lua_pushnil}\DefAPI{lua_pushuserdata}\label{pushing}
1840These functions receive a C~value, 1849These functions receive a C~value,
1841convert it to a corresponding Lua value, 1850convert it to a corresponding Lua value,
1842and push the result onto the stack. 1851and push the result onto the stack.
@@ -1853,8 +1862,6 @@ which accepts an explicit size.
1853Lua uses two numbers to control its garbage collection. 1862Lua uses two numbers to control its garbage collection.
1854One number counts how many bytes of dynamic memory Lua is using, 1863One number counts how many bytes of dynamic memory Lua is using,
1855and the other is a threshold. 1864and the other is a threshold.
1856(This internal byte counter kept by Lua is not completely acurate;
1857it is just a lower bound, usually within~10\% of the correct value.)
1858When the number of bytes crosses the threshold, 1865When the number of bytes crosses the threshold,
1859Lua runs a garbage-collection cycle, 1866Lua runs a garbage-collection cycle,
1860which reclaims the memory of all ``dead'' objects 1867which reclaims the memory of all ``dead'' objects
@@ -1864,17 +1871,17 @@ and then the threshold is reset to twice the value of the byte counter.
1864 1871
1865You can access the current values of these two numbers through the 1872You can access the current values of these two numbers through the
1866following functions: 1873following functions:
1867\DefAPI{lua_getgcthreshold} \DefAPI{lua_getgccount}
1868\begin{verbatim} 1874\begin{verbatim}
1869 int lua_getgccount (lua_State *L); 1875 int lua_getgccount (lua_State *L);
1870 int lua_getgcthreshold (lua_State *L); 1876 int lua_getgcthreshold (lua_State *L);
1871\end{verbatim} 1877\end{verbatim}
1878\DefAPI{lua_getgcthreshold} \DefAPI{lua_getgccount}
1872Both return their respective values in Kbytes. 1879Both return their respective values in Kbytes.
1873You can change the threshold value with 1880You can change the threshold value with
1874\DefAPI{lua_setgcthreshold}
1875\begin{verbatim} 1881\begin{verbatim}
1876 void lua_setgcthreshold (lua_State *L, int newthreshold); 1882 void lua_setgcthreshold (lua_State *L, int newthreshold);
1877\end{verbatim} 1883\end{verbatim}
1884\DefAPI{lua_setgcthreshold}
1878Again, the \verb|newthreshold| value is given in Kbytes. 1885Again, the \verb|newthreshold| value is given in Kbytes.
1879When you call this function, 1886When you call this function,
1880Lua sets the new threshold and checks it against the byte counter. 1887Lua sets the new threshold and checks it against the byte counter.
@@ -1883,7 +1890,7 @@ then Lua immediately runs the garbage collector;
1883after the collection, 1890after the collection,
1884a new threshold is set according to the previous rule. 1891a new threshold is set according to the previous rule.
1885 1892
1886If you want to change the adaptative behavior of the garbage collector, 1893If you want to change the adaptive behavior of the garbage collector,
1887you can use the garbage-collection tag method for \nil\ % 1894you can use the garbage-collection tag method for \nil\ %
1888to set your own threshold 1895to set your own threshold
1889(the tag method is called after Lua resets the threshold). 1896(the tag method is called after Lua resets the threshold).
@@ -1906,29 +1913,29 @@ with tag equal to 0.
1906Userdata can have different tags, 1913Userdata can have different tags,
1907whose semantics are only known to the host program. 1914whose semantics are only known to the host program.
1908Tags are created with the function 1915Tags are created with the function
1909\DefAPI{lua_newtag}
1910\begin{verbatim} 1916\begin{verbatim}
1911 int lua_newtag (lua_State *L); 1917 int lua_newtag (lua_State *L);
1912\end{verbatim} 1918\end{verbatim}
1919\DefAPI{lua_newtag}
1913The function \verb|lua_settag| changes the tag of 1920The function \verb|lua_settag| changes the tag of
1914the object on top of the stack (without popping it): 1921the object on top of the stack (without popping it):
1915\DefAPI{lua_settag}
1916\begin{verbatim} 1922\begin{verbatim}
1917 void lua_settag (lua_State *L, int tag); 1923 void lua_settag (lua_State *L, int tag);
1918\end{verbatim} 1924\end{verbatim}
1925\DefAPI{lua_settag}
1919The object must be a userdata or a table; 1926The object must be a userdata or a table;
1920the given \verb|tag| must be a value created with \verb|lua_newtag|. 1927the given \verb|tag| must be a value created with \verb|lua_newtag|.
1921 1928
1922\subsection{Executing Lua Code}\label{luado} 1929\subsection{Executing Lua Code}\label{luado}
1923A host program can execute Lua chunks written in a file or in a string 1930A host program can execute Lua chunks written in a file or in a string
1924by using the following functions:% 1931by using the following functions:%
1925\DefAPI{lua_dofile}\DefAPI{lua_dostring}\DefAPI{lua_dobuffer}%
1926\begin{verbatim} 1932\begin{verbatim}
1927 int lua_dofile (lua_State *L, const char *filename); 1933 int lua_dofile (lua_State *L, const char *filename);
1928 int lua_dostring (lua_State *L, const char *string); 1934 int lua_dostring (lua_State *L, const char *string);
1929 int lua_dobuffer (lua_State *L, const char *buff, 1935 int lua_dobuffer (lua_State *L, const char *buff,
1930 size_t size, const char *name); 1936 size_t size, const char *name);
1931\end{verbatim} 1937\end{verbatim}
1938\DefAPI{lua_dofile}\DefAPI{lua_dostring}\DefAPI{lua_dobuffer}%
1932These functions return 1939These functions return
19330 in case of success, or one of the following error codes if they fail: 19400 in case of success, or one of the following error codes if they fail:
1934\begin{itemize} 1941\begin{itemize}
@@ -1994,10 +2001,10 @@ leaving the stack as it was before the call:
1994 2001
1995To read the value of a global Lua variable, 2002To read the value of a global Lua variable,
1996you call 2003you call
1997\DefAPI{lua_getglobal}
1998\begin{verbatim} 2004\begin{verbatim}
1999 void lua_getglobal (lua_State *L, const char *varname); 2005 void lua_getglobal (lua_State *L, const char *varname);
2000\end{verbatim} 2006\end{verbatim}
2007\DefAPI{lua_getglobal}
2001which pushes onto the stack the value of the given variable. 2008which pushes onto the stack the value of the given variable.
2002As in Lua, this function may trigger a tag method 2009As in Lua, this function may trigger a tag method
2003for the ``getglobal'' event \see{tag-method}. 2010for the ``getglobal'' event \see{tag-method}.
@@ -2008,10 +2015,10 @@ use \verb|lua_rawget| over the table of globals
2008 2015
2009To store a value in a global variable, 2016To store a value in a global variable,
2010you call 2017you call
2011\DefAPI{lua_setglobal}
2012\begin{verbatim} 2018\begin{verbatim}
2013 void lua_setglobal (lua_State *L, const char *varname); 2019 void lua_setglobal (lua_State *L, const char *varname);
2014\end{verbatim} 2020\end{verbatim}
2021\DefAPI{lua_setglobal}
2015which pops from the stack the value to be stored in the given variable. 2022which pops from the stack the value to be stored in the given variable.
2016As in Lua, this function may trigger a tag method 2023As in Lua, this function may trigger a tag method
2017for the ``setglobal'' event \see{tag-method}. 2024for the ``setglobal'' event \see{tag-method}.
@@ -2022,30 +2029,27 @@ use \verb|lua_rawset| over the table of globals
2022 2029
2023All global variables are kept in an ordinary Lua table. 2030All global variables are kept in an ordinary Lua table.
2024You can get this table calling 2031You can get this table calling
2025\DefAPI{lua_getglobals}
2026\begin{verbatim} 2032\begin{verbatim}
2027 void lua_getglobals (lua_State *L); 2033 void lua_getglobals (lua_State *L);
2028\end{verbatim} 2034\end{verbatim}
2035\DefAPI{lua_getglobals}
2029which pushes the current table of globals onto the stack. 2036which pushes the current table of globals onto the stack.
2030To set another table as the table of globals, 2037To set another table as the table of globals,
2031you call 2038you call
2032\DefAPI{lua_setglobals}
2033\begin{verbatim} 2039\begin{verbatim}
2034 void lua_setglobals (lua_State *L); 2040 void lua_setglobals (lua_State *L);
2035\end{verbatim} 2041\end{verbatim}
2042\DefAPI{lua_setglobals}
2036The table to be used is popped from the stack. 2043The table to be used is popped from the stack.
2037 2044
2038\subsection{Manipulating Tables in Lua} 2045\subsection{Manipulating Tables in Lua}
2039Lua tables can also be manipulated through the API. 2046Lua tables can also be manipulated through the API.
2040 2047
2041To read the value of in a table, 2048To read a value from a table, call
2042the table must reside somewhere in the stack.
2043With this set,
2044you call
2045\DefAPI{lua_gettable}
2046\begin{verbatim} 2049\begin{verbatim}
2047 void lua_gettable (lua_State *L, int index); 2050 void lua_gettable (lua_State *L, int index);
2048\end{verbatim} 2051\end{verbatim}
2052\DefAPI{lua_gettable}
2049where \verb|index| refers to the table. 2053where \verb|index| refers to the table.
2050\verb|lua_gettable| pops a key from the stack, 2054\verb|lua_gettable| pops a key from the stack,
2051and returns (on the stack) the contents of the table at that key. 2055and returns (on the stack) the contents of the table at that key.
@@ -2054,19 +2058,19 @@ for the ``gettable'' event.
2054To get the real value of any table key, 2058To get the real value of any table key,
2055without invoking any tag method, 2059without invoking any tag method,
2056use the \emph{raw} version: 2060use the \emph{raw} version:
2057\DefAPI{lua_rawget}
2058\begin{verbatim} 2061\begin{verbatim}
2059 void lua_rawget (lua_State *L, int index); 2062 void lua_rawget (lua_State *L, int index);
2060\end{verbatim} 2063\end{verbatim}
2064\DefAPI{lua_rawget}
2061 2065
2062To store a value into a table that resides somewhere in the stack, 2066To store a value into a table that resides somewhere in the stack,
2063you push the key and the value onto the stack 2067you push the key and the value onto the stack
2064(in this order), 2068(in this order),
2065and then call 2069and then call
2066\DefAPI{lua_settable}
2067\begin{verbatim} 2070\begin{verbatim}
2068 void lua_settable (lua_State *L, int index); 2071 void lua_settable (lua_State *L, int index);
2069\end{verbatim} 2072\end{verbatim}
2073\DefAPI{lua_settable}
2070where \verb|index| refers to the table. 2074where \verb|index| refers to the table.
2071\verb|lua_settable| pops from the stack both the key and the value. 2075\verb|lua_settable| pops from the stack both the key and the value.
2072As in Lua, this operation may trigger a tag method 2076As in Lua, this operation may trigger a tag method
@@ -2074,30 +2078,30 @@ for the ``settable'' event.
2074To set the real value of any table index, 2078To set the real value of any table index,
2075without invoking any tag method, 2079without invoking any tag method,
2076use the \emph{raw} version: 2080use the \emph{raw} version:
2077\DefAPI{lua_rawset}
2078\begin{verbatim} 2081\begin{verbatim}
2079 void lua_rawset (lua_State *L, int index); 2082 void lua_rawset (lua_State *L, int index);
2080\end{verbatim} 2083\end{verbatim}
2084\DefAPI{lua_rawset}
2081 2085
2082Finally, the function 2086Finally, the function
2083\DefAPI{lua_newtable}
2084\begin{verbatim} 2087\begin{verbatim}
2085 void lua_newtable (lua_State *L); 2088 void lua_newtable (lua_State *L);
2086\end{verbatim} 2089\end{verbatim}
2090\DefAPI{lua_newtable}
2087creates a new, empty table and pushes it onto the stack. 2091creates a new, empty table and pushes it onto the stack.
2088 2092
2089\subsection{Using Tables as Arrays} 2093\subsection{Using Tables as Arrays}
2090The API has functions that help to use Lua tables as arrays, 2094The API has functions that help to use Lua tables as arrays,
2091that is, 2095that is,
2092tables indexed by numbers only: 2096tables indexed by numbers only:
2093\DefAPI{lua_rawgeti}
2094\DefAPI{lua_rawseti}
2095\DefAPI{lua_getn}
2096\begin{verbatim} 2097\begin{verbatim}
2097 void lua_rawgeti (lua_State *L, int index, int n); 2098 void lua_rawgeti (lua_State *L, int index, int n);
2098 void lua_rawseti (lua_State *L, int index, int n); 2099 void lua_rawseti (lua_State *L, int index, int n);
2099 int lua_getn (lua_State *L, int index); 2100 int lua_getn (lua_State *L, int index);
2100\end{verbatim} 2101\end{verbatim}
2102\DefAPI{lua_rawgeti}
2103\DefAPI{lua_rawseti}
2104\DefAPI{lua_getn}
2101 2105
2102\verb|lua_rawgeti| gets the value of the \M{n}-th element of the table 2106\verb|lua_rawgeti| gets the value of the \M{n}-th element of the table
2103at stack position \verb|index|. 2107at stack position \verb|index|.
@@ -2122,19 +2126,19 @@ First, the function to be called is pushed onto the stack;
2122then, the arguments to the function are pushed 2126then, the arguments to the function are pushed
2123\see{pushing} in \emph{direct order}, that is, the first argument is pushed first. 2127\see{pushing} in \emph{direct order}, that is, the first argument is pushed first.
2124Finally, the function is called using 2128Finally, the function is called using
2125\DefAPI{lua_call}
2126\begin{verbatim} 2129\begin{verbatim}
2127 int lua_call (lua_State *L, int nargs, int nresults); 2130 int lua_call (lua_State *L, int nargs, int nresults);
2128\end{verbatim} 2131\end{verbatim}
2132\DefAPI{lua_call}
2129This function returns the same error codes as \verb|lua_dostring| and 2133This function returns the same error codes as \verb|lua_dostring| and
2130friends \see{luado}. 2134friends \see{luado}.
2131If you want to propagate the error, 2135If you want to propagate the error,
2132instead of returning an error code, 2136instead of returning an error code,
2133use 2137use
2134\DefAPI{lua_rawcall}
2135\begin{verbatim} 2138\begin{verbatim}
2136 void lua_rawcall (lua_State *L, int nargs, int nresults); 2139 void lua_rawcall (lua_State *L, int nargs, int nresults);
2137\end{verbatim} 2140\end{verbatim}
2141\DefAPI{lua_rawcall}
2138 2142
2139In both functions, 2143In both functions,
2140\verb|nargs| is the number of arguments that you pushed onto the stack. 2144\verb|nargs| is the number of arguments that you pushed onto the stack.
@@ -2174,10 +2178,10 @@ This is considered good programming practice.
2174 2178
2175Some special Lua functions have their own C~interfaces. 2179Some special Lua functions have their own C~interfaces.
2176The host program can generate a Lua error calling the function 2180The host program can generate a Lua error calling the function
2177\DefAPI{lua_error}
2178\begin{verbatim} 2181\begin{verbatim}
2179 void lua_error (lua_State *L, const char *message); 2182 void lua_error (lua_State *L, const char *message);
2180\end{verbatim} 2183\end{verbatim}
2184\DefAPI{lua_error}
2181This function never returns. 2185This function never returns.
2182If \verb|lua_error| is called from a C~function that has been called from Lua, 2186If \verb|lua_error| is called from a C~function that has been called from Lua,
2183then the corresponding Lua execution terminates, 2187then the corresponding Lua execution terminates,
@@ -2192,32 +2196,36 @@ then \verb|_ERRORMESSAGE| is not called.
2192 2196
2193\medskip 2197\medskip
2194 2198
2195Tag methods can be changed with \DefAPI{lua_settagmethod} 2199Tag methods can be changed with
2196\begin{verbatim} 2200\begin{verbatim}
2197 void lua_settagmethod (lua_State *L, int tag, const char *event); 2201 void lua_settagmethod (lua_State *L, int tag, const char *event);
2198\end{verbatim} 2202\end{verbatim}
2203\DefAPI{lua_settagmethod}
2199The second parameter is the tag, 2204The second parameter is the tag,
2200and the third is the event name \see{tag-method}; 2205and the third is the event name \see{tag-method};
2201the new method is popped from the stack. 2206the new method is popped from the stack.
2202To get the current value of a tag method, 2207To get the current value of a tag method,
2203use the function \DefAPI{lua_gettagmethod} 2208use the function
2204\begin{verbatim} 2209\begin{verbatim}
2205 void lua_gettagmethod (lua_State *L, int tag, const char *event); 2210 void lua_gettagmethod (lua_State *L, int tag, const char *event);
2206\end{verbatim} 2211\end{verbatim}
2212\DefAPI{lua_gettagmethod}
2207 2213
2208It is also possible to copy all tag methods from one tag 2214It is also possible to copy all tag methods from one tag
2209to another: \DefAPI{lua_copytagmethods} 2215to another:
2210\begin{verbatim} 2216\begin{verbatim}
2211 int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); 2217 int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
2212\end{verbatim} 2218\end{verbatim}
2219\DefAPI{lua_copytagmethods}
2213This function returns \verb|tagto|. 2220This function returns \verb|tagto|.
2214 2221
2215\medskip 2222\medskip
2216 2223
2217You can traverse a table with the function \DefAPI{lua_next} 2224You can traverse a table with the function
2218\begin{verbatim} 2225\begin{verbatim}
2219 int lua_next (lua_State *L, int index); 2226 int lua_next (lua_State *L, int index);
2220\end{verbatim} 2227\end{verbatim}
2228\DefAPI{lua_next}
2221where \verb|index| refers to the table to be traversed. 2229where \verb|index| refers to the table to be traversed.
2222The function pops a key from the stack, 2230The function pops a key from the stack,
2223and pushes a key-value pair from the table 2231and pushes a key-value pair from the table
@@ -2236,10 +2244,11 @@ A typical traversal looks like this:
2236 } 2244 }
2237\end{verbatim} 2245\end{verbatim}
2238 2246
2239The function \DefAPI{lua_concat} 2247The function
2240\begin{verbatim} 2248\begin{verbatim}
2241 void lua_concat (lua_State *L, int n); 2249 void lua_concat (lua_State *L, int n);
2242\end{verbatim} 2250\end{verbatim}
2251\DefAPI{lua_concat}
2243concatenates the \verb|n| values at the top of the stack, 2252concatenates the \verb|n| values at the top of the stack,
2244pops them, and leaves the result at the top; 2253pops them, and leaves the result at the top;
2245\verb|n|~must be at least 2. 2254\verb|n|~must be at least 2.
@@ -2250,20 +2259,20 @@ Concatenation is done following the usual semantics of Lua
2250\subsection{Defining C Functions} \label{LuacallC} 2259\subsection{Defining C Functions} \label{LuacallC}
2251To register a C~function to Lua, 2260To register a C~function to Lua,
2252there is the following convenience macro: 2261there is the following convenience macro:
2253\DefAPI{lua_register}
2254\begin{verbatim} 2262\begin{verbatim}
2255 #define lua_register(L, n, f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) 2263 #define lua_register(L, n, f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
2256 /* const char *n; */ 2264 /* const char *n; */
2257 /* lua_CFunction f; */ 2265 /* lua_CFunction f; */
2258\end{verbatim} 2266\end{verbatim}
2267\DefAPI{lua_register}
2259which receives the name the function will have in Lua, 2268which receives the name the function will have in Lua,
2260and a pointer to the function. 2269and a pointer to the function.
2261This pointer must have type \verb|lua_CFunction|, 2270This pointer must have type \verb|lua_CFunction|,
2262which is defined as 2271which is defined as
2263\DefAPI{lua_CFunction}
2264\begin{verbatim} 2272\begin{verbatim}
2265 typedef int (*lua_CFunction) (lua_State *L); 2273 typedef int (*lua_CFunction) (lua_State *L);
2266\end{verbatim} 2274\end{verbatim}
2275\DefAPI{lua_CFunction}
2267that is, a pointer to a function with integer result and a single argument, 2276that is, a pointer to a function with integer result and a single argument,
2268a Lua environment. 2277a Lua environment.
2269 2278
@@ -2309,10 +2318,11 @@ these values are passed to the function whenever it is called,
2309as ordinary arguments. 2318as ordinary arguments.
2310To associate upvalues to a C~function, 2319To associate upvalues to a C~function,
2311first these values should be pushed onto the stack. 2320first these values should be pushed onto the stack.
2312Then the function \DefAPI{lua_pushcclosure} 2321Then the function
2313\begin{verbatim} 2322\begin{verbatim}
2314 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); 2323 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
2315\end{verbatim} 2324\end{verbatim}
2325\DefAPI{lua_pushcclosure}
2316is used to push the C~function onto the stack, 2326is used to push the C~function onto the stack,
2317with the argument \verb|n| telling how many upvalues should be 2327with the argument \verb|n| telling how many upvalues should be
2318associated with the function 2328associated with the function
@@ -2337,13 +2347,12 @@ If the C~code needs to keep a Lua value
2337outside the life span of a C~function, 2347outside the life span of a C~function,
2338then it must create a \Def{reference} to the value. 2348then it must create a \Def{reference} to the value.
2339The functions to manipulate references are the following: 2349The functions to manipulate references are the following:
2340\DefAPI{lua_ref}\DefAPI{lua_getref}
2341\DefAPI{lua_unref}
2342\begin{verbatim} 2350\begin{verbatim}
2343 int lua_ref (lua_State *L, int lock); 2351 int lua_ref (lua_State *L, int lock);
2344 int lua_getref (lua_State *L, int ref); 2352 int lua_getref (lua_State *L, int ref);
2345 void lua_unref (lua_State *L, int ref); 2353 void lua_unref (lua_State *L, int ref);
2346\end{verbatim} 2354\end{verbatim}
2355\DefAPI{lua_ref}\DefAPI{lua_getref}\DefAPI{lua_unref}
2347 2356
2348\verb|lua_ref| pops a value from 2357\verb|lua_ref| pops a value from
2349the stack, creates a reference to it, 2358the stack, creates a reference to it,
@@ -2371,10 +2380,11 @@ it should be released with a call to \verb|lua_unref|.
2371 2380
2372When Lua starts, it registers a table at position 2381When Lua starts, it registers a table at position
2373\IndexAPI{LUA_REFREGISTRY}. 2382\IndexAPI{LUA_REFREGISTRY}.
2374It can be accessed through the macro\DefAPI{lua_getregistry} 2383It can be accessed through the macro
2375\begin{verbatim} 2384\begin{verbatim}
2376 #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY) 2385 #define lua_getregistry(L) lua_getref(L, LUA_REFREGISTRY)
2377\end{verbatim} 2386\end{verbatim}
2387\DefAPI{lua_getregistry}
2378This table can be used by C~libraries as a general registry mechanism. 2388This table can be used by C~libraries as a general registry mechanism.
2379Any C~library can store data into this table, 2389Any C~library can store data into this table,
2380as long as it chooses a key different from other libraries. 2390as long as it chooses a key different from other libraries.
@@ -2710,7 +2720,7 @@ use function \verb|format|.
2710 2720
2711 2721
2712 2722
2713\subsubsection*{\ff \T{tinsert (table [, pos] , value)}}\DefLIB{tinsert} 2723\subsubsection*{\ff \T{tinsert (table, [pos,] value)}}\DefLIB{tinsert}
2714 2724
2715Inserts element \verb|value| at table position \verb|pos|, 2725Inserts element \verb|value| at table position \verb|pos|,
2716shifting other elements to open space, if necessary. 2726shifting other elements to open space, if necessary.
@@ -2788,7 +2798,7 @@ such as finding and extracting substrings and pattern matching.
2788When indexing a string in Lua, the first character is at position~1 2798When indexing a string in Lua, the first character is at position~1
2789(not at~0, as in C). 2799(not at~0, as in C).
2790Also, 2800Also,
2791indices are allowed to be negative and are intepreted as indexing backwards, 2801indices are allowed to be negative and are interpreted as indexing backwards,
2792from the end of the string. Thus, the last character is at position \Math{-1}, 2802from the end of the string. Thus, the last character is at position \Math{-1},
2793and so on. 2803and so on.
2794 2804
@@ -2888,16 +2898,6 @@ will produce the string:
2888 new line" 2898 new line"
2889\end{verbatim} 2899\end{verbatim}
2890 2900
2891Conversions can be applied to the \M{n}-th argument in the argument list,
2892rather than the next unused argument.
2893In this case, the conversion character \verb|%| is replaced
2894by the sequence \verb|%d$|, where \verb|d| is a
2895decimal digit in the range [1,9],
2896giving the position of the argument in the argument list.
2897For instance, the call \verb|format("%2$d -> %1$03d", 1, 34)| will
2898result in \verb|"34 -> 001"|.
2899The same argument can be used in more than one conversion.
2900
2901The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|, 2901The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|,
2902\verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all 2902\verb|g|, \verb|G|, \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all
2903expect a number as argument, 2903expect a number as argument,
@@ -3220,7 +3220,7 @@ usually limited and depends on the system.
3220 3220
3221\subsubsection*{\ff \T{appendto (filename)}}\DefLIB{appendto} 3221\subsubsection*{\ff \T{appendto (filename)}}\DefLIB{appendto}
3222 3222
3223Opens a file named \verb|filename| and sets it as the 3223Opens a file named \verb|filename| and sets its handle as the
3224value of \verb|_OUTPUT|. 3224value of \verb|_OUTPUT|.
3225Unlike the \verb|writeto| operation, 3225Unlike the \verb|writeto| operation,
3226this function does not erase any previous contents of the file; 3226this function does not erase any previous contents of the file;
@@ -3377,11 +3377,11 @@ This interface is declared in \verb|luadebug.h|.
3377 3377
3378\subsection{Stack and Function Information} 3378\subsection{Stack and Function Information}
3379 3379
3380\DefAPI{lua_getstack}
3381The main function to get information about the interpreter stack is 3380The main function to get information about the interpreter stack is
3382\begin{verbatim} 3381\begin{verbatim}
3383 int lua_getstack (lua_State *L, int level, lua_Debug *ar); 3382 int lua_getstack (lua_State *L, int level, lua_Debug *ar);
3384\end{verbatim} 3383\end{verbatim}
3384\DefAPI{lua_getstack}
3385It fills parts of a \verb|lua_Debug| structure with 3385It fills parts of a \verb|lua_Debug| structure with
3386an identification of the \emph{activation record} 3386an identification of the \emph{activation record}
3387of the function executing at a given level. 3387of the function executing at a given level.
@@ -3391,7 +3391,6 @@ Usually, \verb|lua_getstack| returns 1;
3391when called with a level greater than the stack depth, 3391when called with a level greater than the stack depth,
3392it returns 0. 3392it returns 0.
3393 3393
3394\DefAPI{lua_Debug}
3395The structure \verb|lua_Debug| is used to carry different pieces of 3394The structure \verb|lua_Debug| is used to carry different pieces of
3396information about an active function: 3395information about an active function:
3397\begin{verbatim} 3396\begin{verbatim}
@@ -3410,13 +3409,15 @@ information about an active function:
3410 ... 3409 ...
3411 } lua_Debug; 3410 } lua_Debug;
3412\end{verbatim} 3411\end{verbatim}
3412\DefAPI{lua_Debug}
3413\verb|lua_getstack| fills only the private part 3413\verb|lua_getstack| fills only the private part
3414of this structure, for future use. 3414of this structure, for future use.
3415To fill in the other fields of \verb|lua_Debug| with useful information, 3415To fill in the other fields of \verb|lua_Debug| with useful information,
3416call \DefAPI{lua_getinfo} 3416call
3417\begin{verbatim} 3417\begin{verbatim}
3418 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 3418 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
3419\end{verbatim} 3419\end{verbatim}
3420\DefAPI{lua_getinfo}
3420This function returns 0 on error 3421This function returns 0 on error
3421(e.g., an invalid option in \verb|what|). 3422(e.g., an invalid option in \verb|what|).
3422Each character in the string \verb|what| 3423Each character in the string \verb|what|
@@ -3500,13 +3501,13 @@ For the manipulation of local variables,
3500The first parameter or local variable has index~1, and so on, 3501The first parameter or local variable has index~1, and so on,
3501until the last active local variable. 3502until the last active local variable.
3502 3503
3503\DefAPI{lua_getlocal}\DefAPI{lua_setlocal}
3504The following functions allow the manipulation of the 3504The following functions allow the manipulation of the
3505local variables of a given activation record. 3505local variables of a given activation record.
3506\begin{verbatim} 3506\begin{verbatim}
3507 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); 3507 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
3508 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); 3508 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
3509\end{verbatim} 3509\end{verbatim}
3510\DefAPI{lua_getlocal}\DefAPI{lua_setlocal}
3510The parameter \verb|ar| must be a valid activation record, 3511The parameter \verb|ar| must be a valid activation record,
3511filled by a previous call to \verb|lua_getstack| or 3512filled by a previous call to \verb|lua_getstack| or
3512given as argument to a hook \see{sub-hooks}. 3513given as argument to a hook \see{sub-hooks}.
@@ -3543,16 +3544,16 @@ local variables for a function at a given level of the stack:
3543The Lua interpreter offers two hooks for debugging purposes: 3544The Lua interpreter offers two hooks for debugging purposes:
3544a \emph{call} hook and a \emph{line} hook. 3545a \emph{call} hook and a \emph{line} hook.
3545Both have the same type, 3546Both have the same type,
3546\DefAPI{lua_Hook}
3547\begin{verbatim} 3547\begin{verbatim}
3548 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 3548 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
3549\end{verbatim} 3549\end{verbatim}
3550\DefAPI{lua_Hook}
3550and you can set them with the following functions: 3551and you can set them with the following functions:
3551\DefAPI{lua_setcallhook}\DefAPI{lua_setlinehook}
3552\begin{verbatim} 3552\begin{verbatim}
3553 lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); 3553 lua_Hook lua_setcallhook (lua_State *L, lua_Hook func);
3554 lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); 3554 lua_Hook lua_setlinehook (lua_State *L, lua_Hook func);
3555\end{verbatim} 3555\end{verbatim}
3556\DefAPI{lua_setcallhook}\DefAPI{lua_setlinehook}
3556A hook is disabled when its value is \verb|NULL|, 3557A hook is disabled when its value is \verb|NULL|,
3557which is the initial value of both hooks. 3558which is the initial value of both hooks.
3558The functions \verb|lua_setcallhook| and \verb|lua_setlinehook| 3559The functions \verb|lua_setcallhook| and \verb|lua_setlinehook|