diff options
| -rw-r--r-- | manual.tex | 277 |
1 files changed, 145 insertions, 132 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | % $Id: manual.tex,v 1.40 2000/08/09 19:09:20 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.41 2000/08/14 19:18:14 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | \documentclass[11pt]{article} | 3 | \documentclass[11pt]{article} |
| 4 | \usepackage{fullpage,bnf} | 4 | \usepackage{fullpage,bnf} |
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | % LHF | 28 | % LHF |
| 29 | \renewcommand{\ter}[1]{{\rm`{\tt#1}'}} | 29 | \renewcommand{\ter}[1]{{\rm`{\tt#1}'}} |
| 30 | \newcommand{\Nter}[1]{{\rm{\tt#1}}} | ||
| 30 | \newcommand{\NOTE}{\par\noindent\emph{NOTE}: } | 31 | \newcommand{\NOTE}{\par\noindent\emph{NOTE}: } |
| 31 | 32 | ||
| 32 | \makeindex | 33 | \makeindex |
| @@ -122,7 +123,7 @@ Waldemar Celes | |||
| 122 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 123 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | \date{{\small \tt\$Date: 2000/08/09 19:09:20 $ $}} | 126 | \date{{\small \tt\$Date: 2000/08/14 19:18:14 $ $}} |
| 126 | 127 | ||
| 127 | \maketitle | 128 | \maketitle |
| 128 | 129 | ||
| @@ -267,7 +268,7 @@ A chunk is simply a sequence of statements, | |||
| 267 | which are executed sequentially. | 268 | which are executed sequentially. |
| 268 | Each statement can be optionally followed by a semicolon: | 269 | Each statement can be optionally followed by a semicolon: |
| 269 | \begin{Produc} | 270 | \begin{Produc} |
| 270 | \produc{chunk}{\rep{stat} \opt{\ter{;}}} | 271 | \produc{chunk}{\rep{stat \opt{\ter{;}}}} |
| 271 | \end{Produc}% | 272 | \end{Produc}% |
| 272 | Statements are described in \See{stats}. | 273 | Statements are described in \See{stats}. |
| 273 | (The notation above is the usual extended BNF, | 274 | (The notation above is the usual extended BNF, |
| @@ -664,7 +665,7 @@ The table \rwd{for} statement traverses all pairs | |||
| 664 | index--value of a given table. | 665 | index--value of a given table. |
| 665 | It has the following syntax: | 666 | It has the following syntax: |
| 666 | \begin{Produc} | 667 | \begin{Produc} |
| 667 | \produc{stat}{\rwd{for} name \ter{,} name \rwd{in} exp | 668 | \produc{stat}{\rwd{for} name \ter{,} name \rwd{in} exp1 |
| 668 | \rwd{do} block \rwd{end}} | 669 | \rwd{do} block \rwd{end}} |
| 669 | \end{Produc}% | 670 | \end{Produc}% |
| 670 | A \rwd{for} statement like | 671 | A \rwd{for} statement like |
| @@ -974,7 +975,7 @@ Arguments have the following syntax: | |||
| 974 | \begin{Produc} | 975 | \begin{Produc} |
| 975 | \produc{args}{\ter{(} \opt{explist1} \ter{)}} | 976 | \produc{args}{\ter{(} \opt{explist1} \ter{)}} |
| 976 | \produc{args}{tableconstructor} | 977 | \produc{args}{tableconstructor} |
| 977 | \produc{args}{\ter{literal}} | 978 | \produc{args}{\Nter{literal}} |
| 978 | \produc{explist1}{\rep{exp1 \ter{,}} exp} | 979 | \produc{explist1}{\rep{exp1 \ter{,}} exp} |
| 979 | \end{Produc}% | 980 | \end{Produc}% |
| 980 | All argument expressions are evaluated before the call. | 981 | All argument expressions are evaluated before the call. |
| @@ -1561,7 +1562,7 @@ the stack size for the interpreter and a boolean that | |||
| 1561 | indicates whether the predefined functions should be loaded or not. | 1562 | indicates whether the predefined functions should be loaded or not. |
| 1562 | Each function call needs one stack position for each local variable | 1563 | Each function call needs one stack position for each local variable |
| 1563 | and temporary variables, plus one position for book-keeping. | 1564 | and temporary variables, plus one position for book-keeping. |
| 1564 | The stack must also have at least ten extra positions available. | 1565 | The stack must also have some 20 extra positions available. |
| 1565 | For very small implementations, without recursive functions, | 1566 | For very small implementations, without recursive functions, |
| 1566 | a stack size of 100 should be enough. | 1567 | a stack size of 100 should be enough. |
| 1567 | A value 0 for \verb|stacksize| uses a default size of 1024 positions. | 1568 | A value 0 for \verb|stacksize| uses a default size of 1024 positions. |
| @@ -1599,51 +1600,6 @@ to avoid growing too big. | |||
| 1599 | With the exception of \verb|lua_newstate|, | 1600 | With the exception of \verb|lua_newstate|, |
| 1600 | all functions in the API need a state as their first argument. | 1601 | all functions in the API need a state as their first argument. |
| 1601 | 1602 | ||
| 1602 | >>>>>>>>>>>> | ||
| 1603 | However, most applications use a single state. | ||
| 1604 | To avoid the burden of passing this only state explicitly to all | ||
| 1605 | functions, and also to keep compatibility with old versions of Lua, | ||
| 1606 | the API provides a set of macros and one global variable that | ||
| 1607 | take care of this state argument for single-state applications: | ||
| 1608 | \begin{verbatim} | ||
| 1609 | #ifndef LUA_REENTRANT | ||
| 1610 | \end{verbatim} | ||
| 1611 | \begin{verbatim} | ||
| 1612 | extern lua_State *lua_state; | ||
| 1613 | \end{verbatim} | ||
| 1614 | \begin{verbatim} | ||
| 1615 | #define lua_close() (lua_close)(lua_state) | ||
| 1616 | #define lua_dofile(filename) (lua_dofile)(lua_state, filename) | ||
| 1617 | #define lua_dostring(str) (lua_dostring)(lua_state, str) | ||
| 1618 | ... | ||
| 1619 | \end{verbatim} | ||
| 1620 | \begin{verbatim} | ||
| 1621 | #endif | ||
| 1622 | \end{verbatim} | ||
| 1623 | For each function in the API, there is a macro with the same name | ||
| 1624 | that supplies \verb|lua_state| as the first argument to the call. | ||
| 1625 | (The parentheses around the function name avoid it being expanded | ||
| 1626 | again as a macro.) | ||
| 1627 | The only exception is \verb|lua_newstate|; | ||
| 1628 | in this case, the corresponding macro is | ||
| 1629 | \begin{verbatim} | ||
| 1630 | #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0, 1)))) | ||
| 1631 | \end{verbatim} | ||
| 1632 | This code checks whether the global state has been initialized; | ||
| 1633 | if not, it creates a new state with default settings and | ||
| 1634 | assigns it to \verb|lua_state|. | ||
| 1635 | |||
| 1636 | By default, the single-state macros are all active. | ||
| 1637 | If you need to use multiple states, | ||
| 1638 | and therefore will provide the state argument explicitly in each call, | ||
| 1639 | you should define \IndexVerb{LUA_REENTRANT} before | ||
| 1640 | including \verb|lua.h| in your code: | ||
| 1641 | \begin{verbatim} | ||
| 1642 | #define LUA_REENTRANT | ||
| 1643 | #include "lua.h" | ||
| 1644 | \end{verbatim} | ||
| 1645 | <<<<<<<<< | ||
| 1646 | |||
| 1647 | 1603 | ||
| 1648 | \subsection{Exchanging Values between C and Lua} \label{valuesCLua} | 1604 | \subsection{Exchanging Values between C and Lua} \label{valuesCLua} |
| 1649 | Because Lua has no static type system, | 1605 | Because Lua has no static type system, |
| @@ -1801,9 +1757,9 @@ nested blocks can be defined with the functions | |||
| 1801 | void lua_beginblock (lua_State *L); | 1757 | void lua_beginblock (lua_State *L); |
| 1802 | void lua_endblock (lua_State *L); | 1758 | void lua_endblock (lua_State *L); |
| 1803 | \end{verbatim} | 1759 | \end{verbatim} |
| 1804 | After the end of the block, | 1760 | At the end of a block, |
| 1805 | all \verb|lua_Object|s created inside it are released. | 1761 | Lua releases all \verb|lua_Object|s created inside the block, |
| 1806 | The \verb|lua_endblock| function also empties the C2Lua stack. | 1762 | and empties the C2lua stack. |
| 1807 | 1763 | ||
| 1808 | \subsection{Garbage Collection}\label{GC} | 1764 | \subsection{Garbage Collection}\label{GC} |
| 1809 | Because Lua has automatic memory management and garbage collection, | 1765 | Because Lua has automatic memory management and garbage collection, |
| @@ -2026,7 +1982,7 @@ equivalent to the Lua code: | |||
| 2026 | lua_setglobal(L, "b"); /* set global variable 'b' */ | 1982 | lua_setglobal(L, "b"); /* set global variable 'b' */ |
| 2027 | \end{verbatim} | 1983 | \end{verbatim} |
| 2028 | 1984 | ||
| 2029 | Some special Lua functions have exclusive interfaces. | 1985 | Some special Lua functions have direct interfaces. |
| 2030 | The host program can generate a Lua error calling the function | 1986 | The host program can generate a Lua error calling the function |
| 2031 | \Deffunc{lua_error} | 1987 | \Deffunc{lua_error} |
| 2032 | \begin{verbatim} | 1988 | \begin{verbatim} |
| @@ -2071,13 +2027,13 @@ int lua_next (lua_State *L, lua_Object t, int i); | |||
| 2071 | \end{verbatim} | 2027 | \end{verbatim} |
| 2072 | Its first argument is the table to be traversed, | 2028 | Its first argument is the table to be traversed, |
| 2073 | and the second is a \emph{cursor}; | 2029 | and the second is a \emph{cursor}; |
| 2074 | this cursor starts in 0, | 2030 | this cursor starts at 0, |
| 2075 | and for each call the function returns a value to | 2031 | and for each call the function returns a value to |
| 2076 | be used in the next call, | 2032 | be used in the next call, |
| 2077 | or 0 to signal the end of the traversal. | 2033 | or 0 to signal the end of the traversal. |
| 2078 | The function also returns, in the Lua2C array, | 2034 | The function also returns, in the lua2C array, |
| 2079 | a key-value pair from the table. | 2035 | a key-value pair from the table. |
| 2080 | A typical traversal looks like the following code: | 2036 | A typical traversal looks like this: |
| 2081 | \begin{verbatim} | 2037 | \begin{verbatim} |
| 2082 | int i; | 2038 | int i; |
| 2083 | lua_Object t; | 2039 | lua_Object t; |
| @@ -2161,12 +2117,12 @@ If the C code needs to keep a \verb|lua_Object| | |||
| 2161 | outside block boundaries, | 2117 | outside block boundaries, |
| 2162 | then it must create a \Def{reference} to the object. | 2118 | then it must create a \Def{reference} to the object. |
| 2163 | The routines to manipulate references are the following: | 2119 | The routines to manipulate references are the following: |
| 2164 | \Deffunc{lua_ref}\Deffunc{lua_getref} | 2120 | \Deffunc{lua_ref}\Deffunc{lua_pushref} |
| 2165 | \Deffunc{lua_unref} | 2121 | \Deffunc{lua_unref} |
| 2166 | \begin{verbatim} | 2122 | \begin{verbatim} |
| 2167 | int lua_ref (lua_State *L, int lock); | 2123 | int lua_ref (lua_State *L, int lock); |
| 2168 | lua_Object lua_getref (lua_State *L, int ref); | 2124 | int lua_pushref (lua_State *L, int ref); |
| 2169 | void lua_unref (lua_State *L, int ref); | 2125 | void lua_unref (lua_State *L, int ref); |
| 2170 | \end{verbatim} | 2126 | \end{verbatim} |
| 2171 | The function \verb|lua_ref| creates a reference | 2127 | The function \verb|lua_ref| creates a reference |
| 2172 | to the object that is on the top of the stack, | 2128 | to the object that is on the top of the stack, |
| @@ -2180,10 +2136,10 @@ If \verb|lock| is true, then the object is \emph{locked}: | |||
| 2180 | this means the object will not be garbage collected. | 2136 | this means the object will not be garbage collected. |
| 2181 | \emph{Unlocked references may be garbage collected}. | 2137 | \emph{Unlocked references may be garbage collected}. |
| 2182 | Whenever the referenced object is needed in~C, | 2138 | Whenever the referenced object is needed in~C, |
| 2183 | a call to \verb|lua_getref| | 2139 | a call to \verb|lua_pushref| |
| 2184 | returns a handle to it; | 2140 | pushes that object into the C2lua stack; |
| 2185 | if the object has been collected, | 2141 | if the object has been collected, |
| 2186 | \verb|lua_getref| returns \verb|LUA_NOOBJECT|. | 2142 | \verb|lua_getref| returns 0 (and does not push anything). |
| 2187 | 2143 | ||
| 2188 | When a reference is no longer needed, | 2144 | When a reference is no longer needed, |
| 2189 | it can be released with a call to \verb|lua_unref|. | 2145 | it can be released with a call to \verb|lua_unref|. |
| @@ -3257,7 +3213,7 @@ it returns 0. | |||
| 3257 | The structure \verb|lua_Debug| is used to carry different pieces of information | 3213 | The structure \verb|lua_Debug| is used to carry different pieces of information |
| 3258 | about an active function: | 3214 | about an active function: |
| 3259 | \begin{verbatim} | 3215 | \begin{verbatim} |
| 3260 | struct lua_Debug { | 3216 | typedef struct lua_Debug { |
| 3261 | const char *event; /* "call", "return" */ | 3217 | const char *event; /* "call", "return" */ |
| 3262 | const char *source; /* (S) */ | 3218 | const char *source; /* (S) */ |
| 3263 | int linedefined; /* (S) */ | 3219 | int linedefined; /* (S) */ |
| @@ -3269,7 +3225,7 @@ struct lua_Debug { | |||
| 3269 | lua_Object func; /* (f) function being executed */ | 3225 | lua_Object func; /* (f) function being executed */ |
| 3270 | /* private part */ | 3226 | /* private part */ |
| 3271 | ... | 3227 | ... |
| 3272 | }; | 3228 | } lua_Debug; |
| 3273 | \end{verbatim} | 3229 | \end{verbatim} |
| 3274 | The \verb|lua_getstack| function fills only the private part | 3230 | The \verb|lua_getstack| function fills only the private part |
| 3275 | of this structure, for future use. | 3231 | of this structure, for future use. |
| @@ -3282,9 +3238,10 @@ This function returns 0 on error | |||
| 3282 | (e.g., an invalid option in \verb|what|). | 3238 | (e.g., an invalid option in \verb|what|). |
| 3283 | Each character in the string \verb|what| | 3239 | Each character in the string \verb|what| |
| 3284 | selects some fields of \verb|ar| to be filled, | 3240 | selects some fields of \verb|ar| to be filled, |
| 3285 | as indicated by the letter in parentheses in the definition of \verb|lua_Debug|; | 3241 | as indicated by the letter in parentheses in the definition of \verb|lua_Debug|: |
| 3286 | that is, an \verb|S| fills the fields \verb|source| and \verb|linedefined|, | 3242 | An \verb|S| fills in the fields \verb|source|, \verb|linedefined|, |
| 3287 | and \verb|l| fills the field \verb|currentline|, etc. | 3243 | and \verb|what|; |
| 3244 | \verb|l| fills in the field \verb|currentline|, etc. | ||
| 3288 | 3245 | ||
| 3289 | To get information about a function that is not active (that is, | 3246 | To get information about a function that is not active (that is, |
| 3290 | it is not in the stack), | 3247 | it is not in the stack), |
| @@ -3310,7 +3267,7 @@ if the function was defined in a file, | |||
| 3310 | \verb|source| starts with a \verb|@| followed by the file name. | 3267 | \verb|source| starts with a \verb|@| followed by the file name. |
| 3311 | 3268 | ||
| 3312 | \item[linedefined] | 3269 | \item[linedefined] |
| 3313 | the line number where starts the definition of the function. | 3270 | the line number where the definition of the function starts. |
| 3314 | 3271 | ||
| 3315 | \item[what] the string \verb|"Lua"| if this is a Lua function, | 3272 | \item[what] the string \verb|"Lua"| if this is a Lua function, |
| 3316 | \verb|"C"| if this is a C~function, | 3273 | \verb|"C"| if this is a C~function, |
| @@ -3345,9 +3302,7 @@ if the function is a tag method, | |||
| 3345 | otherwise \verb|namewhat| is \verb|""| (the empty string). | 3302 | otherwise \verb|namewhat| is \verb|""| (the empty string). |
| 3346 | 3303 | ||
| 3347 | \item[nups] | 3304 | \item[nups] |
| 3348 | Number of upvalues of a C~function. | 3305 | Number of upvalues of a function. |
| 3349 | If the function is not a C~function, | ||
| 3350 | \verb|nups| is set to 0. | ||
| 3351 | 3306 | ||
| 3352 | \item[func] | 3307 | \item[func] |
| 3353 | The function being executed, as a \verb|lua_Object|. | 3308 | The function being executed, as a \verb|lua_Object|. |
| @@ -3388,24 +3343,20 @@ value of that variable. | |||
| 3388 | For \verb|lua_setlocal|, | 3343 | For \verb|lua_setlocal|, |
| 3389 | you fill the \verb|index| and the \verb|value| fields of \verb|v|, | 3344 | you fill the \verb|index| and the \verb|value| fields of \verb|v|, |
| 3390 | and the function assigns that value to the variable. | 3345 | and the function assigns that value to the variable. |
| 3391 | Both functions return 0 on failure, that happens | 3346 | Both functions return 0 on failure; |
| 3392 | if the index is greater than the number of active local variables. | 3347 | that happens if the index is greater than the number of active local variables. |
| 3393 | 3348 | ||
| 3394 | As an example, the following function lists the names of all | 3349 | As an example, the following function lists the names of all |
| 3395 | local variables for a function in a given level of the stack: | 3350 | local variables for a function in a given level of the stack: |
| 3396 | \begin{verbatim} | 3351 | \begin{verbatim} |
| 3397 | int listvars (lua_State *L, int level) { | 3352 | int listvars (lua_State *L, int level) { |
| 3398 | lua_Debug ar; | 3353 | lua_Debug ar; |
| 3399 | int i; | 3354 | lua_Localvar v; |
| 3400 | if (lua_getstack(L, level, &ar) == 0) | 3355 | if (lua_getstack(L, level, &ar) == 0) |
| 3401 | return 0; /* failure: no such level on the stack */ | 3356 | return 0; /* failure: no such level on the stack */ |
| 3402 | for (i=1; ; i++) { | 3357 | for (v.index = 1; lua_getlocal(L, &ar, &v); v.index++) |
| 3403 | lua_Localvar v; | ||
| 3404 | v.index = i; | ||
| 3405 | if (lua_getlocal(L, &ar, &v) == 0) | ||
| 3406 | return 1; /* no more locals */ | ||
| 3407 | printf("%s\n", v.name); | 3358 | printf("%s\n", v.name); |
| 3408 | } | 3359 | return 1; |
| 3409 | } | 3360 | } |
| 3410 | \end{verbatim} | 3361 | \end{verbatim} |
| 3411 | 3362 | ||
| @@ -3505,7 +3456,7 @@ until the last active local variable.) | |||
| 3505 | The function returns \nil\ if there is no local | 3456 | The function returns \nil\ if there is no local |
| 3506 | variable with the given index, | 3457 | variable with the given index, |
| 3507 | and raises an error when called with a \verb|level| out of range. | 3458 | and raises an error when called with a \verb|level| out of range. |
| 3508 | (You can call \verb|getstack| to check wheter the level is valid.) | 3459 | (You can call \verb|getstack| to check whether the level is valid.) |
| 3509 | 3460 | ||
| 3510 | \subsubsection*{\ff \T{setlocal (level, local, value)}}\Deffunc{setlocal} | 3461 | \subsubsection*{\ff \T{setlocal (level, local, value)}}\Deffunc{setlocal} |
| 3511 | 3462 | ||
| @@ -3638,43 +3589,96 @@ some differences had to be introduced. | |||
| 3638 | Here is a list of all these incompatibilities. | 3589 | Here is a list of all these incompatibilities. |
| 3639 | 3590 | ||
| 3640 | \subsection*{Incompatibilities with \Index{version 3.2}} | 3591 | \subsection*{Incompatibilities with \Index{version 3.2}} |
| 3592 | |||
| 3593 | \subsubsection*{Changes in the Language} | ||
| 3641 | \begin{itemize} | 3594 | \begin{itemize} |
| 3642 | 3595 | ||
| 3643 | \item | 3596 | \item |
| 3644 | General read patterns are now deprecated. | 3597 | All pragmas (\verb|$debug|, \verb|$if|, \ldots) are deprecated. |
| 3598 | |||
| 3599 | \item \rwd{for}, \rwd{break}, and \rwd{in} now are reserved words. | ||
| 3600 | |||
| 3645 | \item | 3601 | \item |
| 3646 | Garbage-collection tag methods for tables is now deprecated. | 3602 | Garbage-collection tag methods for tables is now deprecated. |
| 3603 | |||
| 3647 | \item | 3604 | \item |
| 3648 | \verb|setglobal|, \verb|rawsetglobal|, and \verb|sort| no longer return a value; | 3605 | There is now only one tag method for order operators. |
| 3649 | \verb|type| no longer return a second value. | 3606 | |
| 3650 | \item | 3607 | \item |
| 3651 | In nested function calls like \verb|f(g(x))| | 3608 | In nested function calls like \verb|f(g(x))| |
| 3652 | \emph{all} return values from \verb|g| are passed as arguments to \verb|f|. | 3609 | \emph{all} return values from \verb|g| are passed as arguments to \verb|f|. |
| 3653 | (This only happens when \verb|g| is the last | 3610 | (This only happens when \verb|g| is the last |
| 3654 | [or the only] argument to \verb|f|.) | 3611 | [or the only] argument to \verb|f|.) |
| 3612 | |||
| 3655 | \item | 3613 | \item |
| 3656 | There is now only one tag method for order operators. | 3614 | The pre-compiler may assume that some operators are associative, |
| 3657 | \item | ||
| 3658 | The debug API has been completely rewritten. | ||
| 3659 | \item | ||
| 3660 | The pre-compiler may use the fact that some operators are associative, | ||
| 3661 | for optimizations. | 3615 | for optimizations. |
| 3662 | This may cause problems if these operators | 3616 | This may cause problems if these operators |
| 3663 | have non-associative tag methods. | 3617 | have non-associative tag methods. |
| 3618 | |||
| 3619 | \item Old pre-compiled code is obsolete, and must be re-compiled. | ||
| 3620 | |||
| 3621 | \end{itemize} | ||
| 3622 | |||
| 3623 | |||
| 3624 | \subsubsection*{Changes in the Libraries} | ||
| 3625 | \begin{itemize} | ||
| 3626 | |||
| 3664 | \item | 3627 | \item |
| 3665 | All functions from the old API are now macros. | 3628 | General read patterns are now deprecated. |
| 3629 | |||
| 3630 | \item | ||
| 3631 | The functions \verb|rawgettable| and \verb|rawsettable| | ||
| 3632 | were renamed to \verb|rawget| and \verb|rawset|. | ||
| 3633 | |||
| 3634 | \item | ||
| 3635 | The functions \verb|foreachvar|, \verb|nextvar|, | ||
| 3636 | \verb|rawsetglobal|, and \verb|rawgetglobal| are deprecated. | ||
| 3637 | You can get their functionality using table operations | ||
| 3638 | over the table of globals. | ||
| 3639 | |||
| 3640 | \item | ||
| 3641 | \verb|setglobal| and \verb|sort| no longer return a value; | ||
| 3642 | \verb|type| no longer returns a second value. | ||
| 3643 | |||
| 3644 | \end{itemize} | ||
| 3645 | |||
| 3646 | |||
| 3647 | \subsubsection*{Changes in the API} | ||
| 3648 | \begin{itemize} | ||
| 3649 | |||
| 3650 | \item | ||
| 3651 | The whole API is now reentrant, | ||
| 3652 | which means that all functions have | ||
| 3653 | an extra first argument, a Lua state. | ||
| 3654 | You can still use the old format: | ||
| 3655 | If you define \verb|LUA_SINGLESTATE| before including \verb|lua.h|, | ||
| 3656 | all functions from the old API are defined as macros. | ||
| 3657 | You will also have to define a variable | ||
| 3658 | \begin{verbatim} | ||
| 3659 | lua_State *lua_state = NULL; | ||
| 3660 | \end{verbatim} | ||
| 3661 | somewhere in your program. | ||
| 3662 | |||
| 3663 | \item | ||
| 3664 | The debug API has been completely rewritten. | ||
| 3665 | |||
| 3666 | \item | 3666 | \item |
| 3667 | A \verb|const| qualifier has been added to \verb|char *| | 3667 | A \verb|const| qualifier has been added to \verb|char *| |
| 3668 | in all API functions that handle C~strings. | 3668 | in all API functions that handle C~strings. |
| 3669 | |||
| 3670 | \item | ||
| 3671 | Some types \verb|long| were changed to \verb|size_t|. | ||
| 3672 | |||
| 3669 | \item | 3673 | \item |
| 3670 | \verb|luaL_openlib| no longer automatically calls \verb|lua_open|. | 3674 | \verb|luaL_openlib| no longer automatically calls \verb|lua_open|. |
| 3671 | So, | 3675 | So, |
| 3672 | you must now explicitly call \verb|lua_open| before opening | 3676 | you must now explicitly call \verb|lua_open| before opening |
| 3673 | the standard libraries. | 3677 | the standard libraries. |
| 3678 | |||
| 3674 | \item | 3679 | \item |
| 3675 | \verb|lua_type| now returns a string describing the type, | 3680 | \verb|lua_type| now returns a string describing the type, |
| 3676 | and is no longer a synonym for \verb|lua_tag|. | 3681 | and is no longer a synonym for \verb|lua_tag|. |
| 3677 | \item Old pre-compiled code is obsolete, and must be re-compiled. | ||
| 3678 | 3682 | ||
| 3679 | \end{itemize} | 3683 | \end{itemize} |
| 3680 | 3684 | ||
| @@ -3687,7 +3691,7 @@ and is no longer a synonym for \verb|lua_tag|. | |||
| 3687 | 3691 | ||
| 3688 | \begin{Produc} | 3692 | \begin{Produc} |
| 3689 | 3693 | ||
| 3690 | \produc{chunk}{\rep{stat} \opt{\ter{;}}} | 3694 | \produc{chunk}{\rep{stat \opt{\ter{;}}}} |
| 3691 | 3695 | ||
| 3692 | \produc{block}{chunk} | 3696 | \produc{block}{chunk} |
| 3693 | 3697 | ||
| @@ -3702,43 +3706,72 @@ and is no longer a synonym for \verb|lua_tag|. | |||
| 3702 | \opt{\rwd{else} block} \rwd{end} | 3706 | \opt{\rwd{else} block} \rwd{end} |
| 3703 | \OrNL \rwd{return} \opt{explist1} | 3707 | \OrNL \rwd{return} \opt{explist1} |
| 3704 | \OrNL \rwd{break} | 3708 | \OrNL \rwd{break} |
| 3705 | \OrNL \rwd{for} name \ter{=} exp1 \ter{,} exp1 \opt{\ter{,} exp1} | 3709 | \OrNL \rwd{for} \Nter{name} \ter{=} exp1 \ter{,} exp1 \opt{\ter{,} exp1} |
| 3706 | \rwd{do} block \rwd{end} | 3710 | \rwd{do} block \rwd{end} |
| 3711 | \OrNL \rwd{for} \Nter{name} \ter{,} \Nter{name} \rwd{in} exp1 | ||
| 3712 | \rwd{do} block \rwd{end} | ||
| 3707 | \OrNL \rwd{function} funcname \ter{(} \opt{parlist1} \ter{)} block \rwd{end} | 3713 | \OrNL \rwd{function} funcname \ter{(} \opt{parlist1} \ter{)} block \rwd{end} |
| 3708 | \OrNL \rwd{local} declist \opt{init} | 3714 | \OrNL \rwd{local} declist \opt{init} |
| 3709 | } | 3715 | } |
| 3710 | 3716 | ||
| 3717 | \produc{funcname}{% | ||
| 3718 | \Nter{name} | ||
| 3719 | \Or \Nter{name} \ter{.} \Nter{name} | ||
| 3720 | \Or \Nter{name} \ter{:} \Nter{name} | ||
| 3721 | } | ||
| 3722 | |||
| 3723 | \produc{varlist1}{var \rep{\ter{,} var}} | ||
| 3724 | |||
| 3711 | \produc{var}{% | 3725 | \produc{var}{% |
| 3712 | name | 3726 | \Nter{name} |
| 3713 | \OrNL varorfunc \ter{[} exp1 \ter{]} | 3727 | \Or varorfunc \ter{[} exp1 \ter{]} |
| 3714 | \OrNL varorfunc \ter{.} name | 3728 | \Or varorfunc \ter{.} \Nter{name} |
| 3715 | } | 3729 | } |
| 3716 | 3730 | ||
| 3717 | \produc{varorfunc}{var \Or functioncall} | 3731 | \produc{varorfunc}{var \Or functioncall} |
| 3718 | 3732 | ||
| 3719 | \produc{varlist1}{var \rep{\ter{,} var}} | 3733 | \produc{declist}{\Nter{name} \rep{\ter{,} \Nter{name}}} |
| 3720 | |||
| 3721 | \produc{declist}{name \rep{\ter{,} name}} | ||
| 3722 | 3734 | ||
| 3723 | \produc{init}{\ter{=} explist1} | 3735 | \produc{init}{\ter{=} explist1} |
| 3724 | 3736 | ||
| 3737 | \produc{explist1}{\rep{exp1 \ter{,}} exp} | ||
| 3738 | |||
| 3739 | \produc{exp1}{exp} | ||
| 3740 | |||
| 3725 | \produc{exp}{% | 3741 | \produc{exp}{% |
| 3726 | \rwd{nil} | 3742 | \rwd{nil} |
| 3727 | \Or number | 3743 | \Or \Nter{number} |
| 3728 | \Or literal | 3744 | \Or \Nter{literal} |
| 3745 | \Or var | ||
| 3729 | \Or function | 3746 | \Or function |
| 3730 | \Or upvalue | 3747 | \Or upvalue |
| 3731 | \Or functioncall | 3748 | \OrNL functioncall |
| 3732 | \Or tableconstructor | 3749 | \Or tableconstructor |
| 3733 | \Or \ter{(} exp \ter{)} | 3750 | \Or \ter{(} exp \ter{)} |
| 3734 | \Or exp binop exp | 3751 | \Or exp binop exp |
| 3735 | \Or unop exp | 3752 | \Or unop exp |
| 3736 | } | 3753 | } |
| 3737 | 3754 | ||
| 3738 | \produc{exp1}{exp} | ||
| 3739 | 3755 | ||
| 3740 | \produc{explist1}{\rep{exp1 \ter{,}} exp} | 3756 | \produc{functioncall}{% |
| 3757 | varorfunc args | ||
| 3758 | \Or varorfunc \ter{:} \Nter{name} args | ||
| 3759 | } | ||
| 3760 | |||
| 3761 | \produc{args}{% | ||
| 3762 | \ter{(} \opt{explist1} \ter{)} | ||
| 3763 | \Or tableconstructor | ||
| 3764 | \Or \Nter{literal} | ||
| 3765 | } | ||
| 3766 | |||
| 3767 | \produc{function}{\rwd{function} \ter{(} \opt{parlist1} \ter{)} block \rwd{end}} | ||
| 3768 | |||
| 3769 | \produc{parlist1}{% | ||
| 3770 | \ter{\ldots} | ||
| 3771 | \Or \Nter{name} \rep{\ter{,} \Nter{name}} \opt{\ter{,} \ter{\ldots}} | ||
| 3772 | } | ||
| 3741 | 3773 | ||
| 3774 | \produc{upvalue}{\ter{\%} \Nter{name}} | ||
| 3742 | 3775 | ||
| 3743 | \produc{tableconstructor}{\ter{\{} fieldlist \ter{\}}} | 3776 | \produc{tableconstructor}{\ter{\{} fieldlist \ter{\}}} |
| 3744 | \produc{fieldlist}{% | 3777 | \produc{fieldlist}{% |
| @@ -3753,34 +3786,14 @@ and is no longer a synonym for \verb|lua_tag|. | |||
| 3753 | \produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}} | 3786 | \produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}} |
| 3754 | \produc{ffield}{% | 3787 | \produc{ffield}{% |
| 3755 | \ter{[} exp \ter{]} \ter{=} exp | 3788 | \ter{[} exp \ter{]} \ter{=} exp |
| 3756 | \Or name \ter{=} exp | 3789 | \Or \Nter{name} \ter{=} exp |
| 3757 | } | 3790 | } |
| 3758 | 3791 | ||
| 3759 | \produc{functioncall}{% | 3792 | \produc{binop}{\ter{+} \Or \ter{-} \Or \ter{*} \Or \ter{/} \Or \ter{\^{ }} \Or |
| 3760 | varorfunc args | 3793 | \ter{..} \OrNL \ter{<} \Or \ter{<=} \Or \ter{>} \Or \ter{>=} |
| 3761 | \Or varorfunc \ter{:} name args | 3794 | \Or \ter{==} \Or \ter{\~{ }=} \OrNL \rwd{and} \Or \rwd{or}} |
| 3762 | } | ||
| 3763 | 3795 | ||
| 3764 | \produc{args}{% | 3796 | \produc{unop}{\ter{-} \Or \rwd{not}} |
| 3765 | \ter{(} \opt{explist1} \ter{)} | ||
| 3766 | \Or tableconstructor | ||
| 3767 | \Or \ter{literal} | ||
| 3768 | } | ||
| 3769 | |||
| 3770 | \produc{function}{\rwd{function} \ter{(} \opt{parlist1} \ter{)} block \rwd{end}} | ||
| 3771 | |||
| 3772 | \produc{funcname}{% | ||
| 3773 | name | ||
| 3774 | \OrNL name \ter{.} name | ||
| 3775 | \OrNL name \ter{:} name | ||
| 3776 | } | ||
| 3777 | |||
| 3778 | \produc{parlist1}{% | ||
| 3779 | \ter{\ldots} | ||
| 3780 | \Or name \rep{\ter{,} name} \opt{\ter{,} \ter{\ldots}} | ||
| 3781 | } | ||
| 3782 | |||
| 3783 | \produc{upvalue}{\ter{\%} name} | ||
| 3784 | 3797 | ||
| 3785 | \end{Produc} | 3798 | \end{Produc} |
| 3786 | %}=============================================================== | 3799 | %}=============================================================== |
