From 408af9f5aea23405744c81555d0a17b912cd9b51 Mon Sep 17 00:00:00 2001 From: Maurizio Monge Date: Sat, 7 Jul 2007 23:44:17 +0100 Subject: [PATCH] Updated lua to version 5.1.2. --- lua/COPYRIGHT | 2 +- lua/HISTORY | 2 +- lua/INSTALL | 9 +- lua/{Makefile.lua => Makefile} | 13 +- lua/README | 4 +- lua/doc/amazon.gif | Bin 0 -> 797 bytes lua/doc/contents.html | 51 ++++-- lua/doc/cover.png | Bin 0 -> 3305 bytes lua/doc/lua.css | 23 ++- lua/doc/manual.css | 7 + lua/doc/manual.html | 379 ++++++++++++++++++++++++----------------- lua/doc/readme.html | 14 +- lua/etc/README | 1 + lua/etc/lua.pc | 2 +- lua/etc/luavs.bat | 22 ++- lua/etc/strict.lua | 9 +- lua/src/Makefile | 9 +- lua/src/lbaselib.c | 10 +- lua/src/lcode.c | 44 +++-- lua/src/ldebug.c | 10 +- lua/src/lfunc.c | 6 +- lua/src/loadlib.c | 33 ++-- lua/src/loslib.c | 23 ++- lua/src/lparser.c | 4 +- lua/src/lstrlib.c | 4 +- lua/src/lua.h | 8 +- lua/src/luaconf.h | 4 +- lua/src/lvm.c | 10 +- lua/src/print.c | 6 +- 29 files changed, 443 insertions(+), 266 deletions(-) rename lua/{Makefile.lua => Makefile} (93%) create mode 100644 lua/doc/amazon.gif create mode 100644 lua/doc/cover.png create mode 100644 lua/doc/manual.css diff --git a/lua/COPYRIGHT b/lua/COPYRIGHT index 84d401b..a54a16e 100644 --- a/lua/COPYRIGHT +++ b/lua/COPYRIGHT @@ -9,7 +9,7 @@ For details and rationale, see http://www.lua.org/license.html . =============================================================================== -Copyright (C) 1994-2006 Lua.org, PUC-Rio. +Copyright (C) 1994-2007 Lua.org, PUC-Rio. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lua/HISTORY b/lua/HISTORY index d807a53..ce0c95b 100644 --- a/lua/HISTORY +++ b/lua/HISTORY @@ -14,7 +14,7 @@ HISTORY for Lua 5.1 API: + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer. + user supplies memory allocator (lua_open becomes lua_newstate). - + luaopen_* functionst must be called through Lua. + + luaopen_* functions must be called through Lua. Implementation: + new configuration scheme via luaconf.h. + incremental garbage collection. diff --git a/lua/INSTALL b/lua/INSTALL index 65f6f1e..17eb8ae 100644 --- a/lua/INSTALL +++ b/lua/INSTALL @@ -8,7 +8,10 @@ INSTALL for Lua 5.1 Building Lua on Unix systems should be very easy. First do "make" and see if your platform is listed. If so, just do "make xxx", where xxx is your platform name. The platforms currently supported are: - ansi bsd generic linux macosx mingw posix solaris + aix ansi bsd freebsd generic linux macosx mingw posix solaris + + If your platform is not listed, try the closest one or posix, generic, + ansi, in this order. See below for customization instructions and for instructions on how to build with other Windows compilers. @@ -81,8 +84,8 @@ INSTALL for Lua 5.1 compiler: library, luac.c print.c - If you use Visual Studio .NET, you can use etc/luavs.bat - in its "Command Prompt". + If you use Visual Studio .NET, you can use etc/luavs.bat in its + "Command Prompt". If all you want is to build the Lua interpreter, you may put all .c files in a single project, except for luac.c and print.c. Or just use etc/all.c. diff --git a/lua/Makefile.lua b/lua/Makefile similarity index 93% rename from lua/Makefile.lua rename to lua/Makefile index b3678b1..c5ec666 100644 --- a/lua/Makefile.lua +++ b/lua/Makefile @@ -9,7 +9,8 @@ PLAT= none # Where to install. The installation starts in the src directory, so take care # if INSTALL_TOP is not an absolute path. (Man pages are installed from the -# doc directory.) +# doc directory.) You may want to make these paths consistent with LUA_ROOT, +# LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). # INSTALL_TOP= /usr/local INSTALL_BIN= $(INSTALL_TOP)/bin @@ -37,7 +38,7 @@ RANLIB= ranlib # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= # Convenience platforms targets. -PLATS= aix ansi bsd generic linux macosx mingw posix solaris +PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris # What to install. TO_BIN= lua luac @@ -47,7 +48,7 @@ TO_MAN= lua.1 luac.1 # Lua version and release. V= 5.1 -R= 5.1.1 +R= 5.1.2 all: $(PLAT) @@ -119,11 +120,7 @@ lecho: @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' @echo "-- EOF" -# show what has changed since we unpacked -newer: - @$(FIND) . -newer MANIFEST -type f - # list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho newer +.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho # (end of Makefile) diff --git a/lua/README b/lua/README index f082d40..11b4dff 100644 --- a/lua/README +++ b/lua/README @@ -24,8 +24,8 @@ See HISTORY for a summary of changes since the last released version. * Installation ------------ Lua is implemented in pure ANSI C, and compiles unmodified in all known - platforms that have an ANSI C compiler. Under Unix, simply typing "make" - should work. See INSTALL for detailed instructions. + platforms that have an ANSI C compiler. In most Unix-like platforms, simply + do "make" with a suitable target. See INSTALL for detailed instructions. * Origin ------ diff --git a/lua/doc/amazon.gif b/lua/doc/amazon.gif new file mode 100644 index 0000000000000000000000000000000000000000..f2586d5765361bb8a33a72401449f3abdefe4e16 GIT binary patch literal 797 zcwPY=1LFKgNk%w1VOjtj0K^&q@9)h50%r{k3;+NBK0Y<5t#HiDnQw1j_x9wkua=aQ zf8O4{J3ExYz@^dAvgzr__o-L@ehvGQF7LT?@$1I#;Ij3_g2%_+^3u}mmw|9dEECm0Kc!X!@|#@3&?4Fr)=|m57&HqxlCDW&_KZ+1;`8vSj33YC_e@b zLW(B90kQ_n9Ds8N3z4jU4HiAyWz9`JYknO6suY&Mn*c`+`V13=EEIuKH*uwDKrGlz zo{tDTNaHR5yf%>5cyj}g-^zXgiM@QV=g%Gh303A)7B84EpbPvE-6X=O$DmxJ`b(9|4E82-m%Ds!U< zI=HL8TMx@{~>s4%C(a0wK8Wjd@n+|5vxOvSr(vuAh- z5-e0mzlK5u3lKm6pnB`22G3HYpfaDDC`;MbMg*4 b)M@9Pc;4WH3w-wJ=bwNED(Iksh5!INDePJ9 literal 0 HcwPel00001 diff --git a/lua/doc/contents.html b/lua/doc/contents.html index c1e4a99..01b069f 100644 --- a/lua/doc/contents.html +++ b/lua/doc/contents.html @@ -2,31 +2,59 @@ Lua 5.1 reference manual - contents - +

-Lua -Reference manual for Lua 5.1 + +Lua 5.1 Reference Manual

+This is an online version of +
+ + + +Lua 5.1 Reference Manual +
by R. Ierusalimschy, L. H. de Figueiredo, W. Celes +
Lua.org, August 2006 +
ISBN 85-903798-3-3 +
+[Buy from Amazon] +
+
+

+ +Buy a paper copy and +help to support +the Lua project. +

+ +startcontents · index +· +errata


+ +Copyright © 2006-2007 Lua.org, PUC-Rio. +Freely available under the terms of the +Lua license. +

Contents

Index

- +
- - -
+

Lua functions

_G
_VERSION
@@ -146,7 +173,7 @@ Reference manual for Lua 5.1 xpcall
+

 

coroutine.create
coroutine.resume
@@ -254,7 +281,7 @@ Reference manual for Lua 5.1 table.sort
+

C API

lua_Alloc
lua_CFunction
@@ -419,10 +446,10 @@ Reference manual for Lua 5.1
Last update: -Tue Jun 6 14:55:31 BRT 2006 +Fri Mar 23 08:33:19 BRT 2007 diff --git a/lua/doc/cover.png b/lua/doc/cover.png new file mode 100644 index 0000000000000000000000000000000000000000..2dbb198123f03a7250bfa57c8253739962d69afb GIT binary patch literal 3305 zcwPbN3>Nc=P)V>IGcGYOVIUw=dB=aTYv^*htKxL4xjCf9X{I|EBQ!hu?+M>5oT>TE}0ye97P9R7S8qXycMFZ&6rBQl2xq6d5z1RT?1tMWggH(oGfxZ3MRwMW* zhWcm<0o+gGDNJLnwySJIYqTbnA(cT&JjHAh%b?&;aM%-PVunbF`4oU{acLCOU~~ed z=Xys9YZpo#i8bMPc#43D)u4sMGKqI^_da6LW&~0K*cO4+ z_PRNFEtj+pK65RYy#Eh+iK_)|A>ml%LRW(G?uWEPuP@)V__gB&q{E^1Drx0`;n)|1&{JZ#-e7eMcd1S~0(ChdB8 zS0!Ap-8R#X^0X5R7@pQ0wmH~jKhYj`l%C2tznfmz5?4vXD&s9-{r%L{8o|B1n{hn> zX-7F)1C|g{Fjw^QO3xSEM8WF{nF8))ijLB@AziK0j<-dAU&NHQAw-4j8oelO%2Dg_ z37hiyuBd>qbbcrr0xb~*rLW9q2cyBcq8kgCW9j_Jd}=!9R2g|I=9{KHXtr2}hFHKH zPZ!2Bg|$47mFu;Duqg$YQfQ4vD~-}9t!+atHYg~SbM=?ElxgB&vnLeLny@Jo1@}ra zw-%pO_5&GLRc)GAp8w;^w0pr+)}6{$xN2*=h1(z&s0B5@zOQ2Cj<++EgPm6D*KdLp^Jc$%i(A&wq1mn{*M;Pu$%2I-|s;8_q`68Jd zLJ$dITeas|8_h>+9GB??ksz(jj7@SsNq-j_f;Mf@l8W*L-v0vui)W9N64OhM7aV?n zo{!IxNC9-U@zPPgc8EYtsn)ggZ<}BOc#01{#gH6*gjm!cMXYMFiJ5! z$8SI7^a#mxl?1n2Bwr+veIkV`2fdd@*by0Naq>o!4A;Y!nrTV7gj#l-OAs* zvT_zQj8DKsyvuDrVn7=m8 z&;O0T{VN_DroW5Nu5jxvQZU%ZlLv@3)#xH@icfQd{R930nH<0P?=qQ<5s3ufc;l~s z^rLTdbhJn*9LK$Q@z$Gf{__VPoYQ~*AN<{S=xOJbXHXg;Sjdpd5Nq1FU!ZP(bkV*K z5BX<_uE(!VaN&B59T#f)0@ixmc3_}Kkful!<-+AYa=bk&rr9RA^GG2#cH|o2Jo3*;M^C0Z#I`l`S@(jjq^e|^t7&J*rAXei$y>%zrcxe zzKVokW{ylvDyoN%5F8rxOC(&6ljrfOA4aT&iHZA4RiB-iOg@n)*W;YNOgdZoU&C~Q zYvZ-d>YDjzn4Be*DQQDPBE@KZ$^kz7@cjMzsnv(*TI*A%M(*BC03b*t8J+ZR_jR(6 zttGy#T|b&jH^^6g-e(O?=xBjqSdb8D)Kd$tjjQa}6Izo*l=AOHBZzP@%TWj?-Z2yYmt`$ryp=SGWT>kg8zlLgEEs(4iVm;4Q>56I~!I5E_!W;Hjvwox?Uqoq) z@&EyI&Dg6UFbzN8)tb&2Y&=@c`Y|NW9`Pe8A!)AFN8A)Nk)Urp8ZM1e+_>zsWuw3Gwz#h*<|ZTYWyBV&rD^+OOrPXFnaE_T4H3gMI7NJvIPCeSU~lbZRURtjFJ3 zOtR_n9@p1NEV@-WX*<9pdwg@TE&lANPj7A1!>6YW%k<@shB-1^pOm#iGtfhChrf42 zsVsLR)XYafILOn7Dzbrs7oH##T<@vPK}ueH!cSN`F26lfqvKnrf9<;5xmTWYf?eG_ zeX!9}PBYlclLvflOw3@&T9Q?4=KSZAi+(6#NWSqr9j%R{qzT%*cARj9+M7Z={YZ`Z zkUIHTCXWs=UG`IipsSVd{5f`@zJAseNAl`14({FT2Xbx{9&lM)RVZ}_{lVes;w@a^N+fz49V zNXZM2^W9f`Rcp=JFX(8gt1f+0`B4G4?=d#PKzC_k7?Qz0y4x6=B$uz#sndjmeCtJC zJ5DgL%uYf!d*Z&jYQX0B2)f!R6lrVmT}CPC?c~T_GI?g_YxBM}hQWc|eD9k)^C*Fe z?D1?8AQoMD2D71Pn?G+{G@(R_)@FY(T|5yQo#5loxID%}wj5$qei{Hm5DK!lj~Ach z@X#`~XwB_uPF>*Z&(R#ISEvU#FA)Nz`TQED$+JgFvs?%)ll=n>_cNbnY=Y|(+?{11 zL&3o^iG=8GW2ldzK00F6PjxbRUOh&1<7lUfP!D<@?6{2FWT>x{XIvqi2CY#FPoWf2 zVo0P!tZu2v=D9u1zJZdTwyAHS9=M*uGC8uBNRUK|GgrvwmU;C8q`)+=EkZW7g=ru~ z6RQpkqkiq>Ru+?vAkXbSVK7dSLn?*gy_ zjjN{!SUh^+iEFRr=;K9At8qQ=c=~M}HT#)sT^Fg(`nT>?C{y%_^R>wBb&6$ nh%8`n`v3p{2XskIMF-Xh6%#iZwFs;u00000NkvXXu0mjfd@Wp4 literal 0 HcwPel00001 diff --git a/lua/doc/lua.css b/lua/doc/lua.css index f007211..039cf11 100644 --- a/lua/doc/lua.css +++ b/lua/doc/lua.css @@ -2,16 +2,24 @@ body { color: #000000 ; background-color: #FFFFFF ; font-family: sans-serif ; + text-align: justify ; + margin-right: 20px ; + margin-left: 20px ; +} + +h1, h2, h3, h4 { + font-weight: normal ; + font-style: italic ; } a:link { color: #000080 ; - background-color: #FFFFFF ; + background-color: inherit ; text-decoration: none ; } a:visited { - background-color: #FFFFFF ; + background-color: inherit ; text-decoration: none ; } @@ -20,3 +28,14 @@ a:link:hover, a:visited:hover { background-color: #E0E0FF ; } +a:link:active, a:visited:active { + color: #FF0000 ; +} + +hr { + border: 0 ; + height: 1px ; + color: #a0a0a0 ; + background-color: #a0a0a0 ; +} + diff --git a/lua/doc/manual.css b/lua/doc/manual.css new file mode 100644 index 0000000..93f1ab2 --- /dev/null +++ b/lua/doc/manual.css @@ -0,0 +1,7 @@ +h3 code { + font-family: inherit ; +} + +pre { + font-size: 105% ; +} diff --git a/lua/doc/manual.html b/lua/doc/manual.html index 16fbb36..6b137ff 100644 --- a/lua/doc/manual.html +++ b/lua/doc/manual.html @@ -4,6 +4,7 @@ Lua 5.1 Reference Manual + @@ -17,10 +18,16 @@ Lua 5.1 Reference Manual by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes

-Copyright -© 2006 Lua.org, PUC-Rio. All rights reserved. +Copyright © 2006-2007 Lua.org, PUC-Rio. +Freely available under the terms of the +Lua license.


+

+ +contents +· +index

@@ -71,7 +78,7 @@ this document is dry in places. For a discussion of the decisions behind the design of Lua, see the technical papers available at Lua's web site. For a detailed introduction to programming in Lua, -see Roberto's book, Programming in Lua. +see Roberto's book, Programming in Lua (Second Edition). @@ -390,8 +397,8 @@ Name denotes identifiers, as defined in §2.1.

-Variables are assumed to be global unless explicitly declared local -(see §2.4.7). +Any variable is assumed to be global unless explicitly declared +as a local (see §2.4.7). Local variables are lexically scoped: local variables can be freely accessed by functions defined inside their scope (see §2.6). @@ -708,18 +715,18 @@ third exp. More precisely, a for statement like

-     for var = e1, e2, e3 do block end
+     for v = e1, e2, e3 do block end
 

is equivalent to the code:

      do
-       local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
-       if not (_var and _limit and _step) then error() end
-       while (_step>0 and _var<=_limit) or (_step<=0 and _var>=_limit) do
-         local var = _var
+       local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
+       if not (var and limit and step) then error() end
+       while (step > 0 and var <= limit) or (step <= 0 and var >= limit) do
+         local v = var
          block
-         _var = _var + _step
+         var = var + step
        end
      end
 

@@ -734,7 +741,7 @@ They must all result in numbers.

  • -_var, _limit, and _step are invisible variables. +var, limit, and step are invisible variables. The names are here for explanatory purposes only.
  • @@ -748,10 +755,10 @@ You can use break to exit a for loop.
  • -The loop variable var is local to the loop; +The loop variable v is local to the loop; you cannot use its value after the for ends or is broken. -If you need the value of the loop variable var, -then assign it to another variable before breaking or exiting the loop. +If you need this value, +assign it to another variable before breaking or exiting the loop.
  • @@ -770,18 +777,18 @@ The generic for loop has the following syntax: A for statement like
    -     for var_1, ···, var_n in explist do block end
    +     for var_1, ···, var_n in explist do block end
     

    is equivalent to the code:

          do
    -       local _f, _s, _var = explist
    +       local f, s, var = explist
            while true do
    -         local var_1, ···, var_n = _f(_s, _var)
    -         _var = var_1
    -         if _var == nil then break end
    -         block
    +         local var_1, ···, var_n = f(s, var)
    +         var = var_1
    +         if var == nil then break end
    +         block
            end
          end
     

    @@ -790,13 +797,14 @@ Note the following:

    • -explist is evaluated only once. +explist is evaluated only once. Its results are an iterator function, -a state, and an initial value for the first iterator variable. +a state, +and an initial value for the first iterator variable.
    • -_f, _s, and _var are invisible variables. +f, s, and var are invisible variables. The names are here for explanatory purposes only.
    • @@ -805,7 +813,7 @@ You can use break to exit a for loop.
    • -The loop variables var_i are local to the loop; +The loop variables var_i are local to the loop; you cannot use their values after the for ends. If you need these values, then assign them to other variables before breaking or exiting the loop. @@ -882,8 +890,8 @@ function definitions are explained in §2.5.9; function calls are explained in §2.5.8; table constructors are explained in §2.5.7. Vararg expressions, -denoted by three dots ('...'), can only be used inside -vararg functions; +denoted by three dots ('...'), can only be used when +directly inside a vararg function; they are explained in §2.5.9. @@ -902,13 +910,13 @@ If the expression is used as a statement (see §2.4.6) (only possible for function calls), then its return list is adjusted to zero elements, thus discarding all returned values. -If the expression is used inside another expression -or in the middle of a list of expressions, -then its result list is adjusted to one element, -thus discarding all values except the first one. -If the expression is used as the last element of a list of expressions, -then no adjustment is made, -unless the call is enclosed in parentheses. +If the expression is used as the last (or the only) element +of a list of expressions, +then no adjustment is made +(unless the call is enclosed in parentheses). +In all other contexts, +Lua adjusts the result list to one element, +discarding all values except the first one.

      @@ -917,17 +925,18 @@ Here are some examples:

            f()                -- adjusted to 0 results
            g(f(), x)          -- f() is adjusted to 1 result
      -     g(x, f())          -- g gets x plus all values returned by f()
      +     g(x, f())          -- g gets x plus all results from f()
            a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)
            a,b = ...          -- a gets the first vararg parameter, b gets
      -                        -- the second (both a and b may get nil if there is
      -                        -- no corresponding vararg parameter)
      +                        -- the second (both a and b may get nil if there
      +                        -- is no corresponding vararg parameter)
      +     
            a,b,c = x, f()     -- f() is adjusted to 2 results
            a,b,c = f()        -- f() is adjusted to 3 results
      -     return f()         -- returns all values returned by f()
      +     return f()         -- returns all results from f()
            return ...         -- returns all received vararg parameters
      -     return x,y,f()     -- returns x, y, and all values returned by f()
      -     {f()}              -- creates a list with all values returned by f()
      +     return x,y,f()     -- returns x, y, and all results from f()
      +     {f()}              -- creates a list with all results from f()
            {...}              -- creates a list with all vararg parameters
            {f(), nil}         -- f() is adjusted to 1 result
       
      @@ -1543,8 +1552,7 @@ you must use the C API for that.

      Tables and userdata have individual metatables -(although multiple tables and userdata can share -a same table as their metatable); +(although multiple tables and userdata can share their metatables); values of all other types share one single metatable per type. So, there is one single metatable for all numbers, and for all strings, etc. @@ -1592,6 +1600,7 @@ This should be read as

            rawget(getmetatable(obj) or {}, event)
       

      + That is, the access to a metamethod does not invoke other metamethods, and the access to objects with no metatables does not fail (it simply results in nil). @@ -2077,7 +2086,7 @@ A table with both weak keys and weak values allows the collection of both keys and values. In any case, if either the key or the value is collected, the whole pair is removed from the table. -The weakness of a table is controlled by the value of the +The weakness of a table is controlled by the __mode field of its metatable. If the __mode field is a string containing the character 'k', the keys in the table are weak. @@ -2156,8 +2165,8 @@ arguments passed to coroutine.resume -The coroutine.wrap function creates a coroutine, -just like coroutine.create, +Like coroutine.create, +the coroutine.wrap function also creates a coroutine, but instead of returning the coroutine itself, it returns a function that, when called, resumes the coroutine. Any arguments passed to this function @@ -2198,6 +2207,7 @@ When you run it, it produces the following output:

            co-body 1       10
            foo     2
      +     
            main    true    4
            co-body r
            main    true    11      -9
      @@ -2268,7 +2278,7 @@ then index 1 represents the first element
       and
       index n represents the last element;
       index -1 also represents the last element
      -(that is, the element at the top)
      +(that is, the element at the top)
       and index -n represents the first element.
       We say that an index is valid
       if it lies between 1 and the stack top
      @@ -2473,21 +2483,25 @@ Lua assumes that the allocator never fails when
       
       

      Here is a simple implementation for the allocator function. -It is used in the auxiliary library by lua_newstate. +It is used in the auxiliary library by luaL_newstate.

      -     static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
      -       (void)ud;     /* not used */
      -       (void)osize;  /* not used */
      +     static void *l_alloc (void *ud, void *ptr, size_t osize,
      +                                                size_t nsize) {
      +       (void)ud;  (void)osize;  /* not used */
              if (nsize == 0) {
      -         free(ptr);  /* ANSI requires that free(NULL) has no effect */
      +         free(ptr);
                return NULL;
              }
              else
      -         /* ANSI requires that realloc(NULL, size) == malloc(size) */
                return realloc(ptr, nsize);
            }
      -
      +

      +This code assumes +that free(NULL) has no effect and that +realloc(NULL, size) is equivalent to malloc(size). +ANSI C ensures both behaviors. + @@ -2557,14 +2571,14 @@ equivalent to this Lua code: Here it is in C:

      -     lua_getfield(L, LUA_GLOBALSINDEX, "f");          /* function to be called */
      -     lua_pushstring(L, "how");                                 /* 1st argument */
      -     lua_getfield(L, LUA_GLOBALSINDEX, "t");            /* table to be indexed */
      -     lua_getfield(L, -1, "x");                 /* push result of t.x (2nd arg) */
      -     lua_remove(L, -2);                           /* remove 't' from the stack */
      -     lua_pushinteger(L, 14);                                   /* 3rd argument */
      -     lua_call(L, 3, 1);         /* call function with 3 arguments and 1 result */
      -     lua_setfield(L, LUA_GLOBALSINDEX, "a");        /* set global variable 'a' */
      +     lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
      +     lua_pushstring(L, "how");                        /* 1st argument */
      +     lua_getfield(L, LUA_GLOBALSINDEX, "t");   /* table to be indexed */
      +     lua_getfield(L, -1, "x");        /* push result of t.x (2nd arg) */
      +     lua_remove(L, -2);                  /* remove 't' from the stack */
      +     lua_pushinteger(L, 14);                          /* 3rd argument */
      +     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */
      +     lua_setfield(L, LUA_GLOBALSINDEX, "a");        /* set global 'a' */
       

      Note that the code above is "balanced": at its end, the stack is back to its original configuration. @@ -2611,7 +2625,7 @@ of numerical arguments and returns their average and sum: int i; for (i = 1; i <= n; i++) { if (!lua_isnumber(L, i)) { - lua_pushstring(L, "incorrect argument to function 'average'"); + lua_pushstring(L, "incorrect argument"); lua_error(L); } sum += lua_tonumber(L, i); @@ -2723,7 +2737,7 @@ to write them.

      The value returned is the error code returned by the last call to the writer; -0 means no errors. +0 means no errors.

      @@ -2814,7 +2828,7 @@ The function returns the previous value of the pause.

    • LUA_GCSETSTEPMUL: -sets arg/100 as the new value for the step multiplier of +sets data/100 as the new value for the step multiplier of the collector (see §2.10). The function returns the previous value of the step multiplier.
    • @@ -2942,7 +2956,7 @@ The type used by the Lua API to represent integral values.

      By default it is a ptrdiff_t, -which is usually the largest integral type the machine handles +which is usually the largest signed integral type the machine handles "comfortably". @@ -2954,7 +2968,7 @@ which is usually the largest integral type the machine handles

      Returns 1 if the value at the given acceptable index has type boolean, -and 0 otherwise. +and 0 otherwise. @@ -2965,7 +2979,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a C function, -and 0 otherwise. +and 0 otherwise. @@ -2976,7 +2990,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a function -(either C or Lua), and 0 otherwise. +(either C or Lua), and 0 otherwise. @@ -2987,7 +3001,7 @@ Returns 1 if the value at the given acceptable index is a function

      Returns 1 if the value at the given acceptable index is a light userdata, -and 0 otherwise. +and 0 otherwise. @@ -2998,7 +3012,32 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is nil, -and 0 otherwise. +and 0 otherwise. + + + + + +


      lua_isnone

      +
      int lua_isnone (lua_State *L, int index);
      + +

      +Returns 1 if the the given acceptable index is not valid +(that is, it refers to an element outside the current stack), +and 0 otherwise. + + + + + +


      lua_isnoneornil

      +
      int lua_isnoneornil (lua_State *L, int index);
      + +

      +Returns 1 if the the given acceptable index is not valid +(that is, it refers to an element outside the current stack) +or if the value at this index is nil, +and 0 otherwise. @@ -3010,7 +3049,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, -and 0 otherwise. +and 0 otherwise. @@ -3022,7 +3061,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a string or a number (which is always convertible to a string), -and 0 otherwise. +and 0 otherwise. @@ -3033,7 +3072,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a table, -and 0 otherwise. +and 0 otherwise. @@ -3044,7 +3083,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a thread, -and 0 otherwise. +and 0 otherwise. @@ -3055,7 +3094,7 @@ and 0 otherwise.

      Returns 1 if the value at the given acceptable index is a userdata -(either full or light), and 0 otherwise. +(either full or light), and 0 otherwise. @@ -3113,8 +3152,8 @@ and loads it accordingly (see program luac).

      -lua_load uses a user-supplied reader function to read the chunk -(see lua_Reader). +The lua_load function uses a user-supplied reader function +to read the chunk (see lua_Reader). The data argument is an opaque value passed to the reader function. @@ -3183,7 +3222,7 @@ and returns this address.

      -Userdata represents C values in Lua. +Userdata represent C values in Lua. A full userdata represents a block of memory. It is an object (like a table): you must create it, it can have its own metatable, @@ -3219,10 +3258,12 @@ A typical traversal looks like this: /* table is in the stack at index 't' */ lua_pushnil(L); /* first key */ while (lua_next(L, t) != 0) { - /* 'key' is at index -2 and 'value' at index -1 */ + /* uses 'key' (at index -2) and 'value' (at index -1) */ printf("%s - %s\n", - lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); - lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */ + lua_typename(L, lua_type(L, -2)), + lua_typename(L, lua_type(L, -1))); + /* removes 'value'; keeps 'key' for next iteration */ + lua_pop(L, 1); } @@ -3270,7 +3311,7 @@ for other values, it is 0.


      lua_pcall

      -
      lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
      +
      int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);

      Calls a function in protected mode. @@ -3396,9 +3437,11 @@ and return its results (see lua_CFunction<

      -The call lua_pushcfunction(L, f) is equivalent to -lua_pushcclosure(L, f, 0). +lua_pushcfunction is defined as a macro: +

      +     #define lua_pushcfunction(L,f)  lua_pushcclosure(L,f,0)
      +
      @@ -3455,7 +3498,7 @@ Pushes a light userdata onto the stack.

      -Userdata represents C values in Lua. +Userdata represent C values in Lua. A light userdata represents a pointer. It is a value (like a number): you do not create it, it has no individual metatable, @@ -3642,14 +3685,17 @@ The reader function may return pieces of any size greater than zero.


      lua_register

      -
      void lua_register (lua_State *L, const char *name, lua_CFunction f);
      +
      void lua_register (lua_State *L,
      +                   const char *name,
      +                   lua_CFunction f);

      Sets the C function f as the new value of global name. It is defined as a macro:

      -     #define lua_register(L,n,f)  (lua_pushcfunction(L, f), lua_setglobal(L, n))
      +     #define lua_register(L,n,f) \
      +            (lua_pushcfunction(L, f), lua_setglobal(L, n))
       
      @@ -3905,8 +3951,7 @@ it is truncated in some non-specified way.
      const char *lua_tolstring (lua_State *L, int index, size_t *len);

      -Converts the Lua value at the given acceptable index to a string -(const char*). +Converts the Lua value at the given acceptable index to a C string. If len is not NULL, it also sets *len with the string length. The Lua value must be a string or a number; @@ -3937,7 +3982,7 @@ will be valid after the corresponding value is removed from the stack.

      Converts the Lua value at the given acceptable index -to a number (see lua_Number). +to the C type lua_Number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tonumber returns 0. @@ -4054,7 +4099,7 @@ and the data parameter supplied to lua_du

      The writer returns an error code: -0 means no errors; +0 means no errors; any other value means an error and stops lua_dump from calling the writer again. @@ -4279,8 +4324,8 @@ a value to be pushed on the stack:

    • 'S': -fills in the fields source, linedefined, -lastlinedefined, what, and short_src; +fills in the fields source, short_src, +linedefined, lastlinedefined, and what;
    • 'l': fills in the field currentline; @@ -4313,7 +4358,7 @@ This function returns 0 on error

      lua_getlocal

      -
      const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
      +
      const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);

      Gets information about a local variable of a given activation record. @@ -4424,14 +4469,14 @@ this execution occurs without any calls to hooks.


      lua_sethook

      -
      int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
      +
      int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);

      Sets the debugging hook function.

      -func is the hook function. +Argument f is the hook function. mask specifies on which events the hook will be called: it is formed by a bitwise or of the constants LUA_MASKCALL, @@ -4475,7 +4520,7 @@ A hook is disabled by setting mask to zero.


      lua_setlocal

      -
      const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
      +
      const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);

      Sets the value of a local variable of a given activation record. @@ -4500,11 +4545,11 @@ the number of active local variables.

      Sets the value of a closure's upvalue. -Parameters funcindex and n are as in lua_getupvalue -(see lua_getupvalue). It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack. +Parameters funcindex and n are as in the lua_getupvalue +(see lua_getupvalue).

      @@ -4588,9 +4633,9 @@ The string may contain embedded zeros.

      void luaL_addsize (luaL_Buffer *B, size_t n);

      -Adds a string of length n previously copied to the -buffer area (see luaL_prepbuffer) to the buffer B -(see luaL_Buffer). +Adds to the buffer B (see luaL_Buffer) +a string of length n previously copied to the +buffer area (see luaL_prepbuffer). @@ -4631,7 +4676,7 @@ which is the value to be added to the buffer.


      luaL_argcheck

      void luaL_argcheck (lua_State *L,
                           int cond,
      -                    int numarg,
      +                    int narg,
                           const char *extramsg);

      @@ -4640,21 +4685,21 @@ If not, raises an error with the following message, where func is retrieved from the call stack:

      -     bad argument #<numarg> to <func> (<extramsg>)
      +     bad argument #<narg> to <func> (<extramsg>)
       

      luaL_argerror

      -
      int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
      +
      int luaL_argerror (lua_State *L, int narg, const char *extramsg);

      Raises an error with the following message, where func is retrieved from the call stack:

      -     bad argument #<numarg> to <func> (<extramsg>)
      +     bad argument #<narg> to <func> (<extramsg>)
       

      @@ -5079,9 +5124,10 @@ with tname in the registry.

      lua_State *luaL_newstate (void);

      -Creates a new Lua state, calling lua_newstate with an -allocation function based on the standard C realloc function -and setting a panic function (see lua_atpanic) that prints +Creates a new Lua state. +It calls lua_newstate with an +allocator based on the standard C realloc function +and then sets a panic function (see lua_atpanic) that prints an error message to the standard error output in case of fatal errors. @@ -5119,7 +5165,9 @@ Otherwise, raises an error.


      luaL_optinteger

      -
      lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer d);
      +
      lua_Integer luaL_optinteger (lua_State *L,
      +                             int narg,
      +                             lua_Integer d);

      If the function argument narg is a number, @@ -5183,7 +5231,9 @@ Otherwise, raises an error.


      luaL_optstring

      -
      const char *luaL_optstring (lua_State *L, int narg, const char *d);
      +
      const char *luaL_optstring (lua_State *L,
      +                            int narg,
      +                            const char *d);

      If the function argument narg is a string, @@ -5285,7 +5335,7 @@ it simply registers all functions in the list l

      When called with a non-null libname, -creates a new table t, +luaL_register creates a new table t, sets it as the value of the global variable libname, sets it as the value of package.loaded[libname], and registers on it all functions in the list l. @@ -5316,14 +5366,14 @@ Returns the name of the type of the value at index idx.

      int luaL_typerror (lua_State *L, int narg, const char *tname);

      -Generates an error with a message like +Generates an error with a message like the following:

      -     <location>: bad argument <narg> to <function> (<tname> expected, got <realt>)
      +     location: bad argument narg to 'func' (tname expected, got rt)
       

      -where <location> is produced by luaL_where, -<function> is the name of the current function, -and <realt> is the type name of the actual argument. +where location is produced by luaL_where, +func is the name of the current function, +and rt is the type name of the actual argument. @@ -5354,7 +5404,11 @@ If ref is LUA_NOREF or Pushes onto the stack a string identifying the current position of the control at level lvl in the call stack. -Typically this string has the format <chunkname>:<currentline>:. +Typically this string has the following format: + +

      +     chunkname:currentline:
      +

      Level 0 is the running function, level 1 is the function that called the running function, etc. @@ -5413,9 +5467,8 @@ or as methods of its objects.

      To have access to these libraries, -the C host program must call -luaL_openlibs, -which open all standard libraries. +the C host program should call the luaL_openlibs function, +which opens all standard libraries. Alternatively, it can open them individually by calling luaopen_base (for the basic library), @@ -5547,7 +5600,7 @@ nor vice-versa.

      -


      getfenv (f)

      +

      getfenv ([f])

      Returns the current environment in use by the function. f can be a Lua function or a number that specifies the function at that stack level: @@ -5589,10 +5642,6 @@ will iterate over the pairs (1,t[1]), (2,t[2]), &middo up to the first integer key absent from the table. -

      -See next for the caveats of modifying the table during its traversal. - -

      @@ -5704,7 +5753,8 @@ will iterate over all key–value pairs of table t.

      -See next for the caveats of modifying the table during its traversal. +See function next for the caveats of modifying +the table during its traversal. @@ -5911,7 +5961,7 @@ The current contents of this variable is "Lua 5.1".

      -This function is similar to pcall, +This function is similar to pcall, except that you can set a new error handler. @@ -6101,7 +6151,7 @@ where each option is a function to be applied over the module.

      Loads the given module. -The function starts by looking into the table package.loaded +The function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname]. @@ -6156,7 +6206,7 @@ with each submodule keeping its original open function. Once a loader is found, require calls the loader with a single argument, modname. If the loader returns any value, -require assigns it to package.loaded[modname]. +require assigns the returned value to package.loaded[modname]. If the loader returns no value and has not assigned any value to package.loaded[modname], then require assigns true to this entry. @@ -6190,6 +6240,7 @@ using the environment variable LUA_CPATH +


      package.loaded

      @@ -6426,7 +6477,8 @@ whereas q and s expect a string.

      This function does not accept string values -containing embedded zeros. +containing embedded zeros, +except as arguments to the q option. @@ -6436,9 +6488,6 @@ containing embedded zeros. Returns an iterator function that, each time it is called, returns the next captures from pattern over string s. - - -

      If pattern specifies no captures, then the whole match is produced in each call. @@ -6465,6 +6514,11 @@ given string into a table: end +

      +For this function, a '^' at the start of a pattern does not +work as an anchor, as this would prevent the iteration. + +

      @@ -6540,7 +6594,7 @@ Here are some examples: --> x="4+5 = 9" local t = {name="lua", version="5.1"} - x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t) + x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) --> x="lua-5.1.tar.gz" @@ -6824,7 +6878,8 @@ we mean the result of the length operator.


      table.concat (table [, sep [, i [, j]]])

      -Returns table[i]..sep..table[i+1] ··· sep..table[j]. +Given an array where all elements are strings or numbers, +returns table[i]..sep..table[i+1] ··· sep..table[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table. @@ -7122,7 +7177,7 @@ the integral part of x and the fractional part of x.

      -The value PI. +The value of pi. @@ -7266,7 +7321,8 @@ three predefined file descriptors with their usual meanings from C:

      Unless otherwise stated, all I/O functions return nil on failure -(plus an error message as a second result) +(plus an error message as a second result and +a system-dependent error code as a third result) and some value different from nil on success. @@ -7331,7 +7387,7 @@ it returns nil (to finish the loop) and automatically closes the file.

      -The call io.lines() (without a file name) is equivalent +The call io.lines() (with no file name) is equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends. @@ -7381,7 +7437,7 @@ Similar to io.input, but operates over

      -


      io.popen ([prog [, mode]])

      +

      io.popen (prog [, mode])

      @@ -7596,7 +7652,7 @@ or there is any input from some special files

    -For the last two cases, sizes +For the last two cases, size specifies the size of the buffer, in bytes. The default is an appropriate size. @@ -7657,7 +7713,7 @@ Otherwise, date formats the current time. If format starts with '!', then the date is formatted in Coordinated Universal Time. After this optional character, -if format is *t, +if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), @@ -7667,7 +7723,7 @@ and isdst (daylight saving flag, a boolean).

    -If format is not *t, +If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function strftime. @@ -7772,6 +7828,13 @@ or nil if the request cannot be honored.

    +If locale is the empty string, +the current locate is set to an implementation-defined native locale. +If locate is the string "C", +the current locate is set to the standard C locale. + + +

    When called with nil as the first argument, this function only returns the name of the current locale for the given category. @@ -7921,7 +7984,8 @@ valid lines.

    For instance, the expression debug.getinfo(1,"n").name returns a name of the current function, if a reasonable name can be found, -and debug.getinfo(print) returns a table with all available information +and the expression debug.getinfo(print) +returns a table with all available information about the print function. @@ -8080,15 +8144,16 @@ Otherwise, it returns the name of the upvalue.

    -


    debug.traceback ([thread,] [message])

    +

    debug.traceback ([thread,] [message] [, level])

    Returns a string with a traceback of the call stack. An optional message string is appended -at the beginning of the traceback. -This function is typically used with xpcall to produce -better error messages. +at the beginning of the traceback. +An optional level number tells at which level +to start the traceback +(default is 1, the function calling traceback). @@ -8232,7 +8297,7 @@ is a more portable solution.)

    7 - Incompatibilities with the Previous Version

    -Here we list the incompatibilities that may be found when moving a program +Here we list the incompatibilities that you may found when moving a program from Lua 5.0 to Lua 5.1. You can avoid most of the incompatibilities compiling Lua with appropriate options (see file luaconf.h). @@ -8247,7 +8312,7 @@ all these compatibility options will be removed in the next version of Lua.

  • The vararg system changed from the pseudo-argument arg with a table with the extra arguments to the vararg expression. -(Option LUA_COMPAT_VARARG in luaconf.h.) +(See compile-time option LUA_COMPAT_VARARG in luaconf.h.)
  • @@ -8259,7 +8324,7 @@ variables of the for statement and for the repeat statement. The long string/long comment syntax ([[string]]) does not allow nesting. You can use the new syntax ([=[string]=]) in these cases. -(Option LUA_COMPAT_LSTR in luaconf.h.) +(See compile-time option LUA_COMPAT_LSTR in luaconf.h.)
  • @@ -8272,7 +8337,7 @@ You can use the new syntax ([=[string]=]) in these cases.
  • Function string.gfind was renamed string.gmatch. -(Option LUA_COMPAT_GFIND) +(See compile-time option LUA_COMPAT_GFIND in luaconf.h.)
  • @@ -8288,17 +8353,17 @@ Function table.setn was deprecated. Function table.getn corresponds to the new length operator (#); use the operator instead of the function. -(Option LUA_COMPAT_GETN) +(See compile-time option LUA_COMPAT_GETN in luaconf.h.)
  • Function loadlib was renamed package.loadlib. -(Option LUA_COMPAT_LOADLIB) +(See compile-time option LUA_COMPAT_LOADLIB in luaconf.h.)
  • Function math.mod was renamed math.fmod. -(Option LUA_COMPAT_MOD) +(See compile-time option LUA_COMPAT_MOD in luaconf.h.)
  • @@ -8446,10 +8511,10 @@ Here is the complete syntax of Lua in extended BNF.
    Last update: -Mon Jun 5 17:05:27 BRT 2006 +Mon Mar 26 12:59:26 BRT 2007 diff --git a/lua/doc/readme.html b/lua/doc/readme.html index db20a69..28b1d14 100644 --- a/lua/doc/readme.html +++ b/lua/doc/readme.html @@ -4,7 +4,7 @@ - +

    @@ -12,8 +12,9 @@ Documentation

    +This is the documentation included in the source distribution of Lua 5.1.2. + +Lua's +official web site +contains updated documentation, +especially the +reference manual. +

    +


    Last update: -Wed Sep 7 12:57:50 BRST 2005 +Fri Mar 23 14:19:36 BRT 2007 diff --git a/lua/etc/README b/lua/etc/README index ad9ca6a..5149fc9 100644 --- a/lua/etc/README +++ b/lua/etc/README @@ -20,6 +20,7 @@ lua.pc luavs.bat Script to build Lua under "Visual Studio .NET Command Prompt". + Run it from the toplevel as etc\luavs.bat. min.c A minimal Lua interpreter. diff --git a/lua/etc/lua.pc b/lua/etc/lua.pc index 21a16ba..03a2e68 100644 --- a/lua/etc/lua.pc +++ b/lua/etc/lua.pc @@ -5,7 +5,7 @@ # grep '^V=' ../Makefile V= 5.1 # grep '^R=' ../Makefile -R= 5.1.1 +R= 5.1.2 # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' prefix= /usr/local diff --git a/lua/etc/luavs.bat b/lua/etc/luavs.bat index eea175e..6b1120b 100644 --- a/lua/etc/luavs.bat +++ b/lua/etc/luavs.bat @@ -1,7 +1,15 @@ -cd src -cl /O2 /W3 /c /DLUA_BUILD_AS_DLL l*.c -del lua.obj luac.obj -link /DLL /out:lua51.dll l*.obj -cl /O2 /W3 /c /DLUA_BUILD_AS_DLL lua.c -link /out:lua.exe lua.obj lua51.lib -cd .. +rem script to build Lua under "Visual Studio .NET Command Prompt". +rem do not run it from this directory, run it from the toplevel: etc\luavs.bat +rem it creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. + +cd src +cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL l*.c +del lua.obj luac.obj +link /DLL /out:lua51.dll l*.obj +cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL lua.c +link /out:lua.exe lua.obj lua51.lib +cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE l*.c print.c +del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj loslib.obj ltablib.obj lstrlib.obj loadlib.obj +link /out:luac.exe *.obj +del *.obj +cd .. diff --git a/lua/etc/strict.lua b/lua/etc/strict.lua index 7c9fa15..16ee26b 100644 --- a/lua/etc/strict.lua +++ b/lua/etc/strict.lua @@ -14,9 +14,14 @@ end mt.__declared = {} +local function what () + local d = debug.getinfo(3, "S") + return d and d.what or "C" +end + mt.__newindex = function (t, n, v) if not mt.__declared[n] then - local w = debug.getinfo(2, "S").what + local w = what() if w ~= "main" and w ~= "C" then error("assign to undeclared variable '"..n.."'", 2) end @@ -26,7 +31,7 @@ mt.__newindex = function (t, n, v) end mt.__index = function (t, n) - if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then + if not mt.__declared[n] and what() ~= "C" then error("variable '"..n.."' is not declared", 2) end return rawget(t, n) diff --git a/lua/src/Makefile b/lua/src/Makefile index 0708ac4..cd7f6ba 100644 --- a/lua/src/Makefile +++ b/lua/src/Makefile @@ -20,7 +20,7 @@ MYLIBS= # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= -PLATS= aix ansi bsd generic linux macosx mingw posix solaris +PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris LUA_A= liblua.a CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ @@ -77,7 +77,8 @@ echo: # convenience targets for popular platforms none: - @echo "Please choose a platform: $(PLATS)" + @echo "Please choose a platform:" + @echo " $(PLATS)" aix: $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" @@ -88,6 +89,9 @@ ansi: bsd: $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E" +freebsd: + $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline" + generic: $(MAKE) all MYCFLAGS= @@ -103,6 +107,7 @@ mingw: $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \ "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe + $(MAKE) "LUAC_T=luac.exe" luac.exe posix: $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX diff --git a/lua/src/lbaselib.c b/lua/src/lbaselib.c index 2df437b..147a727 100644 --- a/lua/src/lbaselib.c +++ b/lua/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $ +** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { } -static void getfunc (lua_State *L) { +static void getfunc (lua_State *L, int opt) { if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); else { lua_Debug ar; - int level = luaL_optint(L, 1, 1); + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); if (lua_getstack(L, level, &ar) == 0) luaL_argerror(L, 1, "invalid level"); @@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { static int luaB_getfenv (lua_State *L) { - getfunc(L); + getfunc(L, 1); if (lua_iscfunction(L, -1)) /* is a C function? */ lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ else @@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { static int luaB_setfenv (lua_State *L) { luaL_checktype(L, 2, LUA_TTABLE); - getfunc(L); + getfunc(L, 0); lua_pushvalue(L, 2); if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { /* change environment of current thread */ diff --git a/lua/src/lcode.c b/lua/src/lcode.c index b71acd8..9ce515a 100644 --- a/lua/src/lcode.c +++ b/lua/src/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $ +** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { void luaK_nil (FuncState *fs, int from, int n) { Instruction *previous; if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ - if (fs->pc == 0) /* function start? */ - return; /* positions are already clean */ - if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { - int pfrom = GETARG_A(*previous); - int pto = GETARG_B(*previous); - if (pfrom <= from && from <= pto+1) { /* can connect both? */ - if (from+n-1 > pto) - SETARG_B(*previous, from+n-1); - return; + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } } } } @@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { if (constfolding(op, e1, e2)) return; else { - int o1 = luaK_exp2RK(fs, e1); int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; - freeexp(fs, e2); - freeexp(fs, e1); + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); e1->k = VRELOCABLE; } @@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ break; } - default: { + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { if (!isnumeral(v)) luaK_exp2RK(fs, v); break; } + default: { + luaK_exp2RK(fs, v); + break; + } } } diff --git a/lua/src/ldebug.c b/lua/src/ldebug.c index 8919a01..9c8bdf2 100644 --- a/lua/src/ldebug.c +++ b/lua/src/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ +** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { break; } case OP_CLOSURE: { - int nup; + int nup, j; check(b < pt->sizep); nup = pt->p[b]->nups; check(pc + nup < pt->sizecode); - for (; nup>0; nup--) { - OpCode op1 = GET_OPCODE(pt->code[pc+nup]); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); check(op1 == OP_GETUPVAL || op1 == OP_MOVE); } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ break; } case OP_VARARG: { diff --git a/lua/src/lfunc.c b/lua/src/lfunc.c index b8cd67b..05bd5ff 100644 --- a/lua/src/lfunc.c +++ b/lua/src/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $ +** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -55,7 +55,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { GCObject **pp = &L->openupval; UpVal *p; UpVal *uv; - while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { lua_assert(p->v != &p->u.value); if (p->v == level) { /* found a corresponding upvalue? */ if (isdead(g, obj2gco(p))) /* is it dead? */ @@ -96,7 +96,7 @@ void luaF_freeupval (lua_State *L, UpVal *uv) { void luaF_close (lua_State *L, StkId level) { UpVal *uv; global_State *g = G(L); - while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { GCObject *o = obj2gco(uv); lua_assert(!isblack(o) && uv->v != &uv->u.value); L->openupval = uv->next; /* remove from `open' list */ diff --git a/lua/src/loadlib.c b/lua/src/loadlib.c index 08722e1..808368b 100644 --- a/lua/src/loadlib.c +++ b/lua/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.52 2006/04/10 18:27:23 roberto Exp $ +** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -16,9 +16,9 @@ #define loadlib_c #define LUA_LIB -#include "lauxlib.h" -#include "lobject.h" #include "lua.h" + +#include "lauxlib.h" #include "lualib.h" @@ -98,7 +98,7 @@ static void setprogdir (lua_State *L) { char buff[MAX_PATH + 1]; char *lb; DWORD nsize = sizeof(buff)/sizeof(char); - DWORD n = GetModuleFileName(NULL, buff, nsize); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) luaL_error(L, "unable to get ModuleFileName"); else { @@ -112,7 +112,7 @@ static void setprogdir (lua_State *L) { static void pusherror (lua_State *L) { int error = GetLastError(); char buffer[128]; - if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buffer, sizeof(buffer), NULL)) lua_pushstring(L, buffer); else @@ -125,7 +125,7 @@ static void ll_unloadlib (void *lib) { static void *ll_load (lua_State *L, const char *path) { - HINSTANCE lib = LoadLibrary(path); + HINSTANCE lib = LoadLibraryA(path); if (lib == NULL) pusherror(L); return lib; } @@ -356,15 +356,16 @@ static const char *findfile (lua_State *L, const char *name, path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); - lua_pushstring(L, ""); /* error accumulator */ + lua_pushliteral(L, ""); /* error accumulator */ while ((path = pushnexttemplate(L, path)) != NULL) { const char *filename; filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ if (readable(filename)) /* does file exist and is readable? */ return filename; /* return that file name */ - lua_pop(L, 2); /* remove path template and file name */ - luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); - lua_concat(L, 2); + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + lua_concat(L, 2); /* add entry to possible error message */ } return NULL; /* not found */ } @@ -423,8 +424,8 @@ static int loader_Croot (lua_State *L) { funcname = mkfuncname(L, name); if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { if (stat != ERRFUNC) loaderror(L, filename); /* real error */ - luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, - name, filename); + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); return 1; /* function not found */ } return 1; @@ -438,7 +439,7 @@ static int loader_preload (lua_State *L) { luaL_error(L, LUA_QL("package.preload") " must be a table"); lua_getfield(L, -1, name); if (lua_isnil(L, -1)) /* not found? */ - luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); return 1; } @@ -462,7 +463,7 @@ static int ll_require (lua_State *L) { lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); if (!lua_istable(L, -1)) luaL_error(L, LUA_QL("package.loaders") " must be a table"); - lua_pushstring(L, ""); /* error message accumulator */ + lua_pushliteral(L, ""); /* error message accumulator */ for (i=1; ; i++) { lua_rawgeti(L, -2, i); /* get a loader */ if (lua_isnil(L, -1)) @@ -646,8 +647,8 @@ LUALIB_API int luaopen_package (lua_State *L) { setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ /* store config information */ - lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" - LUA_EXECDIR "\n" LUA_IGMARK); + lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); lua_setfield(L, -2, "config"); /* set field `loaded' */ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); diff --git a/lua/src/loslib.c b/lua/src/loslib.c index 7c6c5d6..fdda474 100644 --- a/lua/src/loslib.c +++ b/lua/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $ +** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -146,11 +146,22 @@ static int os_date (lua_State *L) { setboolfield(L, "isdst", stm->tm_isdst); } else { - char b[256]; - if (strftime(b, sizeof(b), s, stm)) - lua_pushstring(L, b); - else - return luaL_error(L, LUA_QL("date") " format too long"); + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); } return 1; } diff --git a/lua/src/lparser.c b/lua/src/lparser.c index a9be740..6c473c4 100644 --- a/lua/src/lparser.c +++ b/lua/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $ +** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { static void listfield (LexState *ls, struct ConsControl *cc) { expr(ls, &cc->v); - luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); cc->na++; cc->tostore++; } diff --git a/lua/src/lstrlib.c b/lua/src/lstrlib.c index f93a8af..fc7ae48 100644 --- a/lua/src/lstrlib.c +++ b/lua/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $ +** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { const char *p = strfrmt; - while (strchr(FLAGS, *p)) p++; /* skip flags */ + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) luaL_error(L, "invalid format (repeated flags)"); if (isdigit(uchar(*p))) p++; /* skip width */ diff --git a/lua/src/lua.h b/lua/src/lua.h index 064ff6f..2865a7f 100644 --- a/lua/src/lua.h +++ b/lua/src/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $ +** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $ ** Lua - An Extensible Extension Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -17,9 +17,9 @@ #define LUA_VERSION "Lua 5.1" -#define LUA_RELEASE "Lua 5.1.1" +#define LUA_RELEASE "Lua 5.1.2" #define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio" +#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -359,7 +359,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved. +* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/lua/src/luaconf.h b/lua/src/luaconf.h index f32f1f7..8be8338 100644 --- a/lua/src/luaconf.h +++ b/lua/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.82 2006/04/10 18:27:23 roberto Exp $ +** $Id: luaconf.h,v 1.82a 2006/04/10 18:27:23 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -360,7 +360,7 @@ /* @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' @* behavior. -** CHANGE it to undefined as soon as you replace to 'luaL_registry' +** CHANGE it to undefined as soon as you replace to 'luaL_register' ** your uses of 'luaL_openlib' */ #define LUA_COMPAT_OPENLIB diff --git a/lua/src/lvm.c b/lua/src/lvm.c index 1e3ea4c..08802f4 100644 --- a/lua/src/lvm.c +++ b/lua/src/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.63 2006/06/05 15:58:59 roberto Exp $ +** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -165,7 +165,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ if (ttisnil(tm)) tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ - if (!ttisfunction(tm)) return 0; + if (ttisnil(tm)) return 0; callTMres(L, res, tm, p1, p2); return 1; } @@ -281,10 +281,12 @@ void luaV_concat (lua_State *L, int total, int last) { do { StkId top = L->base + last + 1; int n = 2; /* number of elements handled in this pass (at least 2) */ - if (!tostring(L, top-2) || !tostring(L, top-1)) { + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) luaG_concaterror(L, top-2, top-1); - } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { /* at least two string values; get as many as possible */ size_t tl = tsvalue(top-1)->len; char *buffer; diff --git a/lua/src/print.c b/lua/src/print.c index 2a4fb3e..e240cfc 100644 --- a/lua/src/print.c +++ b/lua/src/print.c @@ -1,5 +1,5 @@ /* -** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $ +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ ** print bytecodes ** See Copyright Notice in lua.h */ @@ -23,8 +23,7 @@ static void PrintString(const TString* ts) { const char* s=getstr(ts); - int n=ts->tsv.len; - int i; + size_t i,n=ts->tsv.len; putchar('"'); for (i=0; i