diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-20 16:28:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-20 16:28:16 -0300 |
commit | 3e4327530835f65d3bc089688bd46f44efcddb57 (patch) | |
tree | e53ad5f3e1d741156d646f09eb353bbe8851deaa | |
parent | f97307b54893a53c985a0dcd8b3bb2b94cedd48d (diff) | |
download | lua-3e4327530835f65d3bc089688bd46f44efcddb57.tar.gz lua-3e4327530835f65d3bc089688bd46f44efcddb57.tar.bz2 lua-3e4327530835f65d3bc089688bd46f44efcddb57.zip |
incompatibilities with 2.5 + restrictions on tag methods
-rw-r--r-- | manual.tex | 68 |
1 files changed, 48 insertions, 20 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 2.3 1997/06/19 18:03:04 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 2.4 1997/06/19 18:49:40 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentstyle[fullpage,11pt,bnf]{article} | 3 | \documentstyle[fullpage,11pt,bnf]{article} |
4 | 4 | ||
@@ -38,7 +38,7 @@ Waldemar Celes | |||
38 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 38 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
39 | } | 39 | } |
40 | 40 | ||
41 | \date{\small \verb$Date: 1997/06/19 18:03:04 $} | 41 | \date{\small \verb$Date: 1997/06/19 18:49:40 $} |
42 | 42 | ||
43 | \maketitle | 43 | \maketitle |
44 | 44 | ||
@@ -973,6 +973,8 @@ See event \verb|"gettable"| for its semantics. | |||
973 | 973 | ||
974 | \item[``getglobal'':]\index{getglobal event} | 974 | \item[``getglobal'':]\index{getglobal event} |
975 | called whenever Lua accesses a global variable. | 975 | called whenever Lua accesses a global variable. |
976 | This method can only be set for \nil\ and for tags | ||
977 | created by \verb|newtag|. | ||
976 | \begin{verbatim} | 978 | \begin{verbatim} |
977 | function getglobal (varname) | 979 | function getglobal (varname) |
978 | local value = rawgetglobal(varname) | 980 | local value = rawgetglobal(varname) |
@@ -988,6 +990,8 @@ Notice: the function \verb|getglobal| is pre-defined in Lua \see{predefined}. | |||
988 | 990 | ||
989 | \item[``setglobal'':]\index{setglobal event} | 991 | \item[``setglobal'':]\index{setglobal event} |
990 | called whenever Lua assigns to a global variable. | 992 | called whenever Lua assigns to a global variable. |
993 | This method cannot be set for numbers, strings, and tables and | ||
994 | userdata with default tags. | ||
991 | \begin{verbatim} | 995 | \begin{verbatim} |
992 | function setglobal (varname, newvalue) | 996 | function setglobal (varname, newvalue) |
993 | local oldvalue = rawgetglobal(varname) | 997 | local oldvalue = rawgetglobal(varname) |
@@ -1003,6 +1007,7 @@ Notice: the function \verb|setglobal| is pre-defined in Lua \see{predefined}. | |||
1003 | 1007 | ||
1004 | \item[``gettable'':]\index{gettable event} | 1008 | \item[``gettable'':]\index{gettable event} |
1005 | called whenever Lua accesses an indexed variable. | 1009 | called whenever Lua accesses an indexed variable. |
1010 | This method cannot be set for tables with default tag. | ||
1006 | \begin{verbatim} | 1011 | \begin{verbatim} |
1007 | function gettable_event (table, index) | 1012 | function gettable_event (table, index) |
1008 | local tm = gettagmethod(tag(table), "gettable") | 1013 | local tm = gettagmethod(tag(table), "gettable") |
@@ -1024,6 +1029,7 @@ called whenever Lua accesses an indexed variable. | |||
1024 | 1029 | ||
1025 | \item[``settable'':]\index{settable event} | 1030 | \item[``settable'':]\index{settable event} |
1026 | called when Lua assigns to an indexed variable. | 1031 | called when Lua assigns to an indexed variable. |
1032 | This method cannot be set for tables with default tag. | ||
1027 | \begin{verbatim} | 1033 | \begin{verbatim} |
1028 | function settable_event (table, index, value) | 1034 | function settable_event (table, index, value) |
1029 | local tm = gettagmethod(tag(table), "settable") | 1035 | local tm = gettagmethod(tag(table), "settable") |
@@ -1063,6 +1069,8 @@ called when Lua tries to call a non function value. | |||
1063 | 1069 | ||
1064 | \item[``gc'':]\index{gc event} | 1070 | \item[``gc'':]\index{gc event} |
1065 | called when Lua is garbage collecting an object. | 1071 | called when Lua is garbage collecting an object. |
1072 | This method cannot be set for strings, numbers, functions, | ||
1073 | and userdata with default tag. | ||
1066 | For each object to be collected, | 1074 | For each object to be collected, |
1067 | Lua does the equivalent of the following function: | 1075 | Lua does the equivalent of the following function: |
1068 | \begin{verbatim} | 1076 | \begin{verbatim} |
@@ -1092,20 +1100,22 @@ is terminated returning an error condition. | |||
1092 | 1100 | ||
1093 | The only argument to the error method is a string | 1101 | The only argument to the error method is a string |
1094 | describing the error. | 1102 | describing the error. |
1095 | The standard I/O library redefines this method, | 1103 | The default method prints this message in \verb|stderr|. |
1104 | If needed, it is possible to change the error method with the | ||
1105 | function \verb|seterrormethod|, | ||
1106 | which gets the new error handler as its only parameter | ||
1107 | \see{pdf-seterrormethod}. | ||
1108 | The standard I/O library uses this facility to redefine the error method, | ||
1096 | using the debug facilities \see{debugI}, | 1109 | using the debug facilities \see{debugI}, |
1097 | in order to print some extra information, | 1110 | in order to print some extra information, |
1098 | like the call stack. | 1111 | like the call stack. |
1112 | |||
1099 | To provide more information about errors, | 1113 | To provide more information about errors, |
1100 | Lua programs should include the compilation pragma \verb|$debug|. | 1114 | Lua programs should include the compilation pragma \verb|$debug|. |
1101 | \index{debug pragma}\label{pragma} | 1115 | \index{debug pragma}\label{pragma} |
1102 | When an error occurs in a program compiled with this option, | 1116 | When an error occurs in a program compiled with this option, |
1103 | the error routine is able to print the number of the lines where the calls | 1117 | the I/O error routine is able to print the number of the |
1104 | (and the error) were made. | 1118 | lines where the calls (and the error) were made. |
1105 | If needed, it is possible to change the error method with the | ||
1106 | function \verb|seterrormethod|, | ||
1107 | which gets the new error handler as its only parameter | ||
1108 | \see{pdf-seterrormethod}. | ||
1109 | 1119 | ||
1110 | Lua code can explicitly generate an error by calling the built-in | 1120 | Lua code can explicitly generate an error by calling the built-in |
1111 | function \verb|error| \see{pdf-error}. | 1121 | function \verb|error| \see{pdf-error}. |
@@ -1430,13 +1440,14 @@ pops all elements from the C2lua stack. | |||
1430 | The following example shows how a C program may do the | 1440 | The following example shows how a C program may do the |
1431 | equivalent to the Lua code: | 1441 | equivalent to the Lua code: |
1432 | \begin{verbatim} | 1442 | \begin{verbatim} |
1433 | a = f(t.x, 4) | 1443 | a = f("how", t.x, 4) |
1434 | \end{verbatim} | 1444 | \end{verbatim} |
1435 | \begin{verbatim} | 1445 | \begin{verbatim} |
1446 | lua_pushstring("how"); /* 1st argument */ | ||
1436 | lua_pushobject(lua_getglobal("t")); /* push value of global 't' */ | 1447 | lua_pushobject(lua_getglobal("t")); /* push value of global 't' */ |
1437 | lua_pushstring("x"); /* push the string 'x' */ | 1448 | lua_pushstring("x"); /* push the string 'x' */ |
1438 | lua_pushobject(lua_gettable()); /* push result of t.x (= t['x']) */ | 1449 | lua_pushobject(lua_gettable()); /* push result of t.x (= t['x']) */ |
1439 | lua_pushnumber(4); /* 2nd argument */ | 1450 | lua_pushnumber(4); /* 3th argument */ |
1440 | lua_callfunction(lua_getglobal("f")); /* call Lua function */ | 1451 | lua_callfunction(lua_getglobal("f")); /* call Lua function */ |
1441 | lua_pushobject(lua_getresult(1)); /* push first result of the call */ | 1452 | lua_pushobject(lua_getresult(1)); /* push first result of the call */ |
1442 | lua_setglobal("a"); /* sets global variable 'a' */ | 1453 | lua_setglobal("a"); /* sets global variable 'a' */ |
@@ -1928,8 +1939,8 @@ See some examples below: | |||
1928 | --> x="apple and orange and lime" | 1939 | --> x="apple and orange and lime" |
1929 | 1940 | ||
1930 | t = {} | 1941 | t = {} |
1931 | gsub("first second word", "(%w%w*)", rawsettable, t) | 1942 | dummy, t.n = gsub("first second word", "(%w%w*)", rawsettable, t) |
1932 | --> t={"first", "second", "word"} | 1943 | --> t={"first", "second", "word"; n=3} |
1933 | \end{verbatim} | 1944 | \end{verbatim} |
1934 | 1945 | ||
1935 | 1946 | ||
@@ -2443,13 +2454,34 @@ the previous public versions of Lua, | |||
2443 | some differences had to be introduced. | 2454 | some differences had to be introduced. |
2444 | Here is a list of all these incompatibilities. | 2455 | Here is a list of all these incompatibilities. |
2445 | 2456 | ||
2457 | \subsection*{Incompatibilities with \Index{version 2.5}} | ||
2458 | \begin{itemize} | ||
2459 | \item | ||
2460 | The whole fallback mechanism has been replaced by tag methods. | ||
2461 | Nevertheless, the function \verb|setfallback| has been rewritten in | ||
2462 | a way that uses tag methods to fully emulate the old behavior | ||
2463 | of fallbacks. | ||
2464 | \item | ||
2465 | Tags now must be created with the function \verb|newtag|. | ||
2466 | Nevertheless, old user defined tags are still accepted | ||
2467 | (user defined tags must be positive; | ||
2468 | \verb|newtag| uses negative numbers). | ||
2469 | Tag methods cannot be set for such user defined tags, | ||
2470 | and fallbacks do not affect tags created by \verb|newtag|. | ||
2471 | \item | ||
2472 | Lua 2.5 accepts mixed comparisons of strings and numbers, | ||
2473 | like \verb|2<"12"|, giving weird results. | ||
2474 | Now this is an error. | ||
2475 | \item | ||
2476 | Character \verb|"-"| (hyphen) now is ``magic'' in pattern matching. | ||
2477 | \item | ||
2478 | Some API functions have been rewritten as macros. | ||
2479 | \end{itemize} | ||
2480 | |||
2446 | \subsection*{Incompatibilities with \Index{version 2.4}} | 2481 | \subsection*{Incompatibilities with \Index{version 2.4}} |
2447 | The whole I/O facilities have been rewritten. | 2482 | The whole I/O facilities have been rewritten. |
2448 | We strongly encourage programmers to adapt their code | 2483 | We strongly encourage programmers to adapt their code |
2449 | to this new version. | 2484 | to this new version. |
2450 | However, we are keeping the old version of the libraries | ||
2451 | in the distribution, | ||
2452 | to allow a smooth transition. | ||
2453 | The incompatibilities between the new and the old libraries are: | 2485 | The incompatibilities between the new and the old libraries are: |
2454 | \begin{itemize} | 2486 | \begin{itemize} |
2455 | \item The format facility of function \verb|write| has been supersed by | 2487 | \item The format facility of function \verb|write| has been supersed by |
@@ -2550,7 +2582,3 @@ Special care should be taken with macros like | |||
2550 | \end{document} | 2582 | \end{document} |
2551 | 2583 | ||
2552 | 2584 | ||
2553 | |||
2554 | |||
2555 | |||
2556 | |||