aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manual.tex82
1 files changed, 44 insertions, 38 deletions
diff --git a/manual.tex b/manual.tex
index f0fb75df..3784b4ea 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.34 1999/10/04 17:51:04 roberto Exp roberto $ 1% $Id: manual.tex,v 1.35 2000/04/14 17:47:55 roberto Exp roberto $
2 2
3\documentclass[11pt]{article} 3\documentclass[11pt]{article}
4\usepackage{fullpage,bnf} 4\usepackage{fullpage,bnf}
@@ -41,7 +41,7 @@ Waldemar Celes
41\tecgraf\ --- Computer Science Department --- PUC-Rio 41\tecgraf\ --- Computer Science Department --- PUC-Rio
42} 42}
43 43
44\date{{\small \tt\$Date: 1999/10/04 17:51:04 $ $}} 44\date{{\small \tt\$Date: 2000/04/14 17:47:55 $ $}}
45 45
46\maketitle 46\maketitle
47 47
@@ -456,7 +456,7 @@ and can be optionally followed by a semicolon:
456\begin{Produc} 456\begin{Produc}
457\produc{block}{\opt{label} \rep{stat sc}} 457\produc{block}{\opt{label} \rep{stat sc}}
458\produc{sc}{\opt{\ter{;}}} 458\produc{sc}{\opt{\ter{;}}}
459\produc{label}{\ter{|} name \ter{|}} 459\produc{label}{\ter{$\vert$} name \ter{$\vert$}}
460\end{Produc}% 460\end{Produc}%
461For syntactic reasons, \rwd{return} and 461For syntactic reasons, \rwd{return} and
462\rwd{break} statements can only be written 462\rwd{break} statements can only be written
@@ -680,7 +680,7 @@ giving the expected meaning to \Index{exponentiation}
680\subsubsection{Relational Operators} 680\subsubsection{Relational Operators}
681Lua provides the following \Index{relational operators}: 681Lua provides the following \Index{relational operators}:
682\begin{verbatim} 682\begin{verbatim}
683 < > <= >= ~= == 683 == ~= < > <= >=
684\end{verbatim} 684\end{verbatim}
685All these return \nil\ as false and a value different from \nil\ as true. 685All these return \nil\ as false and a value different from \nil\ as true.
686 686
@@ -698,7 +698,7 @@ Thus, \verb|"0"==0| evaluates to false,
698and \verb|t[0]| and \verb|t["0"]| denote different 698and \verb|t[0]| and \verb|t["0"]| denote different
699entries in a table. 699entries in a table.
700 700
701The other operators work as follows. 701The order operators work as follows.
702If both arguments are numbers, then they are compared as such. 702If both arguments are numbers, then they are compared as such.
703Otherwise, if both arguments are strings, 703Otherwise, if both arguments are strings,
704then their values are compared using lexicographical order. 704then their values are compared using lexicographical order.
@@ -1311,10 +1311,8 @@ called when Lua tries to call a non function value.
1311 else 1311 else
1312 local tm = gettagmethod(tag(func), "function") 1312 local tm = gettagmethod(tag(func), "function")
1313 if tm then 1313 if tm then
1314 local i = arg.n 1314 for i=arg.n,1,-1 do
1315 while i > 0 do
1316 arg[i+1] = arg[i] 1315 arg[i+1] = arg[i]
1317 i = i-1
1318 end 1316 end
1319 arg.n = arg.n+1 1317 arg.n = arg.n+1
1320 arg[1] = func 1318 arg[1] = func
@@ -1430,7 +1428,7 @@ Currently, the function accepts the following options:
1430\item \verb|"stack"| - the stack size. 1428\item \verb|"stack"| - the stack size.
1431Each function call needs one stack position for each local variable 1429Each function call needs one stack position for each local variable
1432and temporary variables, plus one position. 1430and temporary variables, plus one position.
1433The stack must also have at least ten positions available. 1431The stack must also have at least ten extra positions available.
1434For very small implementations, without recursive functions, 1432For very small implementations, without recursive functions,
1435a size of 100 should be enough. 1433a size of 100 should be enough.
1436The default is 1K. 1434The default is 1K.
@@ -1459,7 +1457,7 @@ void lua_close (lua_State *L);
1459This function destroys all objects in the current Lua environment 1457This function destroys all objects in the current Lua environment
1460(calling the correspondent garbage collector tag methods), 1458(calling the correspondent garbage collector tag methods),
1461and frees all dynamic memory used by the state. 1459and frees all dynamic memory used by the state.
1462Frequently, you do not need to call this function, 1460Usually, you do not need to call this function,
1463because these resources are naturally released when the program ends. 1461because these resources are naturally released when the program ends.
1464 1462
1465With the exception of \verb|lua_newstate|, 1463With the exception of \verb|lua_newstate|,
@@ -1470,6 +1468,9 @@ functions, and also to keep compatibility with old versions of Lua,
1470the API provides a set of macros and one global variable that 1468the API provides a set of macros and one global variable that
1471take care of this state argument for single-state applications: 1469take care of this state argument for single-state applications:
1472\begin{verbatim} 1470\begin{verbatim}
1471#ifndef LUA_REENTRANT
1472\end{verbatim}
1473\begin{verbatim}
1473extern lua_State *lua_state; 1474extern lua_State *lua_state;
1474\end{verbatim} 1475\end{verbatim}
1475\begin{verbatim} 1476\begin{verbatim}
@@ -1478,9 +1479,12 @@ extern lua_State *lua_state;
1478#define lua_dostring(str) (lua_dostring)(lua_state, str) 1479#define lua_dostring(str) (lua_dostring)(lua_state, str)
1479 ... 1480 ...
1480\end{verbatim} 1481\end{verbatim}
1482\begin{verbatim}
1483#endif
1484\end{verbatim}
1481For each function in the API, there is a macro with the same name 1485For each function in the API, there is a macro with the same name
1482that supplies \verb|lua_state| as the first argument to the call. 1486that supplies \verb|lua_state| as the first argument to the call.
1483(The parentheses around the function name is to avoid it being expanded 1487(The parentheses around the function name avoid it being expanded
1484again as a macro.) 1488again as a macro.)
1485The only exception is \verb|lua_newstate|; 1489The only exception is \verb|lua_newstate|;
1486in this case, the corresponding macro is 1490in this case, the corresponding macro is
@@ -1488,7 +1492,7 @@ in this case, the corresponding macro is
1488#define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0)))) 1492#define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0))))
1489\end{verbatim} 1493\end{verbatim}
1490It checks whether the global state has been initialized; 1494It checks whether the global state has been initialized;
1491if not, it then creates a new state with default settings and 1495if not, it creates a new state with default settings and
1492assigns it to \verb|lua_newstate|. 1496assigns it to \verb|lua_newstate|.
1493 1497
1494By default, those macros are all active. 1498By default, those macros are all active.
@@ -2030,8 +2034,11 @@ void lua_unref (int ref);
2030The function \verb|lua_ref| creates a reference 2034The function \verb|lua_ref| creates a reference
2031to the object that is on the top of the stack, 2035to the object that is on the top of the stack,
2032and returns this reference. 2036and returns this reference.
2033For a \nil{} object, the reference is always -1; 2037For a \nil{} object,
2038the reference is always \verb|LUA_REFNIL|;\Deffunc{LUA_REFNIL}
2034otherwise, it is a non-negative integer. 2039otherwise, it is a non-negative integer.
2040The constant \verb|LUA_NOREF| \Deffunc{LUA_NOREF}
2041is different from any valid reference.
2035If \verb|lock| is true, the object is \emph{locked}: 2042If \verb|lock| is true, the object is \emph{locked}:
2036this means the object will not be garbage collected. 2043this means the object will not be garbage collected.
2037Note that an unlocked reference may be garbage collected. 2044Note that an unlocked reference may be garbage collected.
@@ -2347,11 +2354,11 @@ This function could be defined in Lua:
2347\begin{verbatim} 2354\begin{verbatim}
2348 function getn (t) 2355 function getn (t)
2349 if type(t.n) == 'number' then return t.n end 2356 if type(t.n) == 'number' then return t.n end
2350 local max = 0 2357 local max, i = 0, nil
2351 local i = next(t, nil) 2358 while 1 do
2352 while i do
2353 if type(i) == 'number' and i>max then max=i end
2354 i = next(t, i) 2359 i = next(t, i)
2360 if not i then break end
2361 if type(i) == 'number' and i>max then max=i end
2355 end 2362 end
2356 return max 2363 return max
2357 end 2364 end
@@ -2369,11 +2376,12 @@ as the final value of \verb|foreach|.
2369This function could be defined in Lua: 2376This function could be defined in Lua:
2370\begin{verbatim} 2377\begin{verbatim}
2371 function foreach (t, f) 2378 function foreach (t, f)
2372 local i, v = next(t, nil) 2379 local i, v = nil
2373 while i do 2380 while 1 do
2381 i, v = next(t, i)
2382 if not i then break end
2374 local res = f(i, v) 2383 local res = f(i, v)
2375 if res then return res end 2384 if res then return res end
2376 i, v = next(t, i)
2377 end 2385 end
2378 end 2386 end
2379\end{verbatim} 2387\end{verbatim}
@@ -2398,11 +2406,9 @@ as the final value of \verb|foreachi|.
2398This function could be defined in Lua: 2406This function could be defined in Lua:
2399\begin{verbatim} 2407\begin{verbatim}
2400 function foreachi (t, f) 2408 function foreachi (t, f)
2401 local i, n = 1, getn(t) 2409 for i=1,getn(t) do
2402 while i <= n do
2403 local res = f(i, t[i]) 2410 local res = f(i, t[i])
2404 if res then return res end 2411 if res then return res end
2405 i = i+1
2406 end 2412 end
2407 end 2413 end
2408\end{verbatim} 2414\end{verbatim}
@@ -2418,11 +2424,12 @@ as the final value of \verb|foreachvar|.
2418This function could be defined in Lua: 2424This function could be defined in Lua:
2419\begin{verbatim} 2425\begin{verbatim}
2420 function foreachvar (f) 2426 function foreachvar (f)
2421 local n, v = nextvar(nil) 2427 local n, v = nil
2422 while n do 2428 while 1 do
2429 n, v = nextvar(n)
2430 if not n then break end
2423 local res = f(n, v) 2431 local res = f(n, v)
2424 if res then return res end 2432 if res then return res end
2425 n, v = nextvar(n)
2426 end 2433 end
2427 end 2434 end
2428\end{verbatim} 2435\end{verbatim}
@@ -2454,9 +2461,8 @@ except that the table accesses are all raw (that is, without tag methods):
2454 pos, value = arg[1], arg[2] 2461 pos, value = arg[1], arg[2]
2455 end 2462 end
2456 t.n = n+1; 2463 t.n = n+1;
2457 while n >= pos do 2464 for i=n,pos,-1 do
2458 t[n+1] = t[n] 2465 t[i+1] = t[i]
2459 n = n-1
2460 end 2466 end
2461 t[pos] = value 2467 t[pos] = value
2462 end 2468 end
@@ -2480,12 +2486,11 @@ except that the table accesses are all raw (that is, without tag methods):
2480\begin{verbatim} 2486\begin{verbatim}
2481 function tremove (t, pos) 2487 function tremove (t, pos)
2482 local n = getn(t) 2488 local n = getn(t)
2489 if n<=0 then return end
2483 pos = pos or n 2490 pos = pos or n
2484 local value = t[pos] 2491 local value = t[pos]
2485 if n<=0 then return end 2492 for i=pos,n-1 do
2486 while pos < n do 2493 t[i] = t[i+1]
2487 t[pos] = t[pos+1]
2488 pos = pos+1
2489 end 2494 end
2490 t[n] = nil 2495 t[n] = nil
2491 t.n = n-1 2496 t.n = n-1
@@ -3266,18 +3271,19 @@ int listvars (lua_State *L, int level) {
3266 3271
3267The Lua interpreter offers two hooks for debugging purposes: 3272The Lua interpreter offers two hooks for debugging purposes:
3268a \emph{call} hook and a \emph{line} hook. 3273a \emph{call} hook and a \emph{line} hook.
3269Both have the same type, and you can set them with the 3274Both have the same type,
3270following functions:
3271\Deffunc{lua_Hook}\Deffunc{lua_setcallhook}\Deffunc{lua_setlinehook}
3272\begin{verbatim} 3275\begin{verbatim}
3273typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 3276typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
3274 3277\end{verbatim}
3278and you can set them with the following functions:
3279\Deffunc{lua_Hook}\Deffunc{lua_setcallhook}\Deffunc{lua_setlinehook}
3280\begin{verbatim}
3275lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); 3281lua_Hook lua_setcallhook (lua_State *L, lua_Hook func);
3276lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); 3282lua_Hook lua_setlinehook (lua_State *L, lua_Hook func);
3277\end{verbatim} 3283\end{verbatim}
3278A hook is disabled when its value is \verb|NULL|, 3284A hook is disabled when its value is \verb|NULL|,
3279which is the initial value of both hooks. 3285which is the initial value of both hooks.
3280Both \verb|lua_setcallhook| and \verb|lua_setlinehook| 3286The functions \verb|lua_setcallhook| and \verb|lua_setlinehook|
3281set their corresponding hooks and return their previous values. 3287set their corresponding hooks and return their previous values.
3282 3288
3283The call hook is called whenever the 3289The call hook is called whenever the