From 19f04502a60b554207cffeee8182e7d5411ba0be Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 18 Mar 2008 02:05:22 +0000 Subject: [PATCH] Updated Lua from 5.1.1 to 5.1.3. --- src/lua-5.1.1/COPYRIGHT | 2 +- src/lua-5.1.1/HISTORY | 2 +- src/lua-5.1.1/INSTALL | 9 +- src/lua-5.1.1/Makefile | 31 +- src/lua-5.1.1/README | 4 +- src/lua-5.1.1/doc/amazon.gif | Bin 0 -> 797 bytes src/lua-5.1.1/doc/contents.html | 112 ++- src/lua-5.1.1/doc/cover.png | Bin 0 -> 3305 bytes src/lua-5.1.1/doc/lua.css | 23 +- src/lua-5.1.1/doc/manual.css | 13 + src/lua-5.1.1/doc/manual.html | 1172 +++++++++++++++++++------------ src/lua-5.1.1/doc/readme.html | 14 +- src/lua-5.1.1/etc/README | 1 + src/lua-5.1.1/etc/lua.pc | 2 +- src/lua-5.1.1/etc/luavs.bat | 29 +- src/lua-5.1.1/etc/min.c | 2 +- src/lua-5.1.1/etc/strict.lua | 11 +- src/lua-5.1.1/src/Makefile | 20 +- src/lua-5.1.1/src/lapi.c | 9 +- src/lua-5.1.1/src/lapi.h | 2 +- src/lua-5.1.1/src/lauxlib.c | 13 +- src/lua-5.1.1/src/lauxlib.h | 2 +- src/lua-5.1.1/src/lbaselib.c | 86 ++- src/lua-5.1.1/src/lcode.c | 46 +- src/lua-5.1.1/src/lcode.h | 2 +- src/lua-5.1.1/src/ldblib.c | 30 +- src/lua-5.1.1/src/ldebug.c | 14 +- src/lua-5.1.1/src/ldebug.h | 2 +- src/lua-5.1.1/src/ldo.c | 24 +- src/lua-5.1.1/src/ldo.h | 2 +- src/lua-5.1.1/src/ldump.c | 2 +- src/lua-5.1.1/src/lfunc.c | 6 +- src/lua-5.1.1/src/lfunc.h | 2 +- src/lua-5.1.1/src/lgc.c | 2 +- src/lua-5.1.1/src/lgc.h | 2 +- src/lua-5.1.1/src/linit.c | 3 +- src/lua-5.1.1/src/liolib.c | 69 +- src/lua-5.1.1/src/llimits.h | 2 +- src/lua-5.1.1/src/lmathlib.c | 2 +- src/lua-5.1.1/src/lmem.c | 2 +- src/lua-5.1.1/src/lmem.h | 2 +- src/lua-5.1.1/src/loadlib.c | 33 +- src/lua-5.1.1/src/lobject.c | 2 +- src/lua-5.1.1/src/lobject.h | 2 +- src/lua-5.1.1/src/lopcodes.c | 2 +- src/lua-5.1.1/src/lopcodes.h | 2 +- src/lua-5.1.1/src/loslib.c | 24 +- src/lua-5.1.1/src/lparser.h | 2 +- src/lua-5.1.1/src/lstate.c | 6 +- src/lua-5.1.1/src/lstate.h | 3 +- src/lua-5.1.1/src/lstring.c | 2 +- src/lua-5.1.1/src/lstring.h | 2 +- src/lua-5.1.1/src/lstrlib.c | 12 +- src/lua-5.1.1/src/ltable.c | 6 +- src/lua-5.1.1/src/ltable.h | 2 +- src/lua-5.1.1/src/ltablib.c | 5 +- src/lua-5.1.1/src/ltm.c | 2 +- src/lua-5.1.1/src/ltm.h | 2 +- src/lua-5.1.1/src/lua.c | 6 +- src/lua-5.1.1/src/lua.h | 14 +- src/lua-5.1.1/src/luaconf.h | 9 +- src/lua-5.1.1/src/lualib.h | 2 +- src/lua-5.1.1/src/lundump.c | 6 +- src/lua-5.1.1/src/lundump.h | 2 +- src/lua-5.1.1/src/lvm.c | 18 +- src/lua-5.1.1/src/lvm.h | 2 +- src/lua-5.1.1/src/lzio.c | 2 +- src/lua-5.1.1/src/lzio.h | 2 +- src/lua-5.1.1/src/print.c | 6 +- src/toby_app.c | 2 +- 70 files changed, 1236 insertions(+), 717 deletions(-) create mode 100644 src/lua-5.1.1/doc/amazon.gif create mode 100644 src/lua-5.1.1/doc/cover.png create mode 100644 src/lua-5.1.1/doc/manual.css diff --git a/src/lua-5.1.1/COPYRIGHT b/src/lua-5.1.1/COPYRIGHT index 84d401b..3a53e74 100644 --- a/src/lua-5.1.1/COPYRIGHT +++ b/src/lua-5.1.1/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-2008 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/src/lua-5.1.1/HISTORY b/src/lua-5.1.1/HISTORY index d807a53..ce0c95b 100644 --- a/src/lua-5.1.1/HISTORY +++ b/src/lua-5.1.1/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/src/lua-5.1.1/INSTALL b/src/lua-5.1.1/INSTALL index 65f6f1e..17eb8ae 100644 --- a/src/lua-5.1.1/INSTALL +++ b/src/lua-5.1.1/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/src/lua-5.1.1/Makefile b/src/lua-5.1.1/Makefile index b3678b1..fec2011 100644 --- a/src/lua-5.1.1/Makefile +++ b/src/lua-5.1.1/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 @@ -19,25 +20,20 @@ INSTALL_MAN= $(INSTALL_TOP)/man/man1 INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V -# How to install. You may prefer "install" instead of "cp" if you have it. -# To remove debug information from binaries, use "install -s" in INSTALL_EXEC. -# -INSTALL_EXEC= $(CP) -INSTALL_DATA= $(CP) -#INSTALL_EXEC= $(INSTALL) -m 0755 -#INSTALL_DATA= $(INSTALL) -m 0644 +# How to install. If you don't have "install" (unlikely) then get install-sh at +# http://dev.w3.org/cvsweb/libwww/config/install-sh +# or use cp instead. +INSTALL_EXEC= $(INSTALL) -p -m 0755 +INSTALL_DATA= $(INSTALL) -p -m 0644 # Utilities. -CP= cp -FIND= find INSTALL= install MKDIR= mkdir -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 +43,7 @@ TO_MAN= lua.1 luac.1 # Lua version and release. V= 5.1 -R= 5.1.1 +R= 5.1.3 all: $(PLAT) @@ -63,10 +59,9 @@ install: dummy cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) -# $(RANLIB) $(INSTALL_LIB)/$(TO_LIB) local: - $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p" + $(MAKE) install INSTALL_TOP=.. none: @echo "Please do" @@ -119,11 +114,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/src/lua-5.1.1/README b/src/lua-5.1.1/README index f082d40..11b4dff 100644 --- a/src/lua-5.1.1/README +++ b/src/lua-5.1.1/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/src/lua-5.1.1/doc/amazon.gif b/src/lua-5.1.1/doc/amazon.gif new file mode 100644 index 0000000000000000000000000000000000000000..f2586d5765361bb8a33a72401449f3abdefe4e16 GIT binary patch literal 797 zcmV+&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 HcmV?d00001 diff --git a/src/lua-5.1.1/doc/contents.html b/src/lua-5.1.1/doc/contents.html index c1e4a99..8e58e18 100644 --- a/src/lua-5.1.1/doc/contents.html +++ b/src/lua-5.1.1/doc/contents.html @@ -1,33 +1,71 @@ + -Lua 5.1 reference manual - contents +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 copy of this book and +help to support +the Lua project. +

+ +The reference manual is the official definition of the Lua language. +For a complete introduction to Lua programming, see the book +Programming in Lua. +

+ +startcontents · index +· +português +· +español


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

Contents

+

  • 3 - The Application Program Interface +

  • 4 - The Auxiliary Library +

  • 5 - Standard Libraries +

  • 6 - Lua Stand-alone +

  • 7 - Incompatibilities with the Previous Version +

  • 8 - The Complete Syntax of Lua -

    Index

    - +
    - - + -
    +

    Lua functions

    _G
    _VERSION
    @@ -144,16 +187,16 @@

    Lua functions

    type
    unpack
    xpcall
    +

    -

    -

     

    coroutine.create
    coroutine.resume
    coroutine.running
    coroutine.status
    coroutine.wrap
    coroutine.yield
    +

    + debug.debug
    debug.getfenv
    debug.gethook
    @@ -168,6 +211,10 @@

     

    debug.setmetatable
    debug.setupvalue
    debug.traceback
    + +
    +

     

    file:close
    file:flush
    file:lines
    @@ -175,6 +222,8 @@

     

    file:seek
    file:setvbuf
    file:write
    +

    + io.close
    io.flush
    io.input
    @@ -183,17 +232,22 @@

     

    io.output
    io.popen
    io.read
    +io.stderr
    +io.stdin
    +io.stdout
    io.tmpfile
    io.type
    io.write
    +

    + math.abs
    math.acos
    math.asin
    -math.atan2
    math.atan
    +math.atan2
    math.ceil
    -math.cosh
    math.cos
    +math.cosh
    math.deg
    math.exp
    math.floor
    @@ -201,8 +255,8 @@

     

    math.frexp
    math.huge
    math.ldexp
    -math.log10
    math.log
    +math.log10
    math.max
    math.min
    math.modf
    @@ -211,11 +265,13 @@

     

    math.rad
    math.random
    math.randomseed
    -math.sinh
    math.sin
    +math.sinh
    math.sqrt
    -math.tanh
    math.tan
    +math.tanh
    +

    + os.clock
    os.date
    os.difftime
    @@ -227,12 +283,17 @@

     

    os.setlocale
    os.time
    os.tmpname
    +

    + package.cpath
    package.loaded
    +package.loaders
    package.loadlib
    package.path
    package.preload
    package.seeall
    +

    + string.byte
    string.char
    string.dump
    @@ -247,6 +308,8 @@

     

    string.reverse
    string.sub
    string.upper
    +

    + table.concat
    table.insert
    table.maxn
    @@ -254,7 +317,7 @@

     

    table.sort
    +

    C API

    lua_Alloc
    lua_CFunction
    @@ -265,6 +328,8 @@

    C API

    lua_Reader
    lua_State
    lua_Writer
    +

    + lua_atpanic
    lua_call
    lua_checkstack
    @@ -296,6 +361,8 @@

    C API

    lua_isfunction
    lua_islightuserdata
    lua_isnil
    +lua_isnone
    +lua_isnoneornil
    lua_isnumber
    lua_isstring
    lua_istable
    @@ -317,6 +384,7 @@

    C API

    lua_pushfstring
    lua_pushinteger
    lua_pushlightuserdata
    +lua_pushliteral
    lua_pushlstring
    lua_pushnil
    lua_pushnumber
    @@ -364,6 +432,8 @@

    C API

    auxiliary library

    luaL_Buffer
    luaL_Reg
    +

    + luaL_addchar
    luaL_addlstring
    luaL_addsize
    @@ -419,10 +489,10 @@

    auxiliary library


    Last update: -Tue Jun 6 14:55:31 BRT 2006 +Sat Jan 19 13:24:29 BRST 2008 diff --git a/src/lua-5.1.1/doc/cover.png b/src/lua-5.1.1/doc/cover.png new file mode 100644 index 0000000000000000000000000000000000000000..2dbb198123f03a7250bfa57c8253739962d69afb GIT binary patch literal 3305 zcmVNc=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 HcmV?d00001 diff --git a/src/lua-5.1.1/doc/lua.css b/src/lua-5.1.1/doc/lua.css index f007211..039cf11 100644 --- a/src/lua-5.1.1/doc/lua.css +++ b/src/lua-5.1.1/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/src/lua-5.1.1/doc/manual.css b/src/lua-5.1.1/doc/manual.css new file mode 100644 index 0000000..eed5afd --- /dev/null +++ b/src/lua-5.1.1/doc/manual.css @@ -0,0 +1,13 @@ +h3 code { + font-family: inherit ; +} + +pre { + font-size: 105% ; +} + +span.apii { + float: right ; + font-family: inherit ; +} + diff --git a/src/lua-5.1.1/doc/manual.html b/src/lua-5.1.1/doc/manual.html index 16fbb36..b125c13 100644 --- a/src/lua-5.1.1/doc/manual.html +++ b/src/lua-5.1.1/doc/manual.html @@ -1,9 +1,11 @@ - + Lua 5.1 Reference Manual + + @@ -17,14 +19,21 @@

    by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes

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


    +

    + +contents +· +index

    + @@ -71,7 +80,7 @@

    1 - Introduction

    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). @@ -171,6 +180,7 @@

    2.1 - Lexical Conventions

    To put a double (single) quote, a newline, a backslash, +a carriage return, or an embedded zero inside a literal string enclosed by double (single) quotes you must use an escape sequence. @@ -390,8 +400,8 @@

    2.3 - Variables

    -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). @@ -547,9 +557,9 @@

    2.4.3 - Assignment

    The elements in both lists are separated by commas:
    -	stat ::= varlist1 `=´ explist1
    -	varlist1 ::= var {`,´ var}
    -	explist1 ::= exp {`,´ exp}
    +	stat ::= varlist `=´ explist
    +	varlist ::= var {`,´ var}
    +	explist ::= exp {`,´ exp}
     

    Expressions are discussed in §2.5. @@ -656,7 +666,7 @@

    2.4.4 - Control Structures

    so the syntax for the return statement is

    -	stat ::= return [explist1]
    +	stat ::= return [explist]
     

    @@ -708,18 +718,18 @@

    2.4.5 - For Statement

    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 +744,7 @@

    2.4.5 - For Statement

  • -_var, _limit, and _step are invisible variables. +var, limit, and step are invisible variables. The names are here for explanatory purposes only.
  • @@ -748,10 +758,10 @@

    2.4.5 - For Statement

  • -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.
  • @@ -764,24 +774,24 @@

    2.4.5 - For Statement

    The generic for loop has the following syntax:
    -	stat ::= for namelist in explist1 do block end
    +	stat ::= for namelist in explist do block end
     	namelist ::= Name {`,´ Name}
     

    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 +800,14 @@

    2.4.5 - For Statement

    • -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 +816,7 @@

      2.4.5 - For Statement

    • -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. @@ -835,7 +846,7 @@

      2.4.7 - Local Declarations

      The declaration may include an initial assignment:

      -	stat ::= local namelist [`=´ explist1]
      +	stat ::= local namelist [`=´ explist]
       

      If present, an initial assignment has the same semantics of a multiple assignment (see §2.4.3). @@ -882,8 +893,8 @@

      2.5 - Expressions

      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 +913,13 @@

      2.5 - Expressions

      (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 +928,18 @@

      2.5 - Expressions

            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
       
      @@ -1212,7 +1224,7 @@

      2.5.8 - Function Calls

      Arguments have the following syntax:

      -	args ::= `(´ [explist1] `)´
      +	args ::= `(´ [explist] `)´
       	args ::= tableconstructor
       	args ::= String
       

      @@ -1277,7 +1289,7 @@

      2.5.9 - Function Definitions

       	function ::= function funcbody
      -	funcbody ::= `(´ [parlist1] `)´ block end
      +	funcbody ::= `(´ [parlist] `)´ block end
       

      @@ -1346,7 +1358,7 @@

      2.5.9 - Function Definitions

      initialized with the argument values:
      -	parlist1 ::= namelist [`,´ `...´] | `...´
      +	parlist ::= namelist [`,´ `...´] | `...´
       

      When a function is called, the list of arguments is adjusted to @@ -1542,12 +1554,11 @@

      2.8 - Metatables

      -Tables and userdata have individual metatables -(although multiple tables and userdata can share -a same table as their metatable); +Tables and full userdata have individual metatables +(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. +one for all strings, etc.

      @@ -1592,6 +1603,7 @@

      2.8 - Metatables

            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). @@ -1629,7 +1641,7 @@

      2.8 - Metatables

      local h = getbinhandler(op1, op2, "__add") if h then -- call the handler with both operands - return h(op1, op2) + return (h(op1, op2)) else -- no handler available: default behavior error(···) end @@ -1686,7 +1698,7 @@

      2.8 - Metatables

      local h = metatable(op).__unm if h then -- call the handler with the operand - return h(op) + return (h(op)) else -- no handler available: default behavior error(···) end @@ -1707,7 +1719,7 @@

      2.8 - Metatables

      else local h = getbinhandler(op1, op2, "__concat") if h then - return h(op1, op2) + return (h(op1, op2)) else error(···) end @@ -1730,7 +1742,7 @@

      2.8 - Metatables

      local h = metatable(op).__len if h then -- call the handler with the operand - return h(op) + return (h(op)) else -- no handler available: default behavior error(···) end @@ -1770,7 +1782,7 @@

      2.8 - Metatables

      -- try metamethod local h = getcomphandler(op1, op2, "__eq") if h then - return h(op1, op2) + return (h(op1, op2)) else return false end @@ -1792,7 +1804,7 @@

      2.8 - Metatables

      else local h = getcomphandler(op1, op2, "__lt") if h then - return h(op1, op2) + return (h(op1, op2)) else error(···); end @@ -1815,7 +1827,7 @@

      2.8 - Metatables

      else local h = getcomphandler(op1, op2, "__le") if h then - return h(op1, op2) + return (h(op1, op2)) else h = getcomphandler(op1, op2, "__lt") if h then @@ -1852,8 +1864,8 @@

      2.8 - Metatables

      end end if type(h) == "function" then - return h(table, key) -- call the handler - else return h[key] -- or repeat operation on it + return (h(table, key)) -- call the handler + else return h[key] -- or repeat operation on it end end

      @@ -1878,7 +1890,7 @@

      2.8 - Metatables

      end end if type(h) == "function" then - return h(table, key,value) -- call the handler + h(table, key,value) -- call the handler else h[key] = value -- or repeat operation on it end end @@ -2053,6 +2065,7 @@

      2.10.1 - Garbage-Collection Metamethods

      among those collected in that cycle. That is, the first finalizer to be called is the one associated with the userdata created last in the program. +The userdata itself is freed only in the next garbage-collection cycle. @@ -2077,7 +2090,7 @@

      2.10.2 - Weak Tables

      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 +2169,8 @@

      2.11 - Coroutines

      -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 +2211,7 @@

      2.11 - Coroutines

            co-body 1       10
            foo     2
      +     
            main    true    4
            co-body r
            main    true    11      -9
      @@ -2268,7 +2282,7 @@ 

      3.1 - The Stack

      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 @@ -2417,17 +2431,14 @@

      3.6 - Error Handling in C

      -Almost any function in the API may raise an error, +Most functions in the API may throw an error, for instance due to a memory allocation error. -The following functions run in protected mode -(that is, they create a protected environment to run), -so they never raise an error: -lua_newstate, lua_close, lua_load, -lua_pcall, and lua_cpcall. +The documentation for each function indicates whether +it can throw errors.

      -Inside a C function you can raise an error by calling lua_error. +Inside a C function you can throw an error by calling lua_error. @@ -2438,6 +2449,30 @@

      3.7 - Functions and Types

      Here we list all functions and types from the C API in alphabetical order. +Each function has an indicator like this: +[-o, +p, x] + + +

      +The first field, o, +is how many elements the function pops from the stack. +The second field, p, +is how many elements the function pushes onto the stack. +(Any function always pushes its results after popping its arguments.) +A field in the form x|y means the function may push (or pop) +x or y elements, +depending on the situation; +an interrogation mark '?' means that +we cannot know how many elements the function pops/pushes +by looking only at its arguments +(e.g., they may depend on what is on the stack). +The third field, x, +tells whether the function may throw errors: +'-' means the function never throws any error; +'m' means the function may throw an error +only due to not enough memory; +'e' means the function may throw other kinds of errors; +'v' means the function may throw an error on purpose. @@ -2473,26 +2508,31 @@

      3.7 - Functions and Types

      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. + -


      lua_atpanic

      +

      lua_atpanic

      +[-0, +0, -]

      lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);

      @@ -2515,7 +2555,8 @@

      3.7 - Functions and Types

      -

      lua_call

      +

      lua_call

      +[-(nargs + 1), +nresults, e]

      void lua_call (lua_State *L, int nargs, int nresults);

      @@ -2557,14 +2598,14 @@

      3.7 - Functions and Types

      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 +2652,7 @@

      3.7 - Functions and Types

      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); @@ -2625,7 +2666,8 @@

      3.7 - Functions and Types

      -

      lua_checkstack

      +

      lua_checkstack

      +[-0, +0, m]

      int lua_checkstack (lua_State *L, int extra);

      @@ -2639,7 +2681,8 @@

      3.7 - Functions and Types

      -

      lua_close

      +

      lua_close

      +[-0, +0, -]

      void lua_close (lua_State *L);

      @@ -2657,23 +2700,25 @@

      3.7 - Functions and Types

      -

      lua_concat

      +

      lua_concat

      +[-n, +1, e]

      void lua_concat (lua_State *L, int n);

      Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. -If n is 1, the result is the single string on the stack +If n is 1, the result is the single value on the stack (that is, the function does nothing); if n is 0, the result is the empty string. -Concatenation is done following the usual semantics of Lua +Concatenation is performed following the usual semantics of Lua (see §2.5.4). -


      lua_cpcall

      +

      lua_cpcall

      +[-0, +(0|1), -]

      int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);

      @@ -2690,7 +2735,8 @@

      3.7 - Functions and Types

      -

      lua_createtable

      +

      lua_createtable

      +[-0, +1, m]

      void lua_createtable (lua_State *L, int narr, int nrec);

      @@ -2705,7 +2751,8 @@

      3.7 - Functions and Types

      -

      lua_dump

      +

      lua_dump

      +[-0, +0, m]

      int lua_dump (lua_State *L, lua_Writer writer, void *data);

      @@ -2723,7 +2770,7 @@

      3.7 - Functions and Types

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

      @@ -2733,7 +2780,8 @@

      3.7 - Functions and Types

      -

      lua_equal

      +

      lua_equal

      +[-0, +0, e]

      int lua_equal (lua_State *L, int index1, int index2);

      @@ -2748,7 +2796,8 @@

      3.7 - Functions and Types

      -

      lua_error

      +

      lua_error

      +[-1, +0, v]

      int lua_error (lua_State *L);

      @@ -2763,7 +2812,8 @@

      3.7 - Functions and Types

      -

      lua_gc

      +

      lua_gc

      +[-0, +0, e]

      int lua_gc (lua_State *L, int what, int data);

      @@ -2814,7 +2864,7 @@

      3.7 - Functions and Types

    • 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.
    • @@ -2824,7 +2874,8 @@

      3.7 - Functions and Types

      -

      lua_getallocf

      +

      lua_getallocf

      +[-0, +0, -]

      lua_Alloc lua_getallocf (lua_State *L, void **ud);

      @@ -2836,7 +2887,8 @@

      3.7 - Functions and Types

      -

      lua_getfenv

      +

      lua_getfenv

      +[-0, +1, -]

      void lua_getfenv (lua_State *L, int index);

      @@ -2847,12 +2899,13 @@

      3.7 - Functions and Types

      -

      lua_getfield

      +

      lua_getfield

      +[-0, +1, e]

      void lua_getfield (lua_State *L, int index, const char *k);

      Pushes onto the stack the value t[k], -where t is the value at the given valid index index. +where t is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.8). @@ -2860,7 +2913,8 @@

      3.7 - Functions and Types

      -

      lua_getglobal

      +

      lua_getglobal

      +[-0, +1, e]

      void lua_getglobal (lua_State *L, const char *name);

      @@ -2874,7 +2928,8 @@

      3.7 - Functions and Types

      -

      lua_getmetatable

      +

      lua_getmetatable

      +[-0, +(0|1), -]

      int lua_getmetatable (lua_State *L, int index);

      @@ -2888,12 +2943,13 @@

      3.7 - Functions and Types

      -

      lua_gettable

      +

      lua_gettable

      +[-1, +1, e]

      void lua_gettable (lua_State *L, int index);

      Pushes onto the stack the value t[k], -where t is the value at the given valid index index +where t is the value at the given valid index and k is the value at the top of the stack. @@ -2907,7 +2963,8 @@

      3.7 - Functions and Types

      -

      lua_gettop

      +

      lua_gettop

      +[-0, +0, -]

      int lua_gettop (lua_State *L);

      @@ -2920,7 +2977,8 @@

      3.7 - Functions and Types

      -

      lua_insert

      +

      lua_insert

      +[-1, +1, -]

      void lua_insert (lua_State *L, int index);

      @@ -2942,126 +3000,164 @@

      3.7 - Functions and Types

      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". -


      lua_isboolean

      +

      lua_isboolean

      +[-0, +0, -]

      int lua_isboolean (lua_State *L, int index);

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


      lua_iscfunction

      +

      lua_iscfunction

      +[-0, +0, -]

      int lua_iscfunction (lua_State *L, int index);

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


      lua_isfunction

      +

      lua_isfunction

      +[-0, +0, -]

      int lua_isfunction (lua_State *L, int index);

      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. -


      lua_islightuserdata

      +

      lua_islightuserdata

      +[-0, +0, -]

      int lua_islightuserdata (lua_State *L, int index);

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


      lua_isnil

      +

      lua_isnil

      +[-0, +0, -]

      int lua_isnil (lua_State *L, int index);

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


      lua_isnumber

      +

      lua_isnone

      +[-0, +0, -] +

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

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


      lua_isnoneornil

      +[-0, +0, -] +

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

      +Returns 1 if 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. + + + + + +


      lua_isnumber

      +[-0, +0, -]

      int lua_isnumber (lua_State *L, int index);

      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. -


      lua_isstring

      +

      lua_isstring

      +[-0, +0, -]

      int lua_isstring (lua_State *L, int index);

      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. -


      lua_istable

      +

      lua_istable

      +[-0, +0, -]

      int lua_istable (lua_State *L, int index);

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


      lua_isthread

      +

      lua_isthread

      +[-0, +0, -]

      int lua_isthread (lua_State *L, int index);

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


      lua_isuserdata

      +

      lua_isuserdata

      +[-0, +0, -]

      int lua_isuserdata (lua_State *L, int index);

      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. -


      lua_lessthan

      +

      lua_lessthan

      +[-0, +0, e]

      int lua_lessthan (lua_State *L, int index1, int index2);

      @@ -3076,7 +3172,8 @@

      3.7 - Functions and Types

      -

      lua_load

      +

      lua_load

      +[-0, +1, -]

      int lua_load (lua_State *L,
                     lua_Reader reader,
                     void *data,
      @@ -3113,8 +3210,8 @@ 

      3.7 - Functions and Types

      -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. @@ -3126,7 +3223,8 @@

      3.7 - Functions and Types

      -

      lua_newstate

      +

      lua_newstate

      +[-0, +0, -]

      lua_State *lua_newstate (lua_Alloc f, void *ud);

      @@ -3142,7 +3240,8 @@

      3.7 - Functions and Types

      -

      lua_newtable

      +

      lua_newtable

      +[-0, +1, m]

      void lua_newtable (lua_State *L);

      @@ -3153,7 +3252,8 @@

      3.7 - Functions and Types

      -

      lua_newthread

      +

      lua_newthread

      +[-0, +1, m]

      lua_State *lua_newthread (lua_State *L);

      @@ -3173,7 +3273,8 @@

      3.7 - Functions and Types

      -

      lua_newuserdata

      +

      lua_newuserdata

      +[-0, +1, m]

      void *lua_newuserdata (lua_State *L, size_t size);

      @@ -3183,7 +3284,7 @@

      3.7 - Functions and Types

      -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, @@ -3201,7 +3302,8 @@

      3.7 - Functions and Types

      -

      lua_next

      +

      lua_next

      +[-1, +(2|0), e]

      int lua_next (lua_State *L, int index);

      @@ -3219,10 +3321,12 @@

      3.7 - Functions and Types

      /* 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); }
      @@ -3254,7 +3358,8 @@

      3.7 - Functions and Types

      -

      lua_objlen

      +

      lua_objlen

      +[-0, +0, -]

      size_t lua_objlen (lua_State *L, int index);

      @@ -3269,8 +3374,9 @@

      3.7 - Functions and Types

      -

      lua_pcall

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

      lua_pcall

      +[-(nargs + 1), +(nresults|1), -] +

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

      Calls a function in protected mode. @@ -3334,7 +3440,8 @@

      3.7 - Functions and Types

      -

      lua_pop

      +

      lua_pop

      +[-n, +0, -]

      void lua_pop (lua_State *L, int n);

      @@ -3344,7 +3451,8 @@

      3.7 - Functions and Types

      -

      lua_pushboolean

      +

      lua_pushboolean

      +[-0, +1, -]

      void lua_pushboolean (lua_State *L, int b);

      @@ -3354,7 +3462,8 @@

      3.7 - Functions and Types

      -

      lua_pushcclosure

      +

      lua_pushcclosure

      +[-n, +1, m]

      void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);

      @@ -3379,7 +3488,8 @@

      3.7 - Functions and Types

      -

      lua_pushcfunction

      +

      lua_pushcfunction

      +[-0, +1, m]

      void lua_pushcfunction (lua_State *L, lua_CFunction f);

      @@ -3396,14 +3506,17 @@

      3.7 - Functions and Types

      -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)
      +
      -

      lua_pushfstring

      +

      lua_pushfstring

      +[-0, +1, m]

      const char *lua_pushfstring (lua_State *L, const char *fmt, ...);

      @@ -3437,7 +3550,8 @@

      3.7 - Functions and Types

      -

      lua_pushinteger

      +

      lua_pushinteger

      +[-0, +1, -]

      void lua_pushinteger (lua_State *L, lua_Integer n);

      @@ -3447,7 +3561,8 @@

      3.7 - Functions and Types

      -

      lua_pushlightuserdata

      +

      lua_pushlightuserdata

      +[-0, +1, -]

      void lua_pushlightuserdata (lua_State *L, void *p);

      @@ -3455,7 +3570,7 @@

      3.7 - Functions and Types

      -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, @@ -3467,7 +3582,21 @@

      3.7 - Functions and Types

      -

      lua_pushlstring

      +

      lua_pushliteral

      +[-0, +1, m] +

      void lua_pushliteral (lua_State *L, const char *s);
      + +

      +This macro is equivalent to lua_pushlstring, +but can be used only when s is a literal string. +In these cases, it automatically provides the string length. + + + + + +


      lua_pushlstring

      +[-0, +1, m]

      void lua_pushlstring (lua_State *L, const char *s, size_t len);

      @@ -3482,7 +3611,8 @@

      3.7 - Functions and Types

      -

      lua_pushnil

      +

      lua_pushnil

      +[-0, +1, -]

      void lua_pushnil (lua_State *L);

      @@ -3492,7 +3622,8 @@

      3.7 - Functions and Types

      -

      lua_pushnumber

      +

      lua_pushnumber

      +[-0, +1, -]

      void lua_pushnumber (lua_State *L, lua_Number n);

      @@ -3502,7 +3633,8 @@

      3.7 - Functions and Types

      -

      lua_pushstring

      +

      lua_pushstring

      +[-0, +1, m]

      void lua_pushstring (lua_State *L, const char *s);

      @@ -3518,7 +3650,8 @@

      3.7 - Functions and Types

      -

      lua_pushthread

      +

      lua_pushthread

      +[-0, +1, -]

      int lua_pushthread (lua_State *L);

      @@ -3529,7 +3662,8 @@

      3.7 - Functions and Types

      -

      lua_pushvalue

      +

      lua_pushvalue

      +[-0, +1, -]

      void lua_pushvalue (lua_State *L, int index);

      @@ -3540,7 +3674,8 @@

      3.7 - Functions and Types

      -

      lua_pushvfstring

      +

      lua_pushvfstring

      +[-0, +1, m]

      const char *lua_pushvfstring (lua_State *L,
                                     const char *fmt,
                                     va_list argp);
      @@ -3553,7 +3688,8 @@

      3.7 - Functions and Types

      -

      lua_rawequal

      +

      lua_rawequal

      +[-0, +0, -]

      int lua_rawequal (lua_State *L, int index1, int index2);

      @@ -3567,7 +3703,8 @@

      3.7 - Functions and Types

      -

      lua_rawget

      +

      lua_rawget

      +[-1, +1, -]

      void lua_rawget (lua_State *L, int index);

      @@ -3578,12 +3715,13 @@

      3.7 - Functions and Types

      -

      lua_rawgeti

      +

      lua_rawgeti

      +[-0, +1, -]

      void lua_rawgeti (lua_State *L, int index, int n);

      Pushes onto the stack the value t[n], -where t is the value at the given valid index index. +where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods. @@ -3591,7 +3729,8 @@

      3.7 - Functions and Types

      -

      lua_rawset

      +

      lua_rawset

      +[-2, +0, m]

      void lua_rawset (lua_State *L, int index);

      @@ -3602,13 +3741,14 @@

      3.7 - Functions and Types

      -

      lua_rawseti

      +

      lua_rawseti

      +[-1, +0, m]

      void lua_rawseti (lua_State *L, int index, int n);

      Does the equivalent of t[n] = v, -where t is the value at the given valid index index -and v is the value at the top of the stack, +where t is the value at the given valid index +and v is the value at the top of the stack.

      @@ -3641,21 +3781,26 @@

      3.7 - Functions and Types

      -

      lua_register

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

      lua_register

      +[-0, +0, e] +

      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))
       
      -

      lua_remove

      +

      lua_remove

      +[-1, +0, -]

      void lua_remove (lua_State *L, int index);

      @@ -3668,7 +3813,8 @@

      3.7 - Functions and Types

      -

      lua_replace

      +

      lua_replace

      +[-1, +0, -]

      void lua_replace (lua_State *L, int index);

      @@ -3680,7 +3826,8 @@

      3.7 - Functions and Types

      -

      lua_resume

      +

      lua_resume

      +[-?, +?, -]

      int lua_resume (lua_State *L, int narg);

      @@ -3713,7 +3860,8 @@

      3.7 - Functions and Types

      -

      lua_setallocf

      +

      lua_setallocf

      +[-0, +0, -]

      void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);

      @@ -3724,7 +3872,8 @@

      3.7 - Functions and Types

      -

      lua_setfenv

      +

      lua_setfenv

      +[-1, +0, -]

      int lua_setfenv (lua_State *L, int index);

      @@ -3739,13 +3888,14 @@

      3.7 - Functions and Types

      -

      lua_setfield

      +

      lua_setfield

      +[-1, +0, e]

      void lua_setfield (lua_State *L, int index, const char *k);

      Does the equivalent to t[k] = v, -where t is the value at the given valid index index -and v is the value at the top of the stack, +where t is the value at the given valid index +and v is the value at the top of the stack.

      @@ -3757,7 +3907,8 @@

      3.7 - Functions and Types

      -

      lua_setglobal

      +

      lua_setglobal

      +[-1, +0, e]

      void lua_setglobal (lua_State *L, const char *name);

      @@ -3772,7 +3923,8 @@

      3.7 - Functions and Types

      -

      lua_setmetatable

      +

      lua_setmetatable

      +[-1, +0, -]

      int lua_setmetatable (lua_State *L, int index);

      @@ -3784,12 +3936,13 @@

      3.7 - Functions and Types

      -

      lua_settable

      +

      lua_settable

      +[-2, +0, e]

      void lua_settable (lua_State *L, int index);

      Does the equivalent to t[k] = v, -where t is the value at the given valid index index, +where t is the value at the given valid index, v is the value at the top of the stack, and k is the value just below the top. @@ -3803,7 +3956,8 @@

      3.7 - Functions and Types

      -

      lua_settop

      +

      lua_settop

      +[-?, +?, -]

      void lua_settop (lua_State *L, int index);

      @@ -3836,7 +3990,8 @@

      3.7 - Functions and Types

      -

      lua_status

      +

      lua_status

      +[-0, +0, -]

      int lua_status (lua_State *L);

      @@ -3852,7 +4007,8 @@

      3.7 - Functions and Types

      -

      lua_toboolean

      +

      lua_toboolean

      +[-0, +0, -]

      int lua_toboolean (lua_State *L, int index);

      @@ -3870,7 +4026,8 @@

      3.7 - Functions and Types

      -

      lua_tocfunction

      +

      lua_tocfunction

      +[-0, +0, -]

      lua_CFunction lua_tocfunction (lua_State *L, int index);

      @@ -3882,8 +4039,9 @@

      3.7 - Functions and Types

      -

      lua_tointeger

      -
      lua_Integer lua_tointeger (lua_State *L, int idx);
      +

      lua_tointeger

      +[-0, +0, -] +

      lua_Integer lua_tointeger (lua_State *L, int index);

      Converts the Lua value at the given acceptable index @@ -3901,12 +4059,12 @@

      3.7 - Functions and Types

      -

      lua_tolstring

      +

      lua_tolstring

      +[-0, +0, m]

      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; @@ -3932,12 +4090,13 @@

      3.7 - Functions and Types

      -

      lua_tonumber

      +

      lua_tonumber

      +[-0, +0, -]

      lua_Number lua_tonumber (lua_State *L, int index);

      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. @@ -3946,7 +4105,8 @@

      3.7 - Functions and Types

      -

      lua_topointer

      +

      lua_topointer

      +[-0, +0, -]

      const void *lua_topointer (lua_State *L, int index);

      @@ -3965,7 +4125,8 @@

      3.7 - Functions and Types

      -

      lua_tostring

      +

      lua_tostring

      +[-0, +0, m]

      const char *lua_tostring (lua_State *L, int index);

      @@ -3975,7 +4136,8 @@

      3.7 - Functions and Types

      -

      lua_tothread

      +

      lua_tothread

      +[-0, +0, -]

      lua_State *lua_tothread (lua_State *L, int index);

      @@ -3988,7 +4150,8 @@

      3.7 - Functions and Types

      -

      lua_touserdata

      +

      lua_touserdata

      +[-0, +0, -]

      void *lua_touserdata (lua_State *L, int index);

      @@ -4002,7 +4165,8 @@

      3.7 - Functions and Types

      -

      lua_type

      +

      lua_type

      +[-0, +0, -]

      int lua_type (lua_State *L, int index);

      @@ -4026,7 +4190,8 @@

      3.7 - Functions and Types

      -

      lua_typename

      +

      lua_typename

      +[-0, +0, -]

      const char *lua_typename  (lua_State *L, int tp);

      @@ -4044,7 +4209,7 @@

      3.7 - Functions and Types

      void* ud);

      -The writer function used by lua_dump. +The type of the writer function used by lua_dump. Every time it produces another piece of chunk, lua_dump calls the writer, passing along the buffer to be written (p), @@ -4054,7 +4219,7 @@

      3.7 - Functions and Types

      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. @@ -4062,7 +4227,8 @@

      3.7 - Functions and Types

      -

      lua_xmove

      +

      lua_xmove

      +[-?, +?, -]

      void lua_xmove (lua_State *from, lua_State *to, int n);

      @@ -4077,7 +4243,8 @@

      3.7 - Functions and Types

      -

      lua_yield

      +

      lua_yield

      +[-?, +?, -]

      int lua_yield  (lua_State *L, int nresults);

      @@ -4209,7 +4376,8 @@

      3.8 - The Debug Interface

      -

      lua_gethook

      +

      lua_gethook

      +[-0, +0, -]

      lua_Hook lua_gethook (lua_State *L);

      @@ -4219,7 +4387,8 @@

      3.8 - The Debug Interface

      -

      lua_gethookcount

      +

      lua_gethookcount

      +[-0, +0, -]

      int lua_gethookcount (lua_State *L);

      @@ -4229,7 +4398,8 @@

      3.8 - The Debug Interface

      -

      lua_gethookmask

      +

      lua_gethookmask

      +[-0, +0, -]

      int lua_gethookmask (lua_State *L);

      @@ -4239,7 +4409,8 @@

      3.8 - The Debug Interface

      -

      lua_getinfo

      +

      lua_getinfo

      +[-(0|1), +(0|1|2), m]

      int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);

      @@ -4279,8 +4450,8 @@

      3.8 - The Debug Interface

    • '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; @@ -4312,8 +4483,9 @@

      3.8 - The Debug Interface

      -

      lua_getlocal

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

      lua_getlocal

      +[-0, +(0|1), -] +

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

      Gets information about a local variable of a given activation record. @@ -4342,7 +4514,8 @@

      3.8 - The Debug Interface

      -

      lua_getstack

      +

      lua_getstack

      +[-0, +0, -]

      int lua_getstack (lua_State *L, int level, lua_Debug *ar);

      @@ -4363,7 +4536,8 @@

      3.8 - The Debug Interface

      -

      lua_getupvalue

      +

      lua_getupvalue

      +[-0, +(0|1), -]

      const char *lua_getupvalue (lua_State *L, int funcindex, int n);

      @@ -4423,15 +4597,16 @@

      3.8 - The Debug Interface

      -

      lua_sethook

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

      lua_sethook

      +[-0, +0, -] +

      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, @@ -4474,8 +4649,9 @@

      3.8 - The Debug Interface

      -

      lua_setlocal

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

      lua_setlocal

      +[-(0|1), +0, -] +

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

      Sets the value of a local variable of a given activation record. @@ -4495,16 +4671,17 @@

      3.8 - The Debug Interface

      -

      lua_setupvalue

      +

      lua_setupvalue

      +[-(0|1), +0, -]

      const char *lua_setupvalue (lua_State *L, int funcindex, int n);

      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).

      @@ -4545,7 +4722,7 @@

      4 - The Auxiliary Library

      Several functions in the auxiliary library are used to check C function arguments. Their names are always luaL_check* or luaL_opt*. -All of these functions raise an error if the check is not satisfied. +All of these functions throw an error if the check is not satisfied. Because the error message is formatted for arguments (e.g., "bad argument #1"), you should not use these functions for other stack values. @@ -4560,7 +4737,8 @@

      4.1 - Functions and Types

      -

      luaL_addchar

      +

      luaL_addchar

      +[-0, +0, m]

      void luaL_addchar (luaL_Buffer *B, char c);

      @@ -4571,7 +4749,8 @@

      4.1 - Functions and Types

      -

      luaL_addlstring

      +

      luaL_addlstring

      +[-0, +0, m]

      void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);

      @@ -4584,19 +4763,21 @@

      4.1 - Functions and Types

      -

      luaL_addsize

      +

      luaL_addsize

      +[-0, +0, m]

      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). -


      luaL_addstring

      +

      luaL_addstring

      +[-0, +0, m]

      void luaL_addstring (luaL_Buffer *B, const char *s);

      @@ -4609,7 +4790,8 @@

      4.1 - Functions and Types

      -

      luaL_addvalue

      +

      luaL_addvalue

      +[-1, +0, m]

      void luaL_addvalue (luaL_Buffer *B);

      @@ -4628,10 +4810,11 @@

      4.1 - Functions and Types

      -

      luaL_argcheck

      +

      luaL_argcheck

      +[-0, +0, v]

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

      @@ -4640,21 +4823,22 @@

      4.1 - Functions and Types

      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);
      +

      luaL_argerror

      +[-0, +0, v] +

      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>)
       

      @@ -4715,7 +4899,8 @@

      4.1 - Functions and Types

      -

      luaL_buffinit

      +

      luaL_buffinit

      +[-0, +0, -]

      void luaL_buffinit (lua_State *L, luaL_Buffer *B);

      @@ -4728,7 +4913,8 @@

      4.1 - Functions and Types

      -

      luaL_callmeta

      +

      luaL_callmeta

      +[-0, +(0|1), e]

      int luaL_callmeta (lua_State *L, int obj, const char *e);

      @@ -4748,7 +4934,8 @@

      4.1 - Functions and Types

      -

      luaL_checkany

      +

      luaL_checkany

      +[-0, +0, v]

      void luaL_checkany (lua_State *L, int narg);

      @@ -4759,7 +4946,8 @@

      4.1 - Functions and Types

      -

      luaL_checkint

      +

      luaL_checkint

      +[-0, +0, v]

      int luaL_checkint (lua_State *L, int narg);

      @@ -4770,7 +4958,8 @@

      4.1 - Functions and Types

      -

      luaL_checkinteger

      +

      luaL_checkinteger

      +[-0, +0, v]

      lua_Integer luaL_checkinteger (lua_State *L, int narg);

      @@ -4781,7 +4970,8 @@

      4.1 - Functions and Types

      -

      luaL_checklong

      +

      luaL_checklong

      +[-0, +0, v]

      long luaL_checklong (lua_State *L, int narg);

      @@ -4792,7 +4982,8 @@

      4.1 - Functions and Types

      -

      luaL_checklstring

      +

      luaL_checklstring

      +[-0, +0, v]

      const char *luaL_checklstring (lua_State *L, int narg, size_t *l);

      @@ -4802,10 +4993,16 @@

      4.1 - Functions and Types

      with the string's length. +

      +This function uses lua_tolstring to get its result, +so all conversions and caveats of that function apply here. + + -


      luaL_checknumber

      +

      luaL_checknumber

      +[-0, +0, v]

      lua_Number luaL_checknumber (lua_State *L, int narg);

      @@ -4816,7 +5013,8 @@

      4.1 - Functions and Types

      -

      luaL_checkoption

      +

      luaL_checkoption

      +[-0, +0, v]

      int luaL_checkoption (lua_State *L,
                             int narg,
                             const char *def,
      @@ -4846,7 +5044,8 @@ 

      4.1 - Functions and Types

      -

      luaL_checkstack

      +

      luaL_checkstack

      +[-0, +0, v]

      void luaL_checkstack (lua_State *L, int sz, const char *msg);

      @@ -4858,7 +5057,8 @@

      4.1 - Functions and Types

      -

      luaL_checkstring

      +

      luaL_checkstring

      +[-0, +0, v]

      const char *luaL_checkstring (lua_State *L, int narg);

      @@ -4866,20 +5066,28 @@

      4.1 - Functions and Types

      and returns this string. +

      +This function uses lua_tolstring to get its result, +so all conversions and caveats of that function apply here. + + -


      luaL_checktype

      +

      luaL_checktype

      +[-0, +0, v]

      void luaL_checktype (lua_State *L, int narg, int t);

      Checks whether the function argument narg has type t. +See lua_type for the encoding of types for t. -


      luaL_checkudata

      +

      luaL_checkudata

      +[-0, +0, v]

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

      @@ -4890,7 +5098,8 @@

      4.1 - Functions and Types

      -

      luaL_dofile

      +

      luaL_dofile

      +[-0, +?, m]

      int luaL_dofile (lua_State *L, const char *filename);

      @@ -4907,7 +5116,8 @@

      4.1 - Functions and Types

      -

      luaL_dostring

      +

      luaL_dostring

      +[-0, +?, m]

      int luaL_dostring (lua_State *L, const char *str);

      @@ -4924,7 +5134,8 @@

      4.1 - Functions and Types

      -

      luaL_error

      +

      luaL_error

      +[-0, +0, v]

      int luaL_error (lua_State *L, const char *fmt, ...);

      @@ -4946,7 +5157,8 @@

      4.1 - Functions and Types

      -

      luaL_getmetafield

      +

      luaL_getmetafield

      +[-0, +(0|1), m]

      int luaL_getmetafield (lua_State *L, int obj, const char *e);

      @@ -4960,7 +5172,8 @@

      4.1 - Functions and Types

      -

      luaL_getmetatable

      +

      luaL_getmetatable

      +[-0, +1, -]

      void luaL_getmetatable (lua_State *L, const char *tname);

      @@ -4971,7 +5184,8 @@

      4.1 - Functions and Types

      -

      luaL_gsub

      +

      luaL_gsub

      +[-0, +1, m]

      const char *luaL_gsub (lua_State *L,
                              const char *s,
                              const char *p,
      @@ -4987,7 +5201,8 @@ 

      4.1 - Functions and Types

      -

      luaL_loadbuffer

      +

      luaL_loadbuffer

      +[-0, +1, m]

      int luaL_loadbuffer (lua_State *L,
                            const char *buff,
                            size_t sz,
      @@ -5008,7 +5223,8 @@ 

      4.1 - Functions and Types

      -

      luaL_loadfile

      +

      luaL_loadfile

      +[-0, +1, m]

      int luaL_loadfile (lua_State *L, const char *filename);

      @@ -5034,7 +5250,8 @@

      4.1 - Functions and Types

      -

      luaL_loadstring

      +

      luaL_loadstring

      +[-0, +1, m]

      int luaL_loadstring (lua_State *L, const char *s);

      @@ -5055,7 +5272,8 @@

      4.1 - Functions and Types

      -

      luaL_newmetatable

      +

      luaL_newmetatable

      +[-0, +1, m]

      int luaL_newmetatable (lua_State *L, const char *tname);

      @@ -5075,13 +5293,15 @@

      4.1 - Functions and Types

      -

      luaL_newstate

      +

      luaL_newstate

      +[-0, +0, -]

      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. @@ -5094,7 +5314,8 @@

      4.1 - Functions and Types

      -

      luaL_openlibs

      +

      luaL_openlibs

      +[-0, +0, m]

      void luaL_openlibs (lua_State *L);

      @@ -5104,7 +5325,8 @@

      4.1 - Functions and Types

      -

      luaL_optint

      +

      luaL_optint

      +[-0, +0, v]

      int luaL_optint (lua_State *L, int narg, int d);

      @@ -5118,8 +5340,11 @@

      4.1 - Functions and Types

      -

      luaL_optinteger

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

      luaL_optinteger

      +[-0, +0, v] +

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

      If the function argument narg is a number, @@ -5132,7 +5357,8 @@

      4.1 - Functions and Types

      -

      luaL_optlong

      +

      luaL_optlong

      +[-0, +0, v]

      long luaL_optlong (lua_State *L, int narg, long d);

      @@ -5146,7 +5372,8 @@

      4.1 - Functions and Types

      -

      luaL_optlstring

      +

      luaL_optlstring

      +[-0, +0, v]

      const char *luaL_optlstring (lua_State *L,
                                    int narg,
                                    const char *d,
      @@ -5168,7 +5395,8 @@ 

      4.1 - Functions and Types

      -

      luaL_optnumber

      +

      luaL_optnumber

      +[-0, +0, v]

      lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number d);

      @@ -5182,8 +5410,11 @@

      4.1 - Functions and Types

      -

      luaL_optstring

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

      luaL_optstring

      +[-0, +0, v] +

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

      If the function argument narg is a string, @@ -5196,7 +5427,8 @@

      4.1 - Functions and Types

      -

      luaL_prepbuffer

      +

      luaL_prepbuffer

      +[-0, +0, -]

      char *luaL_prepbuffer (luaL_Buffer *B);

      @@ -5211,7 +5443,8 @@

      4.1 - Functions and Types

      -

      luaL_pushresult

      +

      luaL_pushresult

      +[-?, +1, m]

      void luaL_pushresult (luaL_Buffer *B);

      @@ -5222,7 +5455,8 @@

      4.1 - Functions and Types

      -

      luaL_ref

      +

      luaL_ref

      +[-1, +0, m]

      int luaL_ref (lua_State *L, int t);

      @@ -5268,7 +5502,8 @@

      4.1 - Functions and Types

      -

      luaL_register

      +

      luaL_register

      +[-(0|1), +1, m]

      void luaL_register (lua_State *L,
                           const char *libname,
                           const luaL_Reg *l);
      @@ -5285,7 +5520,7 @@

      4.1 - Functions and Types

      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. @@ -5302,34 +5537,37 @@

      4.1 - Functions and Types

      -

      luaL_typename

      -
      const char *luaL_typename (lua_State *L, int idx);
      +

      luaL_typename

      +[-0, +0, -] +

      const char *luaL_typename (lua_State *L, int index);

      -Returns the name of the type of the value at index idx. +Returns the name of the type of the value at the given index. -


      luaL_typerror

      +

      luaL_typerror

      +[-0, +0, v]

      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. -


      luaL_unref

      +

      luaL_unref

      +[-0, +0, -]

      void luaL_unref (lua_State *L, int t, int ref);

      @@ -5348,13 +5586,18 @@

      4.1 - Functions and Types

      -

      luaL_where

      +

      luaL_where

      +[-0, +1, m]

      void luaL_where (lua_State *L, int lvl);

      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. @@ -5379,7 +5622,7 @@

      5 - Standard Libraries

      others provide access to "outside" services (e.g., I/O); and others could be implemented in Lua itself, but are quite useful or have critical performance requirements that -deserve an implementation in C (e.g., sort). +deserve an implementation in C (e.g., table.sort).

      @@ -5413,9 +5656,8 @@

      5 - Standard Libraries

      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), @@ -5423,7 +5665,8 @@

      5 - Standard Libraries

      luaopen_string (for the string library), luaopen_table (for the table library), luaopen_math (for the mathematical library), -luaopen_io (for the I/O and the Operating System libraries), +luaopen_io (for the I/O library), +luaopen_os (for the Operating System library), and luaopen_debug (for the debug library). These functions are declared in lualib.h and should not be called directly: @@ -5547,7 +5790,7 @@

      5.1 - Basic Functions

      -


      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 +5832,6 @@

      5.1 - Basic Functions

      up to the first integer key absent from the table. -

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

      @@ -5616,6 +5855,8 @@

      5.1 - Basic Functions

      chunkname is used as the chunk name for error messages and debug information. +When absent, +it defaults to "=(load)". @@ -5649,6 +5890,11 @@

      5.1 - Basic Functions

      assert(loadstring(s))()
      +

      +When absent, +chunkname defaults to the given string. + +

      @@ -5704,7 +5950,8 @@

      5.1 - Basic Functions

      -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 +6158,7 @@

      5.1 - Basic Functions

      -This function is similar to pcall, +This function is similar to pcall, except that you can set a new error handler. @@ -6101,7 +6348,7 @@

      5.3 - Modules

      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]. @@ -6110,7 +6357,15 @@

      5.3 - Modules

      To find a loader, -first require queries package.preload[modname]. +require is guided by the package.loaders array. +By changing this array, +we can change how require looks for a module. +The following explanation is based on the default configuration +for package.loaders. + + +

      +First require queries package.preload[modname]. If it has a value, this value (which should be a function) is the loader. Otherwise require searches for a Lua loader using the @@ -6118,45 +6373,14 @@

      5.3 - Modules

      If that also fails, it searches for a C loader using the path stored in package.cpath. If that also fails, -it tries an all-in-one loader (see below). - - -

      -When loading a C library, -require first uses a dynamic link facility to link the -application with the library. -Then it tries to find a C function inside this library to -be used as the loader. -The name of this C function is the string "luaopen_" -concatenated with a copy of the module name where each dot -is replaced by an underscore. -Moreover, if the module name has a hyphen, -its prefix up to (and including) the first hyphen is removed. -For instance, if the module name is a.v1-b.c, -the function name will be luaopen_b_c. - - -

      -If require finds neither a Lua library nor a -C library for a module, -it calls the all-in-one loader. -This loader searches the C path for a library for -the root name of the given module. -For instance, when requiring a.b.c, -it will search for a C library for a. -If found, it looks into it for an open function for -the submodule; -in our example, that would be luaopen_a_b_c. -With this facility, a package can pack several C submodules -into one single library, -with each submodule keeping its original open function. +it tries an all-in-one loader (see package.loaders).

      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. @@ -6184,12 +6408,13 @@

      5.3 - Modules

      Lua initializes the C path package.cpath in the same way it initializes the Lua path package.path, using the environment variable LUA_CPATH -(plus another default path defined in luaconf.h). +or a default path defined in luaconf.h.

      +


      package.loaded

      @@ -6203,6 +6428,94 @@

      5.3 - Modules

      +

      +


      package.loaders

      + + +

      +A table used by require to control how to load modules. + + +

      +Each entry in this table is a searcher function. +When looking for a module, +require calls each of these searchers in ascending order, +with the module name (the argument given to require) as its +sole parameter. +The function may return another function (the module loader) +or a string explaining why it did not find that module +(or nil if it has nothing to say). +Lua initializes this table with four functions. + + +

      +The first searcher simply looks for a loader in the +package.preload table. + + +

      +The second searcher looks for a loader as a Lua library, +using the path stored at package.path. +A path is a sequence of templates separated by semicolons. +For each template, +the searcher will change each interrogation +mark in the template by filename, +which is the module name with each dot replaced by a +"directory separator" (such as "/" in Unix); +then it will try to open the resulting file name. +So, for instance, if the Lua path is the string + +

      +     "./?.lua;./?.lc;/usr/local/?/init.lua"
      +

      +the search for a Lua file for module foo +will try to open the files +./foo.lua, ./foo.lc, and +/usr/local/foo/init.lua, in that order. + + +

      +The third searcher looks for a loader as a C library, +using the path given by the variable package.cpath. +For instance, +if the C path is the string + +

      +     "./?.so;./?.dll;/usr/local/?/init.so"
      +

      +the searcher for module foo +will try to open the files ./foo.so, ./foo.dll, +and /usr/local/foo/init.so, in that order. +Once it finds a C library, +this searcher first uses a dynamic link facility to link the +application with the library. +Then it tries to find a C function inside the library to +be used as the loader. +The name of this C function is the string "luaopen_" +concatenated with a copy of the module name where each dot +is replaced by an underscore. +Moreover, if the module name has a hyphen, +its prefix up to (and including) the first hyphen is removed. +For instance, if the module name is a.v1-b.c, +the function name will be luaopen_b_c. + + +

      +The fourth searcher tries an all-in-one loader. +It searches the C path for a library for +the root name of the given module. +For instance, when requiring a.b.c, +it will search for a C library for a. +If found, it looks into it for an open function for +the submodule; +in our example, that would be luaopen_a_b_c. +With this facility, a package can pack several C submodules +into one single library, +with each submodule keeping its original open function. + + + +


      package.loadlib (libname, funcname)

      @@ -6252,24 +6565,6 @@

      5.3 - Modules

      is replaced by the default path. -

      -A path is a sequence of templates separated by semicolons. -For each template, require will change each interrogation -mark in the template by filename, -which is modname with each dot replaced by a -"directory separator" (such as "/" in Unix); -then it will try to load the resulting file name. -So, for instance, if the Lua path is - -

      -     "./?.lua;./?.lc;/usr/local/?/init.lua"
      -

      -the search for a Lua loader for module foo -will try to load the files -./foo.lua, ./foo.lc, and -/usr/local/foo/init.lua, in that order. - -

      @@ -6426,7 +6721,8 @@

      5.4 - String Manipulation

      This function does not accept string values -containing embedded zeros. +containing embedded zeros, +except as arguments to the q option. @@ -6436,9 +6732,6 @@

      5.4 - String Manipulation

      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,16 +6758,22 @@

      5.4 - String Manipulation

      end
      +

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


      string.gsub (s, pattern, repl [, n])

      Returns a copy of s -in which all occurrences of the pattern have been +in which all (or the first n, if given) +occurrences of the pattern have been replaced by a replacement string specified by repl, which may be a string, a table, or a function. gsub also returns, as its second value, -the total number of substitutions made. +the total number of matches that occurred.

      @@ -6511,13 +6810,6 @@

      5.4 - String Manipulation

      (that is, the original match is kept in the string). -

      -The optional last parameter n limits -the maximum number of substitutions to occur. -For instance, when n is 1 only the first occurrence of -pattern is replaced. - -

      Here are some examples: @@ -6540,7 +6832,7 @@

      5.4 - String Manipulation

      --> 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 +7116,8 @@

      5.5 - Table Manipulation


      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. @@ -6950,14 +7243,14 @@

      5.6 - Mathematical Functions

      -


      math.atan2 (x, y)

      +

      math.atan2 (y, x)

      -Returns the arc tangent of x/y (in radians), +Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. -(It also handles correctly the case of y being zero.) +(It also handles correctly the case of x being zero.) @@ -7007,7 +7300,7 @@

      5.6 - Mathematical Functions

      -Returns the the value ex. +Returns the value ex. @@ -7122,7 +7415,7 @@

      5.6 - Mathematical Functions

      -The value PI. +The value of pi. @@ -7160,13 +7453,13 @@

      5.6 - Mathematical Functions

      When called without arguments, -returns a pseudo-random real number +returns a uniform pseudo-random real number in the range [0,1). -When called with a number m, +When called with an integer number m, math.random returns -a pseudo-random integer in the range [1, m]. -When called with two numbers m and n, -math.random returns a pseudo-random +a uniform pseudo-random integer in the range [1, m]. +When called with two integer numbers m and n, +math.random returns a uniform pseudo-random integer in the range [m, n]. @@ -7261,12 +7554,14 @@

      5.7 - Input and Output Facilities

      The table io also provides three predefined file descriptors with their usual meanings from C: io.stdin, io.stdout, and io.stderr. +The I/O library never closes these files.

      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 +7626,7 @@

      5.7 - Input and Output Facilities

      -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 +7676,7 @@

      5.7 - Input and Output Facilities

      -


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

      +

      io.popen (prog [, mode])

      @@ -7596,7 +7891,7 @@

      5.7 - Input and Output Facilities

    -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 +7952,7 @@

    5.8 - Operating System Facilities

    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 +7962,7 @@

    5.8 - Operating System Facilities

    -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. @@ -7771,6 +8066,13 @@

    5.8 - Operating System Facilities

    or nil if the request cannot be honored. +

    +If locale is the empty string, +the current locale is set to an implementation-defined native locale. +If locale is the string "C", +the current locale 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 @@ -7829,7 +8131,7 @@

    5.9 - The Debug Library

    Please resist the temptation to use them as a usual programming tool: they can be very slow. -Moreover, several of its functions +Moreover, several of these functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or @@ -7920,8 +8222,10 @@

    5.9 - The Debug Library

    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 +a table with a name for the current function, +if a reasonable name can be found, +and the expression debug.getinfo(print) +returns a table with all available information about the print function. @@ -8006,9 +8310,9 @@

    5.9 - The Debug Library

    with the given meaning:
      -
    • "c": The hook is called every time Lua calls a function;
    • -
    • "r": The hook is called every time Lua returns from a function;
    • -
    • "l": The hook is called every time Lua enters a new line of code.
    • +
    • "c": the hook is called every time Lua calls a function;
    • +
    • "r": the hook is called every time Lua returns from a function;
    • +
    • "l": the hook is called every time Lua enters a new line of code.

    With a count different from zero, the hook is called after every count instructions. @@ -8080,15 +8384,16 @@

    5.9 - The Debug Library

    -


    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). @@ -8192,17 +8497,19 @@

    6 - Lua Stand-alone

    Similarly, if the global variable _PROMPT2 contains a string, its value is used as the secondary prompt (issued during incomplete statements). -Therefore, both prompts can be changed directly on the command line. -For instance, +Therefore, both prompts can be changed directly on the command line +or in any Lua programs by assigning to _PROMPT. +See the next example:
          $ lua -e"_PROMPT='myprompt> '" -i
     

    -(the outer pair of quotes is for the shell, -the inner pair is for Lua), -or in any Lua programs by assigning to _PROMPT. -Note the use of -i to enter interactive mode; otherwise, -the program would just end silently right after the assignment to _PROMPT. +(The outer pair of quotes is for the shell, +the inner pair is for Lua.) +Note the use of -i to enter interactive mode; +otherwise, +the program would just end silently +right after the assignment to _PROMPT.

    @@ -8232,7 +8539,7 @@

    6 - Lua Stand-alone

    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 find 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 +8554,7 @@

    7.1 - Changes in the Language

  • 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 +8566,7 @@

    7.1 - Changes in the Language

    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 +8579,7 @@

    7.2 - Changes in the Libraries

  • Function string.gfind was renamed string.gmatch. -(Option LUA_COMPAT_GFIND) +(See compile-time option LUA_COMPAT_GFIND in luaconf.h.)
  • @@ -8288,17 +8595,17 @@

    7.2 - Changes in the Libraries

    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.)
  • @@ -8381,29 +8688,29 @@

    8 - The Complete Syntax of Lua

    block ::= chunk - stat ::= varlist1 `=´ explist1 | + stat ::= varlist `=´ explist | functioncall | do block end | while exp do block end | repeat block until exp | if exp then block {elseif exp then block} [else block] end | for Name `=´ exp `,´ exp [`,´ exp] do block end | - for namelist in explist1 do block end | + for namelist in explist do block end | function funcname funcbody | local function Name funcbody | - local namelist [`=´ explist1] + local namelist [`=´ explist] - laststat ::= return [explist1] | break + laststat ::= return [explist] | break funcname ::= Name {`.´ Name} [`:´ Name] - varlist1 ::= var {`,´ var} + varlist ::= var {`,´ var} var ::= Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name namelist ::= Name {`,´ Name} - explist1 ::= {exp `,´} exp + explist ::= {exp `,´} exp exp ::= nil | false | true | Number | String | `...´ | function | prefixexp | tableconstructor | exp binop exp | unop exp @@ -8412,13 +8719,13 @@

    8 - The Complete Syntax of Lua

    functioncall ::= prefixexp args | prefixexp `:´ Name args - args ::= `(´ [explist1] `)´ | tableconstructor | String + args ::= `(´ [explist] `)´ | tableconstructor | String function ::= function funcbody - funcbody ::= `(´ [parlist1] `)´ block end + funcbody ::= `(´ [parlist] `)´ block end - parlist1 ::= namelist [`,´ `...´] | `...´ + parlist ::= namelist [`,´ `...´] | `...´ tableconstructor ::= `{´ [fieldlist] `}´ @@ -8443,13 +8750,14 @@

    8 - The Complete Syntax of Lua

    +
    Last update: -Mon Jun 5 17:05:27 BRT 2006 +Fri Jan 18 22:32:24 BRST 2008 diff --git a/src/lua-5.1.1/doc/readme.html b/src/lua-5.1.1/doc/readme.html index db20a69..972fadd 100644 --- a/src/lua-5.1.1/doc/readme.html +++ b/src/lua-5.1.1/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.3. + +Lua's +official web site +contains updated documentation, +especially the +reference manual. +

    +


    Last update: -Wed Sep 7 12:57:50 BRST 2005 +Wed Dec 19 13:59:14 BRST 2007 diff --git a/src/lua-5.1.1/etc/README b/src/lua-5.1.1/etc/README index ad9ca6a..5149fc9 100644 --- a/src/lua-5.1.1/etc/README +++ b/src/lua-5.1.1/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/src/lua-5.1.1/etc/lua.pc b/src/lua-5.1.1/etc/lua.pc index 21a16ba..19a5c91 100644 --- a/src/lua-5.1.1/etc/lua.pc +++ b/src/lua-5.1.1/etc/lua.pc @@ -5,7 +5,7 @@ # grep '^V=' ../Makefile V= 5.1 # grep '^R=' ../Makefile -R= 5.1.1 +R= 5.1.3 # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' prefix= /usr/local diff --git a/src/lua-5.1.1/etc/luavs.bat b/src/lua-5.1.1/etc/luavs.bat index eea175e..054b462 100644 --- a/src/lua-5.1.1/etc/luavs.bat +++ b/src/lua-5.1.1/etc/luavs.bat @@ -1,7 +1,28 @@ +@rem Script to build Lua under "Visual Studio .NET Command Prompt". +@rem Do not run 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. +@rem (contributed by David Manura and Mike Pall) + +@setlocal +@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE +@set MYLINK=link /nologo +@set MYMT=mt /nologo + cd src -cl /O2 /W3 /c /DLUA_BUILD_AS_DLL l*.c +%MYCOMPILE% /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 +%MYLINK% /DLL /out:lua51.dll l*.obj +if exist lua51.dll.manifest^ + %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 +%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c +%MYLINK% /out:lua.exe lua.obj lua51.lib +if exist lua.exe.manifest^ + %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe +%MYCOMPILE% 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 +%MYLINK% /out:luac.exe *.obj +if exist luac.exe.manifest^ + %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe +del *.obj *.manifest cd .. diff --git a/src/lua-5.1.1/etc/min.c b/src/lua-5.1.1/etc/min.c index 404bd50..6a85a4d 100644 --- a/src/lua-5.1.1/etc/min.c +++ b/src/lua-5.1.1/etc/min.c @@ -18,7 +18,7 @@ static int print(lua_State *L) if (i>1) printf("\t"); if (lua_isstring(L,i)) printf("%s",lua_tostring(L,i)); - else if (lua_isnil(L,i)==2) + else if (lua_isnil(L,i)) printf("%s","nil"); else if (lua_isboolean(L,i)) printf("%s",lua_toboolean(L,i) ? "true" : "false"); diff --git a/src/lua-5.1.1/etc/strict.lua b/src/lua-5.1.1/etc/strict.lua index 7c9fa15..604619d 100644 --- a/src/lua-5.1.1/etc/strict.lua +++ b/src/lua-5.1.1/etc/strict.lua @@ -6,6 +6,8 @@ -- anywhere or assigned to inside a function. -- +local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget + local mt = getmetatable(_G) if mt == nil then mt = {} @@ -14,9 +16,14 @@ end mt.__declared = {} +local function what () + local d = 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 +33,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/src/lua-5.1.1/src/Makefile b/src/lua-5.1.1/src/Makefile index bfc4552..e4a3cd6 100644 --- a/src/lua-5.1.1/src/Makefile +++ b/src/lua-5.1.1/src/Makefile @@ -8,7 +8,7 @@ PLAT= none CC= gcc -CFLAGS= -O0 -g -Wall $(MYCFLAGS) +CFLAGS= -O2 -Wall $(MYCFLAGS) AR= ar rcu RANLIB= ranlib RM= rm -f @@ -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= @@ -95,14 +99,15 @@ linux: $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" macosx: - $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX -# use this on Mac OS X 10.4 -# $(MAKE) all MYCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" MYLIBS="-lreadline" + $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline" +# use this on Mac OS X 10.3- +# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX 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 @@ -143,8 +148,7 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ ltm.h lzio.h lmem.h ldo.h -loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \ - lualib.h +loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h diff --git a/src/lua-5.1.1/src/lapi.c b/src/lua-5.1.1/src/lapi.c index 7c532b8..d7e8931 100644 --- a/src/lua-5.1.1/src/lapi.c +++ b/src/lua-5.1.1/src/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 roberto Exp $ +** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -123,6 +123,11 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { } +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { lua_CFunction old; lua_lock(L); @@ -749,7 +754,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { res = 0; break; } - luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); L->top--; lua_unlock(L); return res; diff --git a/src/lua-5.1.1/src/lapi.h b/src/lua-5.1.1/src/lapi.h index 9d1d435..2c3fab2 100644 --- a/src/lua-5.1.1/src/lapi.h +++ b/src/lua-5.1.1/src/lapi.h @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lauxlib.c b/src/lua-5.1.1/src/lauxlib.c index 96a6b85..10f14e2 100644 --- a/src/lua-5.1.1/src/lauxlib.c +++ b/src/lua-5.1.1/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $ +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -244,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, if (libname) { int size = libsize(l); /* check whether lib already exists */ - luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); lua_getfield(L, -1, libname); /* get _LOADED[libname] */ if (!lua_istable(L, -1)) { /* not found? */ lua_pop(L, 1); /* remove previous result */ @@ -535,7 +535,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { return "\n"; } if (feof(lf->f)) return NULL; - *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f); + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); return (*size > 0) ? lf->buff : NULL; } @@ -570,9 +570,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ if (c == '\n') c = getc(lf.f); } - if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ - fclose(lf.f); - lf.f = fopen(filename, "rb"); /* reopen in binary mode */ + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ if (lf.f == NULL) return errfile(L, "reopen", fnameindex); /* skip eventual `#!...' */ while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; @@ -581,7 +580,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { ungetc(c, lf.f); status = lua_load(L, getF, &lf, lua_tostring(L, -1)); readstatus = ferror(lf.f); - if (lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */ + if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from `lua_load' */ return errfile(L, "read", fnameindex); diff --git a/src/lua-5.1.1/src/lauxlib.h b/src/lua-5.1.1/src/lauxlib.h index 1f34308..3425823 100644 --- a/src/lua-5.1.1/src/lauxlib.h +++ b/src/lua-5.1.1/src/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $ +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lbaselib.c b/src/lua-5.1.1/src/lbaselib.c index 2df437b..eb06bce 100644 --- a/src/lua-5.1.1/src/lbaselib.c +++ b/src/lua-5.1.1/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.191.1.4 2008/01/20 13:53:22 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 */ @@ -477,15 +477,52 @@ static const luaL_Reg base_funcs[] = { ** ======================================================= */ +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + static int auxresume (lua_State *L, lua_State *co, int narg) { - int status; + int status = costatus(L, co); if (!lua_checkstack(co, narg)) luaL_error(L, "too many arguments to resume"); - if (lua_status(co) == 0 && lua_gettop(co) == 0) { - lua_pushliteral(L, "cannot resume dead coroutine"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); return -1; /* error flag */ } lua_xmove(L, co, narg); + lua_setlevel(L, co); status = lua_resume(co, narg); if (status == 0 || status == LUA_YIELD) { int nres = lua_gettop(co); @@ -556,39 +593,10 @@ static int luaB_yield (lua_State *L) { } -static int luaB_costatus (lua_State *L) { - lua_State *co = lua_tothread(L, 1); - luaL_argcheck(L, co, 1, "coroutine expected"); - if (L == co) lua_pushliteral(L, "running"); - else { - switch (lua_status(co)) { - case LUA_YIELD: - lua_pushliteral(L, "suspended"); - break; - case 0: { - lua_Debug ar; - if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ - lua_pushliteral(L, "normal"); /* it is running */ - else if (lua_gettop(co) == 0) - lua_pushliteral(L, "dead"); - else - lua_pushliteral(L, "suspended"); /* initial state */ - break; - } - default: /* some error occured */ - lua_pushliteral(L, "dead"); - break; - } - } - return 1; -} - - static int luaB_corunning (lua_State *L) { if (lua_pushthread(L)) - return 0; /* main thread is not a coroutine */ - else - return 1; + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; } diff --git a/src/lua-5.1.1/src/lcode.c b/src/lua-5.1.1/src/lcode.c index b71acd8..cff626b 100644 --- a/src/lua-5.1.1/src/lcode.c +++ b/src/lua-5.1.1/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.25.1.3 2007/12/28 15:32:23 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; } @@ -688,7 +699,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; switch (op) { case OPR_MINUS: { - if (e->k == VK) + if (!isnumeral(e)) luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ codearith(fs, OP_UNM, e, &e2); break; @@ -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/src/lua-5.1.1/src/lcode.h b/src/lua-5.1.1/src/lcode.h index c02cb2b..b941c60 100644 --- a/src/lua-5.1.1/src/lcode.h +++ b/src/lua-5.1.1/src/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $ +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/ldblib.c b/src/lua-5.1.1/src/ldblib.c index 26a19b6..67de122 100644 --- a/src/lua-5.1.1/src/ldblib.c +++ b/src/lua-5.1.1/src/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -255,24 +255,25 @@ static void gethooktable (lua_State *L) { static int db_sethook (lua_State *L) { - int arg; + int arg, mask, count; + lua_Hook func; lua_State *L1 = getthread(L, &arg); if (lua_isnoneornil(L, arg+1)) { lua_settop(L, arg+1); - lua_sethook(L1, NULL, 0, 0); /* turn off hooks */ + func = NULL; mask = 0; count = 0; /* turn off hooks */ } else { const char *smask = luaL_checkstring(L, arg+2); - int count = luaL_optint(L, arg+3, 0); luaL_checktype(L, arg+1, LUA_TFUNCTION); - lua_sethook(L1, hookf, makemask(smask, count), count); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); } - gethooktable(L1); - lua_pushlightuserdata(L1, L1); + gethooktable(L); + lua_pushlightuserdata(L, L1); lua_pushvalue(L, arg+1); - lua_xmove(L, L1, 1); - lua_rawset(L1, -3); /* set new hook */ - lua_pop(L1, 1); /* remove hook table */ + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ return 0; } @@ -286,11 +287,10 @@ static int db_gethook (lua_State *L) { if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { - gethooktable(L1); - lua_pushlightuserdata(L1, L1); - lua_rawget(L1, -2); /* get hook */ - lua_remove(L1, -2); /* remove hook table */ - lua_xmove(L1, L, 1); + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushinteger(L, lua_gethookcount(L1)); diff --git a/src/lua-5.1.1/src/ldebug.c b/src/lua-5.1.1/src/ldebug.c index 8919a01..9eac4a9 100644 --- a/src/lua-5.1.1/src/ldebug.c +++ b/src/lua-5.1.1/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.29.1.3 2007/12/28 15:32:23 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: { @@ -561,8 +563,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { - if (ttisstring(p1)) p1 = p2; - lua_assert(!ttisstring(p1)); + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); luaG_typeerror(L, p1, "concatenate"); } diff --git a/src/lua-5.1.1/src/ldebug.h b/src/lua-5.1.1/src/ldebug.h index 9c76aa1..ba28a97 100644 --- a/src/lua-5.1.1/src/ldebug.h +++ b/src/lua-5.1.1/src/ldebug.h @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/ldo.c b/src/lua-5.1.1/src/ldo.c index ab86fb7..8de05f7 100644 --- a/src/lua-5.1.1/src/ldo.c +++ b/src/lua-5.1.1/src/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 roberto Exp $ +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) { L->base = L->ci->base; luaF_close(L, L->base); /* close eventual pending closures */ luaD_seterrorobj(L, status, L->base); - L->nCcalls = 0; + L->nCcalls = L->baseCcalls; L->allowhook = 1; restore_stack_limit(L); L->errfunc = 0; @@ -332,7 +332,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) { ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ luaD_callhook(L, LUA_HOOKRET, -1); if (f_isLua(L->ci)) { /* Lua function? */ - while (L->ci->tailcalls--) /* call hook for eventual tail calls */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ luaD_callhook(L, LUA_HOOKTAILRET, -1); } return restorestack(L, fr); @@ -417,22 +417,24 @@ static int resume_error (lua_State *L, const char *msg) { LUA_API int lua_resume (lua_State *L, int nargs) { int status; lua_lock(L); - if (L->status != LUA_YIELD) { - if (L->status != 0) - return resume_error(L, "cannot resume dead coroutine"); - else if (L->ci != L->base_ci) + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) return resume_error(L, "cannot resume non-suspended coroutine"); - } + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); luai_userstateresume(L, nargs); - lua_assert(L->errfunc == 0 && L->nCcalls == 0); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; status = luaD_rawrunprotected(L, resume, L->top - nargs); if (status != 0) { /* error? */ L->status = cast_byte(status); /* mark thread as `dead' */ luaD_seterrorobj(L, status, L->top); L->ci->top = L->top; } - else + else { + lua_assert(L->nCcalls == L->baseCcalls); status = L->status; + } + --L->nCcalls; lua_unlock(L); return status; } @@ -441,7 +443,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); - if (L->nCcalls > 0) + if (L->nCcalls > L->baseCcalls) luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); L->base = L->top - nresults; /* protect stack slots below */ L->status = LUA_YIELD; diff --git a/src/lua-5.1.1/src/ldo.h b/src/lua-5.1.1/src/ldo.h index b2de92b..98fddac 100644 --- a/src/lua-5.1.1/src/ldo.h +++ b/src/lua-5.1.1/src/ldo.h @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $ +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/ldump.c b/src/lua-5.1.1/src/ldump.c index f08277d..c9d3d48 100644 --- a/src/lua-5.1.1/src/ldump.c +++ b/src/lua-5.1.1/src/ldump.c @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $ +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lfunc.c b/src/lua-5.1.1/src/lfunc.c index b8cd67b..813e88f 100644 --- a/src/lua-5.1.1/src/lfunc.c +++ b/src/lua-5.1.1/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.12.1.2 2007/12/28 14:58:43 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/src/lua-5.1.1/src/lfunc.h b/src/lua-5.1.1/src/lfunc.h index 2e02419..a68cf51 100644 --- a/src/lua-5.1.1/src/lfunc.h +++ b/src/lua-5.1.1/src/lfunc.h @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lgc.c b/src/lua-5.1.1/src/lgc.c index 2d24a12..d9e0b78 100644 --- a/src/lua-5.1.1/src/lgc.c +++ b/src/lua-5.1.1/src/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $ +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lgc.h b/src/lua-5.1.1/src/lgc.h index 5f69acb..5a8dc60 100644 --- a/src/lua-5.1.1/src/lgc.h +++ b/src/lua-5.1.1/src/lgc.h @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $ +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/linit.c b/src/lua-5.1.1/src/linit.c index c92b156..c1f90df 100644 --- a/src/lua-5.1.1/src/linit.c +++ b/src/lua-5.1.1/src/linit.c @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ ** Initialization of libraries for lua.c ** See Copyright Notice in lua.h */ @@ -13,6 +13,7 @@ #include "lualib.h" #include "lauxlib.h" + static const luaL_Reg lualibs[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, diff --git a/src/lua-5.1.1/src/liolib.c b/src/lua-5.1.1/src/liolib.c index be60972..e79ed1c 100644 --- a/src/lua-5.1.1/src/liolib.c +++ b/src/lua-5.1.1/src/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $ +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -51,7 +51,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) { } -#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) static int io_type (lua_State *L) { @@ -70,7 +70,7 @@ static int io_type (lua_State *L) { static FILE *tofile (lua_State *L) { - FILE **f = topfile(L); + FILE **f = tofilep(L); if (*f == NULL) luaL_error(L, "attempt to use a closed file"); return *f; @@ -93,19 +93,31 @@ static FILE **newfile (lua_State *L) { /* -** this function has a separated environment, which defines the -** correct __close for 'popen' files +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files */ static int io_pclose (lua_State *L) { - FILE **p = topfile(L); + FILE **p = tofilep(L); int ok = lua_pclose(L, *p); *p = NULL; return pushresult(L, ok, NULL); } +/* +** function to close regular files +*/ static int io_fclose (lua_State *L) { - FILE **p = topfile(L); + FILE **p = tofilep(L); int ok = (fclose(*p) == 0); *p = NULL; return pushresult(L, ok, NULL); @@ -128,18 +140,18 @@ static int io_close (lua_State *L) { static int io_gc (lua_State *L) { - FILE *f = *topfile(L); - /* ignore closed files and standard files */ - if (f != NULL && f != stdin && f != stdout && f != stderr) + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) aux_close(L); return 0; } static int io_tostring (lua_State *L) { - FILE *f = *topfile(L); + FILE *f = *tofilep(L); if (f == NULL) - lua_pushstring(L, "file (closed)"); + lua_pushliteral(L, "file (closed)"); else lua_pushfstring(L, "file (%p)", f); return 1; @@ -155,6 +167,10 @@ static int io_open (lua_State *L) { } +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ static int io_popen (lua_State *L) { const char *filename = luaL_checkstring(L, 1); const char *mode = luaL_optstring(L, 2, "r"); @@ -280,7 +296,7 @@ static int read_line (lua_State *L, FILE *f) { char *p = luaL_prepbuffer(&b); if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ luaL_pushresult(&b); /* close buffer */ - return (lua_strlen(L, -1) > 0); /* check whether read something */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ } l = strlen(p); if (l == 0 || p[l-1] != '\n') @@ -308,7 +324,7 @@ static int read_chars (lua_State *L, FILE *f, size_t n) { n -= nr; /* still have to read `n' chars */ } while (n > 0 && nr == rlen); /* until end of count or eof */ luaL_pushresult(&b); /* close buffer */ - return (n == 0 || lua_strlen(L, -1) > 0); + return (n == 0 || lua_objlen(L, -1) > 0); } @@ -502,31 +518,36 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { lua_pushvalue(L, -1); lua_rawseti(L, LUA_ENVIRONINDEX, k); } - lua_setfield(L, -2, fname); + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); +} + + +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); } LUALIB_API int luaopen_io (lua_State *L) { createmeta(L); /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ - lua_createtable(L, 2, 1); + newfenv(L, io_fclose); lua_replace(L, LUA_ENVIRONINDEX); /* open library */ luaL_register(L, LUA_IOLIBNAME, iolib); /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, 0, "stderr"); - /* create environment for 'popen' */ + lua_pop(L, 1); /* pop environment for default files */ lua_getfield(L, -1, "popen"); - lua_createtable(L, 0, 1); - lua_pushcfunction(L, io_pclose); - lua_setfield(L, -2, "__close"); - lua_setfenv(L, -2); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ lua_pop(L, 1); /* pop 'popen' */ - /* set default close function */ - lua_pushcfunction(L, io_fclose); - lua_setfield(L, LUA_ENVIRONINDEX, "__close"); return 1; } diff --git a/src/lua-5.1.1/src/llimits.h b/src/lua-5.1.1/src/llimits.h index b03221a..ca8dcb7 100644 --- a/src/lua-5.1.1/src/llimits.h +++ b/src/lua-5.1.1/src/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lmathlib.c b/src/lua-5.1.1/src/lmathlib.c index d181a73..441fbf7 100644 --- a/src/lua-5.1.1/src/lmathlib.c +++ b/src/lua-5.1.1/src/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $ +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ ** Standard mathematical library ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lmem.c b/src/lua-5.1.1/src/lmem.c index cef2bc5..ae7d8c9 100644 --- a/src/lua-5.1.1/src/lmem.c +++ b/src/lua-5.1.1/src/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lmem.h b/src/lua-5.1.1/src/lmem.h index 19df1fb..7c2dcb3 100644 --- a/src/lua-5.1.1/src/lmem.h +++ b/src/lua-5.1.1/src/lmem.h @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/loadlib.c b/src/lua-5.1.1/src/loadlib.c index 08722e1..d955f3e 100644 --- a/src/lua-5.1.1/src/loadlib.c +++ b/src/lua-5.1.1/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.52.1.2 2007/12/28 14:58:43 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/src/lua-5.1.1/src/lobject.c b/src/lua-5.1.1/src/lobject.c index acde82c..4ff5073 100644 --- a/src/lua-5.1.1/src/lobject.c +++ b/src/lua-5.1.1/src/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $ +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lobject.h b/src/lua-5.1.1/src/lobject.h index 8ce4405..e7199df 100644 --- a/src/lua-5.1.1/src/lobject.h +++ b/src/lua-5.1.1/src/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $ +** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lopcodes.c b/src/lua-5.1.1/src/lopcodes.c index bf9cd52..4cc7452 100644 --- a/src/lua-5.1.1/src/lopcodes.c +++ b/src/lua-5.1.1/src/lopcodes.c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $ +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lopcodes.h b/src/lua-5.1.1/src/lopcodes.h index 48105f1..41224d6 100644 --- a/src/lua-5.1.1/src/lopcodes.h +++ b/src/lua-5.1.1/src/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $ +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/loslib.c b/src/lua-5.1.1/src/loslib.c index 7c6c5d6..da06a57 100644 --- a/src/lua-5.1.1/src/loslib.c +++ b/src/lua-5.1.1/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.19.1.3 2008/01/18 16:38:18 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; } @@ -204,7 +215,6 @@ static int os_setlocale (lua_State *L) { static int os_exit (lua_State *L) { exit(luaL_optint(L, 1, EXIT_SUCCESS)); - return 0; /* to avoid warnings */ } static const luaL_Reg syslib[] = { diff --git a/src/lua-5.1.1/src/lparser.h b/src/lua-5.1.1/src/lparser.h index e5b5b57..18836af 100644 --- a/src/lua-5.1.1/src/lparser.h +++ b/src/lua-5.1.1/src/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $ +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lstate.c b/src/lua-5.1.1/src/lstate.c index 4bcb759..4313b83 100644 --- a/src/lua-5.1.1/src/lstate.c +++ b/src/lua-5.1.1/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $ +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, global_State *g) { resethookcount(L); L->openupval = NULL; L->size_ci = 0; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; L->status = 0; L->base_ci = L->ci = NULL; L->savedpc = NULL; @@ -205,7 +205,7 @@ LUA_API void lua_close (lua_State *L) { do { /* repeat until no more errors */ L->ci = L->base_ci; L->base = L->top = L->ci->base; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); lua_assert(G(L)->tmudata == NULL); luai_userstateclose(L); diff --git a/src/lua-5.1.1/src/lstate.h b/src/lua-5.1.1/src/lstate.h index d296a4c..3bc575b 100644 --- a/src/lua-5.1.1/src/lstate.h +++ b/src/lua-5.1.1/src/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $ +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -112,6 +112,7 @@ struct lua_State { int stacksize; int size_ci; /* size of array `base_ci' */ unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ lu_byte hookmask; lu_byte allowhook; int basehookcount; diff --git a/src/lua-5.1.1/src/lstring.c b/src/lua-5.1.1/src/lstring.c index 4319930..4911315 100644 --- a/src/lua-5.1.1/src/lstring.c +++ b/src/lua-5.1.1/src/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lstring.h b/src/lua-5.1.1/src/lstring.h index 1d2e91e..73a2ff8 100644 --- a/src/lua-5.1.1/src/lstring.h +++ b/src/lua-5.1.1/src/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lstrlib.c b/src/lua-5.1.1/src/lstrlib.c index f93a8af..ca333ba 100644 --- a/src/lua-5.1.1/src/lstrlib.c +++ b/src/lua-5.1.1/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.132.1.3 2007/12/28 15:32:23 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -629,10 +629,6 @@ static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, lua_gettable(L, 3); break; } - default: { - luaL_argerror(L, 3, "string/function/table expected"); - return; - } } if (!lua_toboolean(L, -1)) { /* nil or false? */ lua_pop(L, 1); @@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) { size_t srcl; const char *src = luaL_checklstring(L, 1, &srcl); const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); int max_s = luaL_optint(L, 4, srcl+1); int anchor = (*p == '^') ? (p++, 1) : 0; int n = 0; MatchState ms; luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); luaL_buffinit(L, &b); ms.L = L; ms.src_init = src; @@ -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/src/lua-5.1.1/src/ltable.c b/src/lua-5.1.1/src/ltable.c index bc91cac..ec84f4f 100644 --- a/src/lua-5.1.1/src/ltable.c +++ b/src/lua-5.1.1/src/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $ +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -84,8 +84,8 @@ static const Node dummynode_ = { static Node *hashnum (const Table *t, lua_Number n) { unsigned int a[numints]; int i; - n += 1; /* normalize number (avoid -0) */ - lua_assert(sizeof(a) <= sizeof(n)); + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); memcpy(a, &n, sizeof(a)); for (i = 1; i < numints; i++) a[0] += a[i]; return hashmod(t, a[0]); diff --git a/src/lua-5.1.1/src/ltable.h b/src/lua-5.1.1/src/ltable.h index 09193cd..f5b9d5e 100644 --- a/src/lua-5.1.1/src/ltable.h +++ b/src/lua-5.1.1/src/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/ltablib.c b/src/lua-5.1.1/src/ltablib.c index 453b23b..06f1c37 100644 --- a/src/lua-5.1.1/src/ltablib.c +++ b/src/lua-5.1.1/src/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $ +** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -118,7 +118,8 @@ static int tinsert (lua_State *L) { static int tremove (lua_State *L) { int e = aux_getn(L, 1); int pos = luaL_optint(L, 2, e); - if (e == 0) return 0; /* table is `empty' */ + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ luaL_setn(L, 1, e - 1); /* t.n = n-1 */ lua_rawgeti(L, 1, pos); /* result = t[pos] */ for ( ;pos SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX) @@ -666,7 +667,7 @@ union luai_Cast { double l_d; long l_l; }; */ #if defined(LUA_USE_POPEN) -#define lua_popen(L,c,m) ((void)L, popen(c,m)) +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #elif defined(LUA_WIN) diff --git a/src/lua-5.1.1/src/lualib.h b/src/lua-5.1.1/src/lualib.h index 0c76232..469417f 100644 --- a/src/lua-5.1.1/src/lualib.h +++ b/src/lua-5.1.1/src/lualib.h @@ -1,5 +1,5 @@ /* -** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $ +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua standard libraries ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lundump.c b/src/lua-5.1.1/src/lundump.c index 7fc635e..731c064 100644 --- a/src/lua-5.1.1/src/lundump.c +++ b/src/lua-5.1.1/src/lundump.c @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $ +** $Id: lundump.c,v 2.7.1.2 2008/01/18 16:39:11 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -29,6 +29,7 @@ typedef struct { #ifdef LUAC_TRUST_BINARIES #define IF(c,s) +#define error(S,s) #else #define IF(c,s) if (c) error(S,s) @@ -47,6 +48,7 @@ static void error(LoadState* S, const char* why) static void LoadBlock(LoadState* S, void* b, size_t size) { size_t r=luaZ_read(S->Z,b,size); + UNUSED(r); IF (r!=0, "unexpected end"); } @@ -122,7 +124,7 @@ static void LoadConstants(LoadState* S, Proto* f) setsvalue2n(S->L,o,LoadString(S)); break; default: - IF (1, "bad constant"); + error(S,"bad constant"); break; } } diff --git a/src/lua-5.1.1/src/lundump.h b/src/lua-5.1.1/src/lundump.h index 58cca5d..c80189d 100644 --- a/src/lua-5.1.1/src/lundump.h +++ b/src/lua-5.1.1/src/lundump.h @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $ +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lvm.c b/src/lua-5.1.1/src/lvm.c index 1e3ea4c..ee3256a 100644 --- a/src/lua-5.1.1/src/lvm.c +++ b/src/lua-5.1.1/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.63.1.3 2007/12/28 15:32:23 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -61,11 +61,9 @@ static void traceexec (lua_State *L, const Instruction *pc) { lu_byte mask = L->hookmask; const Instruction *oldpc = L->savedpc; L->savedpc = pc; - if (mask > LUA_MASKLINE) { /* instruction-hook set? */ - if (L->hookcount == 0) { - resethookcount(L); - luaD_callhook(L, LUA_HOOKCOUNT, -1); - } + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); } if (mask & LUA_MASKLINE) { Proto *p = ci_func(L->ci)->l.p; @@ -165,7 +163,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 +279,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/src/lua-5.1.1/src/lvm.h b/src/lua-5.1.1/src/lvm.h index 788423f..bfe4f56 100644 --- a/src/lua-5.1.1/src/lvm.h +++ b/src/lua-5.1.1/src/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $ +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lzio.c b/src/lua-5.1.1/src/lzio.c index 5121ada..293edd5 100644 --- a/src/lua-5.1.1/src/lzio.c +++ b/src/lua-5.1.1/src/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $ +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** a generic input stream interface ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/lzio.h b/src/lua-5.1.1/src/lzio.h index 8f403b8..51d695d 100644 --- a/src/lua-5.1.1/src/lzio.h +++ b/src/lua-5.1.1/src/lzio.h @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ ** Buffered streams ** See Copyright Notice in lua.h */ diff --git a/src/lua-5.1.1/src/print.c b/src/lua-5.1.1/src/print.c index 2a4fb3e..e240cfc 100644 --- a/src/lua-5.1.1/src/print.c +++ b/src/lua-5.1.1/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