├── .gitignore ├── COPYING ├── all.config ├── bin ├── README └── srluab │ └── README ├── build ├── build-all.bat ├── build.bat ├── default.config ├── dll.config ├── exe.config ├── install.lua ├── lake ├── lakefile ├── lfs.config ├── lib └── README ├── linenoise ├── Makefile ├── README.markdown ├── example.c ├── linenoise.c └── linenoise.h ├── lua-5.2.2 ├── Makefile ├── lapi.c ├── lapi.h ├── lauxlib.c ├── lauxlib.h ├── lbaselib.c ├── lbitlib.c ├── lcode.c ├── lcode.h ├── lcorolib.c ├── lctype.c ├── lctype.h ├── ldblib.c ├── ldebug.c ├── ldebug.h ├── ldo.c ├── ldo.h ├── ldump.c ├── lfunc.c ├── lfunc.h ├── lgc.c ├── lgc.h ├── linit.c.in ├── liolib.c ├── llex.c ├── llex.h ├── llimits.h ├── llinit.c ├── lmathlib.c ├── lmem.c ├── lmem.h ├── loadlib.c ├── lobject.c ├── lobject.h ├── lopcodes.c ├── lopcodes.h ├── loslib.c ├── lparser.c ├── lparser.h ├── lstate.c ├── lstate.h ├── lstring.c ├── lstring.h ├── lstrlib.c ├── ltable.c ├── ltable.h ├── ltablib.c ├── ltm.c ├── ltm.h ├── lua.c ├── lua.h ├── lua.hpp ├── luac.c ├── luaconf.h ├── lualib.h ├── lundump.c ├── lundump.h ├── lvm.c ├── lvm.h ├── lzio.c └── lzio.h ├── lua-5.3.0 ├── Makefile ├── README ├── doc │ ├── contents.html │ ├── logo.gif │ ├── lua.1 │ ├── lua.css │ ├── luac.1 │ ├── manual.css │ ├── manual.html │ ├── osi-certified-72x60.png │ └── readme.html └── src │ ├── Makefile │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lbitlib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── linit.c.in │ ├── liolib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.hpp │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── lua.config ├── lua ├── README └── ml.lua ├── luaish ├── config.lua ├── lua.lua ├── luaish.lua └── t.lua ├── modules ├── bc.lake ├── bc │ ├── Makefile │ ├── README │ ├── config.h │ ├── lbc.c │ ├── number.c │ ├── number.h │ └── test.lua ├── complex.lake ├── complex │ ├── README │ ├── lcomplex.c │ └── test.lua ├── curses_c.lake ├── inotify.lake ├── lfs │ ├── COPYING │ ├── lfs.c │ ├── lfs.h │ └── test.lua ├── linenoise.lake ├── linotify │ ├── COPYRIGHT │ ├── README │ ├── linotify.c │ └── test.lua ├── lpeg.lake ├── lpeg │ ├── lpeg.c │ ├── lpeg.h │ ├── re.lua │ └── test.lua ├── lsqlite3.lake ├── lsqlite3_svn08 │ ├── HISTORY │ ├── Makefile │ ├── README │ ├── doc │ │ ├── lsqlite3.pod │ │ ├── lsqlite3.wiki │ │ └── pod2html.pl │ ├── examples │ │ ├── aggregate.lua │ │ ├── function.lua │ │ ├── order.lua │ │ ├── simple.lua │ │ ├── smart.lua │ │ ├── statement.lua │ │ └── tracing.lua │ ├── installpath.lua │ ├── lsqlite3-0.8-1.rockspec │ ├── lsqlite3.c │ ├── lunit.lua │ ├── test.lua │ └── tests-sqlite3.lua ├── ltcl.lake ├── ltcltk-0.9-2 │ ├── Makefile │ ├── clean.sh │ ├── doc │ │ ├── LICENSE │ │ ├── README │ │ ├── README_ltcl │ │ └── README_ltk │ ├── ltcl.c │ ├── ltcltk-0.9-2.rockspec │ ├── ltk.lua │ └── samples │ │ ├── ltcltest.lua │ │ ├── ltcltest.output │ │ ├── ltkaddwidget.lua │ │ ├── ltkcheckers.lua │ │ ├── ltkfuncplotter.lua │ │ ├── ltkhello.lua │ │ ├── ltkhtext.lua │ │ ├── ltkimage.lua │ │ ├── ltkoptionmenu.lua │ │ ├── renumbertests.lua │ │ ├── tkbrowse.lua │ │ ├── tkhello.lua │ │ └── tktcolor.lua ├── lua-linenoise │ ├── COPYING │ ├── Makefile │ ├── README.md │ ├── example.lua │ ├── linenoise-0.1-1.rockspec │ ├── linenoise.c │ └── lua.lua ├── luaexpat │ ├── src │ │ ├── lxp.def │ │ ├── lxp │ │ │ └── lom.lua │ │ ├── lxplib.c │ │ ├── lxplib.h │ │ └── test-driver.lua │ └── tests │ │ ├── test-lom.lua │ │ └── test.lua ├── luaposix │ ├── AUTHORS │ ├── COPYING │ ├── ChangeLog.old │ ├── NEWS │ ├── README │ ├── bsd-strlcpy.c │ ├── curses.lua │ ├── lcurses.c │ ├── lposix.c │ ├── lua52compat.h │ ├── posix.lua │ ├── tests-curses.lua │ ├── tests-fcntl.lua │ ├── tests-posix.lua │ ├── tests-posix.output │ └── tree.lua ├── luasignal │ ├── LICENSE │ ├── README │ ├── TODO │ └── src │ │ ├── queue.c │ │ ├── queue.h │ │ ├── signal.c │ │ ├── signal.luadoc │ │ ├── signames.c │ │ └── signames.h ├── luasocket │ ├── LICENSE │ ├── NEW │ ├── README │ ├── etc │ │ ├── README │ │ ├── b64.lua │ │ ├── check-links.lua │ │ ├── check-memory.lua │ │ ├── dict.lua │ │ ├── dispatch.lua │ │ ├── eol.lua │ │ ├── forward.lua │ │ ├── get.lua │ │ ├── lp.lua │ │ ├── qp.lua │ │ └── tftp.lua │ ├── samples │ │ ├── README │ │ ├── cddb.lua │ │ ├── daytimeclnt.lua │ │ ├── echoclnt.lua │ │ ├── echosrvr.lua │ │ ├── listener.lua │ │ ├── lpr.lua │ │ ├── talker.lua │ │ └── tinyirc.lua │ ├── src │ │ ├── auxiliar.c │ │ ├── auxiliar.h │ │ ├── buffer.c │ │ ├── buffer.h │ │ ├── except.c │ │ ├── except.h │ │ ├── ftp.lua │ │ ├── globals.lua │ │ ├── headers.lua │ │ ├── http.lua │ │ ├── inet.c │ │ ├── inet.h │ │ ├── io.c │ │ ├── io.h │ │ ├── ltn12.lua │ │ ├── luasocket.c │ │ ├── luasocket.h │ │ ├── makefile │ │ ├── mbox.lua │ │ ├── mime.c │ │ ├── mime.h │ │ ├── mime.lua │ │ ├── options.c │ │ ├── options.h │ │ ├── select.c │ │ ├── select.h │ │ ├── serial.c │ │ ├── smtp.lua │ │ ├── socket.h │ │ ├── socket.lua │ │ ├── tcp.c │ │ ├── tcp.h │ │ ├── test-driver.lua │ │ ├── timeout.c │ │ ├── timeout.h │ │ ├── tp.lua │ │ ├── udp.c │ │ ├── udp.h │ │ ├── unix.c │ │ ├── unix.h │ │ ├── url.lua │ │ ├── usocket.c │ │ ├── usocket.h │ │ ├── wsocket.c │ │ └── wsocket.h │ └── test │ │ ├── README │ │ ├── driver.lua │ │ ├── find-connect-limit │ │ ├── tcp-getoptions │ │ ├── testclnt.lua │ │ ├── testsrvr.lua │ │ ├── testsupport.lua │ │ ├── udp-zero-length-send │ │ └── udp-zero-length-send-recv ├── luasql.odbc.lake ├── luasql │ ├── README │ ├── example.lua │ ├── license.html │ └── src │ │ ├── ls_mysql.c │ │ ├── ls_odbc.c │ │ ├── ls_postgres.c │ │ ├── luasql.c │ │ └── luasql.h ├── lxp.lake ├── manifest ├── mime.core.lake ├── posix_c.lake ├── socket.core.lake ├── struct │ ├── COPYING │ ├── struct.c │ └── test.lua ├── winapi-1.4 │ ├── winapi.c │ ├── winapi.l.c │ ├── wutils.c │ └── wutils.h └── winapi.lake ├── readme.md ├── setpath ├── shared.config ├── srlua ├── Makefile ├── README ├── glue.c ├── glue.h ├── srlua.c ├── test.lua └── wsrlua.c ├── test-dynamic.bat ├── test-static ├── test-static.bat ├── test.lake ├── test └── README ├── tests ├── tests.bat └── tools ├── soar.lua └── srlua.lua /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.obj 3 | *.d 4 | lib/ 5 | bin/ 6 | lua/ 7 | test/ 8 | 9 | 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Steve Donovan 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so, subject to the following 8 | conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies 11 | or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 18 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /all.config: -------------------------------------------------------------------------------- 1 | --- building the kitchen sink --- 2 | exclude = 'debug' 3 | if PLAT == 'Windows' then 4 | include = 'lfs winapi socket.core ' 5 | if CC == 'gcc' then include = include .. 'complex' end 6 | else 7 | include = 'lfs complex socket.core posix_c curses_c ltcl' 8 | readline = false 9 | end 10 | OPTIMIZE='O2' 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bin/README: -------------------------------------------------------------------------------- 1 | Executables and shared libraries end up here. If your Lua52 is built with custom_lua_path = true then this is where it will find its binary modules 2 | -------------------------------------------------------------------------------- /bin/srluab/README: -------------------------------------------------------------------------------- 1 | This is where srlua stub exes will go 2 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | LUA="lua" 3 | CC="gcc" 4 | 5 | while test $# -gt 0 6 | do 7 | case "$1" in 8 | (*=*) eval $1;; 9 | -h|--help) echo "optionally LUA=lua, PLAT=plat, CC=cc, LUA53=1"; exit;; 10 | esac 11 | shift 12 | done 13 | 14 | if test -z $LUA53 15 | then 16 | SOURCE='lua-5.2.2' 17 | LUAVS='' 18 | else 19 | SOURCE='lua-5.3.0/src' 20 | LUAVS='LUA53=1' 21 | fi 22 | 23 | quiet () { 24 | cmd=$1 25 | shift 26 | env $cmd $* 2>&1 > /dev/null 27 | } 28 | 29 | if ! quiet which $CC 30 | then 31 | echo "compiler $CC cannot be found" 32 | exit 33 | else 34 | if [ "$CC" != "gcc" ] 35 | then 36 | CC="CC=$CC" 37 | else 38 | CC='' 39 | fi 40 | fi 41 | 42 | if quiet which $LUA 43 | then 44 | if ! quiet $LUA -llfs -e "print(1)" 45 | then 46 | echo "Please install LuaFileSystem" 47 | exit 48 | fi 49 | else # have to bootstrap! 50 | echo "$LUA not found, bootstrapping" 51 | if [ -z "$PLAT" ] 52 | then 53 | case "$(uname)" in 54 | "Linux" ) PLAT=linux;; 55 | "Darwin" ) PLAT=macosx;; 56 | * ) PLAT=posix;; 57 | esac 58 | HERE=$PWD 59 | cd $SOURCE 60 | if ! make $PLAT 61 | then 62 | echo "bootstrap build borked" 63 | exit 64 | fi 65 | rm lua.o loadlib.o 66 | cd $HERE 67 | sh setpath 68 | LUA=luaboot 69 | fi 70 | fi 71 | 72 | # now let Lake do the hard part ... 73 | CMD="env $LUA lake $CC $LUAVS" 74 | echo $CMD 75 | if $CMD 76 | then 77 | env $LUA lake install.lua $LUA53 78 | fi 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /build-all.bat: -------------------------------------------------------------------------------- 1 | lua lake 2 | lua lake STATIC=1 3 | lua lake install.lua 4 | 5 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem do we already have lake? 3 | for %%X in (lake.exe) do ( 4 | set LAKE=%%~$PATH:X 5 | if defined LAKE goto :lake 6 | ) 7 | :outf 8 | for %%X in (lua.exe,lua51.exe,luajit.exe) do ( 9 | set LUA="%%~$PATH:X" 10 | if defined LUA goto :lua 11 | ) 12 | echo no lua available...get lake.exe!! 13 | exit /b 14 | :lua 15 | %LUA% -llfs -e "print 'OK!'" 2>&1 | find "OK!" > nul 16 | if %errorlevel% neq 0 ( 17 | echo luafilesystem not installed for %LUA% 18 | exit /b 19 | ) 20 | set LAKE=%LUA% lake 21 | goto :go 22 | :lake 23 | rem if it's a batch needs special treatment 24 | echo %LAKE% | find ".bat" 25 | set LAKE="%LAKE%" 26 | if %errorlevel% equ 0 set LAKE=call %LAKE% 27 | :go 28 | rem and go! 29 | if "%1" == "LUA53=1" (set LAKE=%LAKE% LUA53=1) 30 | if defined LUA53 (set LAKE=%LAKE% LUA53=1) 31 | %LAKE% %* 32 | rem can now install the rest 33 | if %errorlevel% equ 0 ( 34 | echo installing... 35 | %LAKE% install.lua 36 | ) 37 | -------------------------------------------------------------------------------- /default.config: -------------------------------------------------------------------------------- 1 | ----- Luabuild default configuration 2 | OPTIMIZE='O2' 3 | -- or you can get a debug build 4 | --DEBUG = true 5 | 6 | -- this is the default; build with as much 5.1 compatibility as possible 7 | no_lua51_compat = false 8 | 9 | if not STATIC then 10 | build_shared = true 11 | --the excutable/lib will find its modules in $LB/libs/VERSION and $LIB/lua 12 | custom_lua_path = true 13 | -- default to linking against linenoise - set READLINE if you really 14 | -- want the old dog back 15 | readline = READLINE and true or 'linenoise' 16 | else 17 | --it will be a statically-linked executable that can't link dynamically 18 | no_dlink = true 19 | -- can switch off readline (useful for self-contained executables) 20 | readline = false 21 | end 22 | 23 | -- set this if you want MSVC builds to link against runtime 24 | -- (they will be smaller but less portable) 25 | dynamic = DYNAMIC 26 | 27 | if not LUA53 then 28 | if not STATIC then 29 | name = 'lua52' 30 | else 31 | name = 'lua52s' -- for 'static' 32 | end 33 | else 34 | if not STATIC then 35 | name = 'lua53' 36 | else 37 | name = 'lua53s' -- for 'static' 38 | end 39 | end 40 | 41 | if PLAT == 'Windows' then 42 | dll = name 43 | end 44 | 45 | -- for all platforms 46 | include = 'lfs socket.core mime.core lpeg ' 47 | 48 | if not LUA53 then 49 | include = include .. 'struct ' 50 | end 51 | 52 | if PLAT == 'Windows' then 53 | include = include .. ' winapi luasql.odbc' 54 | if CC ~= 'cl' then -- sorry, MSVC does not do C99 complex... 55 | include = include .. ' complex' 56 | end 57 | else 58 | include = include .. ' complex posix_c ' 59 | if not READLINE then 60 | include = include .. ' linenoise ' 61 | end 62 | if PLAT == 'Linux' then 63 | include = include .. ' inotify ' 64 | end 65 | --either satisfy external requirements, or just leave these out 66 | if EXTRAS then 67 | include = include .. ' curses_c ltcl lxp lsqlite3' 68 | end 69 | end 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dll.config: -------------------------------------------------------------------------------- 1 | CC = 'gcc' 2 | dll = 'lua52' 3 | -------------------------------------------------------------------------------- /exe.config: -------------------------------------------------------------------------------- 1 | -- building a 'full' executable on Windows 2 | name = 'lua52f' 3 | -------------------------------------------------------------------------------- /install.lua: -------------------------------------------------------------------------------- 1 | --- Lake script to install script wrappers in bin 2 | local exec, join = utils.execute, path.join 3 | 4 | if arg[1] or LUA53 then 5 | lua = 'lua53' 6 | soar = 'soar53' 7 | print 'installing Lua 5.3' 8 | else 9 | lua = 'lua52' 10 | soar = 'soar52' 11 | end 12 | 13 | -- some platform-dependent swearing... 14 | if WINDOWS then 15 | bat_ext, all_args, shebang = '.bat',' %*', '@echo off\n' 16 | else 17 | bat_ext, all_args, shebang = '',' $*','#!/bin/sh\n' 18 | end 19 | 20 | local function bin_dir(f) return join('bin',f) end 21 | 22 | local function make_wrapper(target,exe,name) 23 | if not name then 24 | local _ 25 | _, name = path.splitpath(target) 26 | name = path.splitext(name) 27 | end 28 | target = path.abs(target) 29 | if not exe then 30 | exe = path.abs(bin_dir(lua)) 31 | end 32 | local wrap = bin_dir (name)..bat_ext 33 | file.write(wrap,shebang..exe..' '..target..all_args..'\n') 34 | if not WINDOWS then 35 | exec('chmod +x '..wrap) 36 | end 37 | end 38 | 39 | make_wrapper ('tools/soar.lua') 40 | make_wrapper ('tools/srlua.lua','lake') 41 | make_wrapper 'lake' 42 | 43 | -------------------------------------------------------------------------------- /lfs.config: -------------------------------------------------------------------------------- 1 | CC = 'gcc' 2 | include = 'lfs' 3 | srlua = 'lua-fs' 4 | 5 | -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | Static libraries end up here 2 | -------------------------------------------------------------------------------- /linenoise/Makefile: -------------------------------------------------------------------------------- 1 | linenoise_example: linenoise.h linenoise.c 2 | 3 | linenoise_example: linenoise.c example.c 4 | $(CC) -Wall -W -Os -g -o linenoise_example linenoise.c example.c 5 | 6 | clean: 7 | rm -f linenoise_example 8 | -------------------------------------------------------------------------------- /linenoise/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "linenoise.h" 4 | 5 | 6 | void completion(const char *buf, linenoiseCompletions *lc) { 7 | if (buf[0] == 'h') { 8 | linenoiseAddCompletion(lc,"hello"); 9 | linenoiseAddCompletion(lc,"hello there"); 10 | } 11 | } 12 | 13 | int main(void) { 14 | char *line; 15 | 16 | linenoiseSetCompletionCallback(completion); 17 | linenoiseHistoryLoad("history.txt"); /* Load the history at startup */ 18 | while((line = linenoise("hello> ")) != NULL) { 19 | if (line[0] != '\0') { 20 | printf("echo: '%s'\n", line); 21 | linenoiseHistoryAdd(line); 22 | linenoiseHistorySave("history.txt"); /* Save every new entry */ 23 | } 24 | free(line); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /linenoise/linenoise.h: -------------------------------------------------------------------------------- 1 | /* linenoise.h -- guerrilla line editing library against the idea that a 2 | * line editing lib needs to be 20,000 lines of C code. 3 | * 4 | * See linenoise.c for more information. 5 | * 6 | * ------------------------------------------------------------------------ 7 | * 8 | * Copyright (c) 2010, Salvatore Sanfilippo 9 | * Copyright (c) 2010, Pieter Noordhuis 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are 15 | * met: 16 | * 17 | * * Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 20 | * * Redistributions in binary form must reproduce the above copyright 21 | * notice, this list of conditions and the following disclaimer in the 22 | * documentation and/or other materials provided with the distribution. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef __LINENOISE_H 38 | #define __LINENOISE_H 39 | 40 | typedef struct linenoiseCompletions { 41 | size_t len; 42 | char **cvec; 43 | } linenoiseCompletions; 44 | 45 | typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *); 46 | void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); 47 | void linenoiseAddCompletion(linenoiseCompletions *, char *); 48 | 49 | char *linenoise(const char *prompt); 50 | int linenoiseHistoryAdd(const char *line); 51 | int linenoiseHistorySetMaxLen(int len); 52 | int linenoiseHistorySave(char *filename); 53 | int linenoiseHistoryLoad(char *filename); 54 | void linenoiseClearScreen(void); 55 | 56 | #endif /* __LINENOISE_H */ 57 | -------------------------------------------------------------------------------- /lua-5.2.2/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.7 2009/11/27 15:37:59 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lua-5.2.2/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.11 2011/10/03 16:19:23 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lctype.h" 11 | 12 | #if !LUA_USE_CTYPE /* { */ 13 | 14 | #include 15 | 16 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 17 | 0x00, /* EOZ */ 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 19 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 23 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 24 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 25 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 26 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 27 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 28 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 29 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 30 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 32 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 33 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | }; 51 | 52 | #endif /* } */ 53 | -------------------------------------------------------------------------------- /lua-5.2.2/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /lua-5.2.2/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.7 2011/10/07 20:45:19 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2); 27 | LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, 28 | const TValue *p2); 29 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 30 | const TValue *p2); 31 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 32 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lua-5.2.2/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.20 2011/11/29 15:55:08 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by `runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /lua-5.2.2/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.8 2012/05/08 13:53:33 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 29 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 30 | int pc); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lua-5.2.2/linit.c.in: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | $(REGISTER_INTERNAL) 32 | {NULL, NULL} 33 | }; 34 | 35 | $(DECLARATIONS) 36 | 37 | /* 38 | ** these libs are preloaded and must be required before used 39 | */ 40 | static const luaL_Reg preloadedlibs[] = { 41 | $(REGISTER_EXTERNAL) 42 | {NULL, NULL} 43 | }; 44 | 45 | 46 | LUALIB_API void luaL_openlibs (lua_State *L) { 47 | const luaL_Reg *lib; 48 | /* call open functions from 'loadedlibs' and set results to global table */ 49 | for (lib = loadedlibs; lib->func; lib++) { 50 | luaL_requiref(L, lib->name, lib->func, 1); 51 | lua_pop(L, 1); /* remove lib */ 52 | } 53 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 54 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 55 | for (lib = preloadedlibs; lib->func; lib++) { 56 | lua_pushcfunction(L, lib->func); 57 | lua_setfield(L, -2, lib->name); 58 | } 59 | lua_pop(L, 1); /* remove _PRELOAD table */ 60 | } 61 | 62 | -------------------------------------------------------------------------------- /lua-5.2.2/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.72 2011/11/30 12:43:51 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | 18 | /* 19 | * WARNING: if you change the order of this enumeration, 20 | * grep "ORDER RESERVED" 21 | */ 22 | enum RESERVED { 23 | /* terminal symbols denoted by reserved words */ 24 | TK_AND = FIRST_RESERVED, TK_BREAK, 25 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 26 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 27 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 28 | /* other terminal symbols */ 29 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS, 30 | TK_NUMBER, TK_NAME, TK_STRING 31 | }; 32 | 33 | /* number of reserved words */ 34 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 35 | 36 | 37 | typedef union { 38 | lua_Number r; 39 | TString *ts; 40 | } SemInfo; /* semantics information */ 41 | 42 | 43 | typedef struct Token { 44 | int token; 45 | SemInfo seminfo; 46 | } Token; 47 | 48 | 49 | /* state of the lexer plus state of the parser when shared by all 50 | functions */ 51 | typedef struct LexState { 52 | int current; /* current character (charint) */ 53 | int linenumber; /* input line counter */ 54 | int lastline; /* line of last token `consumed' */ 55 | Token t; /* current token */ 56 | Token lookahead; /* look ahead token */ 57 | struct FuncState *fs; /* current function (parser) */ 58 | struct lua_State *L; 59 | ZIO *z; /* input stream */ 60 | Mbuffer *buff; /* buffer for tokens */ 61 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 62 | TString *source; /* current source name */ 63 | TString *envn; /* environment variable name */ 64 | char decpoint; /* locale decimal point */ 65 | } LexState; 66 | 67 | 68 | LUAI_FUNC void luaX_init (lua_State *L); 69 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 70 | TString *source, int firstchar); 71 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 72 | LUAI_FUNC void luaX_next (LexState *ls); 73 | LUAI_FUNC int luaX_lookahead (LexState *ls); 74 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 75 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /lua-5.2.2/llinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | {LUA_LOADLIBNAME, luaopen_package}, 32 | {LUA_COLIBNAME, luaopen_coroutine}, 33 | {LUA_TABLIBNAME, luaopen_table}, 34 | {LUA_IOLIBNAME, luaopen_io}, 35 | {LUA_OSLIBNAME, luaopen_os}, 36 | {LUA_STRLIBNAME, luaopen_string}, 37 | {LUA_BITLIBNAME, luaopen_bit32}, 38 | {LUA_MATHLIBNAME, luaopen_math}, 39 | {LUA_DBLIBNAME, luaopen_debug}, 40 | {NULL, NULL} 41 | }; 42 | 43 | int luaopen_lfs(lua_State *L); 44 | 45 | /* 46 | ** these libs are preloaded and must be required before used 47 | */ 48 | static const luaL_Reg preloadedlibs[] = { 49 | {"lfs",luaopen_lfs}, 50 | {NULL, NULL} 51 | }; 52 | 53 | 54 | LUALIB_API void luaL_openlibs (lua_State *L) { 55 | const luaL_Reg *lib; 56 | /* call open functions from 'loadedlibs' and set results to global table */ 57 | for (lib = loadedlibs; lib->func; lib++) { 58 | luaL_requiref(L, lib->name, lib->func, 1); 59 | lua_pop(L, 1); /* remove lib */ 60 | } 61 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 62 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 63 | for (lib = preloadedlibs; lib->func; lib++) { 64 | lua_pushcfunction(L, lib->func); 65 | lua_setfield(L, -2, lib->name); 66 | } 67 | lua_pop(L, 1); /* remove _PRELOAD table */ 68 | } 69 | 70 | -------------------------------------------------------------------------------- /lua-5.2.2/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.40 2013/02/20 14:08:21 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is 19 | ** always constant. 20 | ** The macro is somewhat complex to avoid warnings: 21 | ** +1 avoids warnings of "comparison has constant result"; 22 | ** cast to 'void' avoids warnings of "value unused". 23 | */ 24 | #define luaM_reallocv(L,b,on,n,e) \ 25 | (cast(void, \ 26 | (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \ 27 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 28 | 29 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 30 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 31 | #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0])) 32 | 33 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 34 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 35 | #define luaM_newvector(L,n,t) \ 36 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 37 | 38 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 39 | 40 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 41 | if ((nelems)+1 > (size)) \ 42 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 43 | 44 | #define luaM_reallocvector(L, v,oldn,n,t) \ 45 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 46 | 47 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 48 | 49 | /* not to be called directly */ 50 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 51 | size_t size); 52 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 53 | size_t size_elem, int limit, 54 | const char *what); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /lua-5.2.2/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.49 2012/02/01 21:57:15 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 16 | 17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 18 | 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 20 | (sizeof(s)/sizeof(char))-1)) 21 | 22 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); 40 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lua-5.2.2/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define invalidateTMcache(t) ((t)->flags = 0) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); 22 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 25 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L); 28 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); 29 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 30 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 31 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 32 | LUAI_FUNC int luaH_getn (Table *t); 33 | 34 | 35 | #if defined(LUA_DEBUG) 36 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 37 | LUAI_FUNC int luaH_isdummy (Node *n); 38 | #endif 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lua-5.2.2/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.14 2011/06/02 19:31:40 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | static const char udatatypename[] = "userdata"; 23 | 24 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 25 | "no value", 26 | "nil", "boolean", udatatypename, "number", 27 | "string", "table", "function", udatatypename, "thread", 28 | "proto", "upval" /* these last two cases are used for tests only */ 29 | }; 30 | 31 | 32 | void luaT_init (lua_State *L) { 33 | static const char *const luaT_eventname[] = { /* ORDER TM */ 34 | "__index", "__newindex", 35 | "__gc", "__mode", "__len", "__eq", 36 | "__add", "__sub", "__mul", "__div", "__mod", 37 | "__pow", "__unm", "__lt", "__le", 38 | "__concat", "__call" 39 | }; 40 | int i; 41 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 43 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 44 | } 45 | } 46 | 47 | 48 | /* 49 | ** function to be used with macro "fasttm": optimized for absence of 50 | ** tag methods 51 | */ 52 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 53 | const TValue *tm = luaH_getstr(events, ename); 54 | lua_assert(event <= TM_EQ); 55 | if (ttisnil(tm)) { /* no tag method? */ 56 | events->flags |= cast_byte(1u<metatable; 68 | break; 69 | case LUA_TUSERDATA: 70 | mt = uvalue(o)->metatable; 71 | break; 72 | default: 73 | mt = G(L)->mt[ttypenv(o)]; 74 | } 75 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /lua-5.2.2/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.11 2011/02/28 17:32:10 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with `fast' access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_DIV, 29 | TM_MOD, 30 | TM_POW, 31 | TM_UNM, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | #define ttypename(x) luaT_typenames_[(x) + 1] 47 | #define objtypename(x) ttypename(ttypenv(x)) 48 | 49 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 50 | 51 | 52 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 53 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 54 | TMS event); 55 | LUAI_FUNC void luaT_init (lua_State *L); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lua-5.2.2/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lua-5.2.2/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43 2011/12/08 12:11:37 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_BITLIBNAME "bit32" 33 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 34 | 35 | #define LUA_MATHLIBNAME "math" 36 | LUAMOD_API int (luaopen_math) (lua_State *L); 37 | 38 | #define LUA_DBLIBNAME "debug" 39 | LUAMOD_API int (luaopen_debug) (lua_State *L); 40 | 41 | #define LUA_LOADLIBNAME "package" 42 | LUAMOD_API int (luaopen_package) (lua_State *L); 43 | 44 | 45 | /* open all previous libraries */ 46 | LUALIB_API void (luaL_openlibs) (lua_State *L); 47 | 48 | 49 | 50 | #if !defined(lua_assert) 51 | #define lua_assert(x) ((void)0) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lua-5.2.2/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.39 2012/05/08 13:53:33 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (lu_byte* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | /* data to catch conversion errors */ 23 | #define LUAC_TAIL "\x19\x93\r\n\x1a\n" 24 | 25 | /* size in bytes of header of binary files */ 26 | #define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lua-5.2.2/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.18 2013/01/08 14:06:55 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL)) 19 | 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2)) 21 | 22 | #define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2) 23 | 24 | 25 | /* not to called directly */ 26 | LUAI_FUNC int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2); 27 | 28 | 29 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 30 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 31 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 32 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 33 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 34 | StkId val); 35 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 36 | StkId val); 37 | LUAI_FUNC void luaV_finishOp (lua_State *L); 38 | LUAI_FUNC void luaV_execute (lua_State *L); 39 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 40 | LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb, 41 | const TValue *rc, TMS op); 42 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lua-5.2.2/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.35 2012/05/14 13:34:18 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) 29 | return EOZ; 30 | z->n = size - 1; /* discount char being returned */ 31 | z->p = buff; 32 | return cast_uchar(*(z->p++)); 33 | } 34 | 35 | 36 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 37 | z->L = L; 38 | z->reader = reader; 39 | z->data = data; 40 | z->n = 0; 41 | z->p = NULL; 42 | } 43 | 44 | 45 | /* --------------------------------------------------------------- read --- */ 46 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 47 | while (n) { 48 | size_t m; 49 | if (z->n == 0) { /* no bytes in buffer? */ 50 | if (luaZ_fill(z) == EOZ) /* try to read more */ 51 | return n; /* no more input; return number of missing bytes */ 52 | else { 53 | z->n++; /* luaZ_fill consumed first byte; put it back */ 54 | z->p--; 55 | } 56 | } 57 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 58 | memcpy(b, z->p, m); 59 | z->n -= m; 60 | z->p += m; 61 | b = (char *)b + m; 62 | n -= m; 63 | } 64 | return 0; 65 | } 66 | 67 | /* ------------------------------------------------------------------------ */ 68 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 69 | if (n > buff->buffsize) { 70 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 71 | luaZ_resizebuffer(L, buff, n); 72 | } 73 | return buff->buffer; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /lua-5.2.2/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 36 | 37 | 38 | #define luaZ_resizebuffer(L, buff, size) \ 39 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 40 | (buff)->buffsize = size) 41 | 42 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 43 | 44 | 45 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 46 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 47 | void *data); 48 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 49 | 50 | 51 | 52 | /* --------- Private Part ------------------ */ 53 | 54 | struct Zio { 55 | size_t n; /* bytes still unread */ 56 | const char *p; /* current position in buffer */ 57 | lua_Reader reader; /* reader function */ 58 | void* data; /* additional data */ 59 | lua_State *L; /* Lua state (for reader) */ 60 | }; 61 | 62 | 63 | LUAI_FUNC int luaZ_fill (ZIO *z); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /lua-5.3.0/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.3.0, released on 16 Dec 2014. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /lua-5.3.0/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevedonovan/luabuild/4c2afadb6184911e8fdcd0215f3dceede0aad180/lua-5.3.0/doc/logo.gif -------------------------------------------------------------------------------- /lua-5.3.0/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | border: solid #a0a0a0 1px ; 7 | border-radius: 20px ; 8 | padding: 26px ; 9 | margin: 16px ; 10 | color: #000000 ; 11 | background-color: #FFFFFF ; 12 | font-family: Helvetica, Arial, sans-serif ; 13 | text-align: justify ; 14 | } 15 | 16 | h1, h2, h3, h4 { 17 | font-family: Verdana, Geneva, sans-serif ; 18 | font-weight: normal ; 19 | font-style: normal ; 20 | } 21 | 22 | h2 { 23 | padding-top: 0.4em ; 24 | padding-bottom: 0.4em ; 25 | padding-left: 0.8em ; 26 | padding-right: 0.8em ; 27 | background-color: #D0D0FF ; 28 | border-radius: 8px ; 29 | border: solid #a0a0a0 1px ; 30 | } 31 | 32 | h3 { 33 | padding-left: 0.5em ; 34 | border-left: solid #D0D0FF 1em ; 35 | } 36 | 37 | table h3 { 38 | padding-left: 0px ; 39 | border-left: none ; 40 | } 41 | 42 | a:link { 43 | color: #000080 ; 44 | background-color: inherit ; 45 | text-decoration: none ; 46 | } 47 | 48 | a:visited { 49 | background-color: inherit ; 50 | text-decoration: none ; 51 | } 52 | 53 | a:link:hover, a:visited:hover { 54 | color: #000080 ; 55 | background-color: #D0D0FF ; 56 | border-radius: 4px; 57 | } 58 | 59 | a:link:active, a:visited:active { 60 | color: #FF0000 ; 61 | } 62 | 63 | h1 a img { 64 | vertical-align: text-bottom ; 65 | } 66 | 67 | hr { 68 | border: 0 ; 69 | height: 1px ; 70 | color: #a0a0a0 ; 71 | background-color: #a0a0a0 ; 72 | display: none ; 73 | } 74 | 75 | table hr { 76 | display: block ; 77 | } 78 | 79 | :target { 80 | background-color: #F8F8F8 ; 81 | padding: 8px ; 82 | border: solid #a0a0a0 2px ; 83 | border-radius: 8px ; 84 | } 85 | 86 | .footer { 87 | color: gray ; 88 | font-size: x-small ; 89 | } 90 | 91 | input[type=text] { 92 | border: solid #a0a0a0 2px ; 93 | border-radius: 2em ; 94 | background-image: url('images/search.png') ; 95 | background-repeat: no-repeat ; 96 | background-position: 4px center ; 97 | padding-left: 20px ; 98 | height: 2em ; 99 | } 100 | 101 | pre.session { 102 | background-color: #F8F8F8 ; 103 | padding: 1em ; 104 | border-radius: 8px ; 105 | } 106 | -------------------------------------------------------------------------------- /lua-5.3.0/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | font-style: normal ; 20 | padding-top: 0.4em ; 21 | padding-bottom: 0.4em ; 22 | padding-left: 16px ; 23 | margin-left: -16px ; 24 | background-color: #D0D0FF ; 25 | border-radius: 8px ; 26 | border: solid #000080 1px ; 27 | } 28 | -------------------------------------------------------------------------------- /lua-5.3.0/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevedonovan/luabuild/4c2afadb6184911e8fdcd0215f3dceede0aad180/lua-5.3.0/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /lua-5.3.0/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check((n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /lua-5.3.0/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 29 | const TValue *p2, 30 | const char *msg); 31 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 32 | const TValue *p2); 33 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 34 | const TValue *p2); 35 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 36 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 37 | LUAI_FUNC void luaG_traceexec (lua_State *L); 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lua-5.3.0/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by 'runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.14 2014/06/19 18:27:20 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** Upvalues for Lua closures 27 | */ 28 | struct UpVal { 29 | TValue *v; /* points to stack or to its own value */ 30 | lu_mem refcount; /* reference counter */ 31 | union { 32 | struct { /* (when open) */ 33 | UpVal *next; /* linked list */ 34 | int touched; /* mark to avoid cycles with dead threads */ 35 | } open; 36 | TValue value; /* the value (when closed) */ 37 | } u; 38 | }; 39 | 40 | #define upisopen(up) ((up)->v != &(up)->u.value) 41 | 42 | 43 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 44 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 45 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 46 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 47 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 48 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 49 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 50 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 51 | int pc); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lua-5.3.0/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | {"table",luaopen_table}, 32 | {"os",luaopen_os}, 33 | {"string",luaopen_string}, 34 | {"math",luaopen_math}, 35 | {"coroutine",luaopen_coroutine}, 36 | {"package",luaopen_package}, 37 | {"io",luaopen_io}, 38 | {"utf8",luaopen_utf8}, 39 | {"debug",luaopen_debug}, 40 | {NULL, NULL} 41 | }; 42 | 43 | 44 | 45 | /* 46 | ** these libs are preloaded and must be required before used 47 | */ 48 | static const luaL_Reg preloadedlibs[] = { 49 | 50 | {NULL, NULL} 51 | }; 52 | 53 | 54 | LUALIB_API void luaL_openlibs (lua_State *L) { 55 | const luaL_Reg *lib; 56 | /* call open functions from 'loadedlibs' and set results to global table */ 57 | for (lib = loadedlibs; lib->func; lib++) { 58 | luaL_requiref(L, lib->name, lib->func, 1); 59 | lua_pop(L, 1); /* remove lib */ 60 | } 61 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 62 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 63 | for (lib = preloadedlibs; lib->func; lib++) { 64 | lua_pushcfunction(L, lib->func); 65 | lua_setfield(L, -2, lib->name); 66 | } 67 | lua_pop(L, 1); /* remove _PRELOAD table */ 68 | } 69 | 70 | -------------------------------------------------------------------------------- /lua-5.3.0/src/linit.c.in: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | $(REGISTER_INTERNAL) 32 | {NULL, NULL} 33 | }; 34 | 35 | $(DECLARATIONS) 36 | 37 | /* 38 | ** these libs are preloaded and must be required before used 39 | */ 40 | static const luaL_Reg preloadedlibs[] = { 41 | $(REGISTER_EXTERNAL) 42 | {NULL, NULL} 43 | }; 44 | 45 | 46 | LUALIB_API void luaL_openlibs (lua_State *L) { 47 | const luaL_Reg *lib; 48 | /* call open functions from 'loadedlibs' and set results to global table */ 49 | for (lib = loadedlibs; lib->func; lib++) { 50 | luaL_requiref(L, lib->name, lib->func, 1); 51 | lua_pop(L, 1); /* remove lib */ 52 | } 53 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 54 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 55 | for (lib = preloadedlibs; lib->func; lib++) { 56 | lua_pushcfunction(L, lib->func); 57 | lua_setfield(L, -2, lib->name); 58 | } 59 | lua_pop(L, 1); /* remove _PRELOAD table */ 60 | } 61 | 62 | -------------------------------------------------------------------------------- /lua-5.3.0/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | char decpoint; /* locale decimal point */ 73 | } LexState; 74 | 75 | 76 | LUAI_FUNC void luaX_init (lua_State *L); 77 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 78 | TString *source, int firstchar); 79 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 80 | LUAI_FUNC void luaX_next (LexState *ls); 81 | LUAI_FUNC int luaX_lookahead (LexState *ls); 82 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 83 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.1 2014/11/03 15:12:44 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(_XOPEN_SOURCE) 15 | #define _XOPEN_SOURCE 600 16 | #endif 17 | 18 | /* 19 | ** Allows manipulation of large files in gcc and some other compilers 20 | */ 21 | #if !defined(_FILE_OFFSET_BITS) 22 | #define _LARGEFILE_SOURCE 1 23 | #define _FILE_OFFSET_BITS 64 24 | #endif 25 | 26 | 27 | /* 28 | ** Windows stuff 29 | */ 30 | #if defined(_WIN32) /* { */ 31 | 32 | #if !defined(_CRT_SECURE_NO_WARNINGS) 33 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 34 | #endif 35 | 36 | #endif /* } */ 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.56 2014/07/18 14:46:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | #define sizestring(s) sizelstring((s)->len) 17 | 18 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 19 | #define sizeudata(u) sizeludata((u)->len) 20 | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lua-5.3.0/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.20 2014/09/04 18:15:29 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | #define wgkey(n) (&(n)->i_key.nk) 22 | 23 | #define invalidateTMcache(t) ((t)->flags = 0) 24 | 25 | 26 | /* returns the key, given the value of a table entry */ 27 | #define keyfromval(v) \ 28 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 29 | 30 | 31 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 32 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 33 | TValue *value); 34 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 35 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 36 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 37 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 38 | LUAI_FUNC Table *luaH_new (lua_State *L); 39 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 40 | unsigned int nhsize); 41 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 42 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 43 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 44 | LUAI_FUNC int luaH_getn (Table *t); 45 | 46 | 47 | #if defined(LUA_DEBUG) 48 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 49 | LUAI_FUNC int luaH_isdummy (Node *n); 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lua-5.3.0/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | #define objtypename(x) ttypename(ttnov(x)) 55 | 56 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 57 | 58 | 59 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 60 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 61 | TMS event); 62 | LUAI_FUNC void luaT_init (lua_State *L); 63 | 64 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 65 | const TValue *p2, TValue *p3, int hasres); 66 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 67 | StkId res, TMS event); 68 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 69 | StkId res, TMS event); 70 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 71 | const TValue *p2, TMS event); 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.44 2014/06/19 18:27:20 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, 27 | const char* name); 28 | 29 | /* dump one chunk; from ldump.c */ 30 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 31 | void* data, int strip); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.34 2014/08/01 17:24:02 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | #define tonumber(o,n) \ 31 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 32 | 33 | #define tointeger(o,i) \ 34 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i)) 35 | 36 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 37 | 38 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 39 | 40 | 41 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 42 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 43 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 44 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 45 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); 46 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 47 | StkId val); 48 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 49 | StkId val); 50 | LUAI_FUNC void luaV_finishOp (lua_State *L); 51 | LUAI_FUNC void luaV_execute (lua_State *L); 52 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 53 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 54 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 55 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 56 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.36 2014/11/02 19:19:04 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | /* ------------------------------------------------------------------------ */ 70 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 71 | if (n > buff->buffsize) { 72 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 73 | luaZ_resizebuffer(L, buff, n); 74 | } 75 | return buff->buffer; 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /lua-5.3.0/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.30 2014/12/19 17:26:14 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 48 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 49 | void *data); 50 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; /* reader function */ 60 | void *data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /lua.config: -------------------------------------------------------------------------------- 1 | OPTIMIZE='O2' 2 | custom_lua_path=true 3 | name='lua52t' 4 | -- straight Lua 5.2 build, using defaults -- 5 | -------------------------------------------------------------------------------- /lua/README: -------------------------------------------------------------------------------- 1 | Any modules with pure Lua components must copy them here; custom_lua_path = true makes your Lua52 look here for Lua modules. 2 | -------------------------------------------------------------------------------- /luaish/t.lua: -------------------------------------------------------------------------------- 1 | print(posix.getcwd()) 2 | -------------------------------------------------------------------------------- /modules/bc.lake: -------------------------------------------------------------------------------- 1 | luabuild.test 'test.lua' 2 | 3 | return luabuild.library{'bc',src='lbc number',incdir = '.'} 4 | -------------------------------------------------------------------------------- /modules/bc/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for bc library for Lua 2 | 3 | # change these to reflect your Lua installation 4 | LUA= /tmp/lhf/lua-5.2.0 5 | LUAINC= $(LUA)/src 6 | LUALIB= $(LUA)/src 7 | LUABIN= $(LUA)/src 8 | 9 | # these will probably work if Lua has been installed globally 10 | #LUA= /usr/local 11 | #LUAINC= $(LUA)/include 12 | #LUALIB= $(LUA)/lib 13 | #LUABIN= $(LUA)/bin 14 | 15 | # probably no need to change anything below here 16 | CC= gcc 17 | CFLAGS= $(INCS) $(WARN) -O2 $G 18 | WARN= -ansi -pedantic -Wall -Wextra 19 | INCS= -I$(LUAINC) -I. 20 | MAKESO= $(CC) -shared 21 | #MAKESO= $(CC) -bundle -undefined dynamic_lookup 22 | 23 | MYNAME= bc 24 | MYLIB= l$(MYNAME) 25 | T= $(MYNAME).so 26 | OBJS= $(MYLIB).o number.o 27 | TEST= test.lua 28 | 29 | all: test 30 | 31 | test: $T 32 | $(LUABIN)/lua $(TEST) 33 | 34 | o: $(MYLIB).o 35 | 36 | so: $T 37 | 38 | $T: $(OBJS) 39 | $(MAKESO) -o $@ $(OBJS) 40 | 41 | clean: 42 | rm -f $(OBJS) $T core core.* 43 | 44 | doc: 45 | @echo "$(MYNAME) library:" 46 | @fgrep '/**' $(MYLIB).c | cut -f2 -d/ | tr -d '*' | sort | column 47 | 48 | # eof 49 | -------------------------------------------------------------------------------- /modules/bc/README: -------------------------------------------------------------------------------- 1 | This is a big-number library for Lua 5.2. It is based on the arbitrary 2 | precision library number.c written by Philip A. Nelson for GNU bc-1.06: 3 | http://www.gnu.org/software/bc/ 4 | 5 | To try the library, just edit Makefile to reflect your installation of Lua and 6 | then run make. This will build the library and run a simple test. For detailed 7 | installation instructions, see 8 | http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html 9 | 10 | There is no manual but the library is simple and intuitive; see the summary 11 | below. Read also test.lua, which shows the library in action. 12 | 13 | This code is hereby placed in the public domain, except number.c and number.h, 14 | which are subject to GPL. 15 | 16 | Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br . 17 | 18 | ------------------------------------------------------------------------------- 19 | 20 | bc library: 21 | __add(x,y) __pow(x,y) digits([n]) mul(x,y) sub(x,y) 22 | __div(x,y) __sub(x,y) div(x,y) neg(x) tonumber(x) 23 | __eq(x,y) __tostring(x) divmod(x,y) number(x) tostring(x) 24 | __lt(x,y) __unm(x) isneg(x) pow(x,y) trunc(x,[n]) 25 | __mod(x,y) add(x,y) iszero(x) powmod(x,y,m) version 26 | __mul(x,y) compare(x,y) mod(x,y) sqrt(x) 27 | 28 | ------------------------------------------------------------------------------- 29 | -------------------------------------------------------------------------------- /modules/bc/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * number.c from GNU bc-1.06 exports some symbols without the bc_ prefix. 4 | * This header file fixes this without touching either number.c or number.h 5 | * (luckily, number.c already wants to include a config.h). 6 | * Clients of number.c should include config.h before number.h. 7 | */ 8 | 9 | #include 10 | #include 11 | #define NDEBUG 12 | 13 | #define _zero_ bc_zero 14 | #define _one_ bc_one 15 | #define _two_ bc_two 16 | #define num2str bc_num2str 17 | #define mul_base_digits bc_mul_base_digits 18 | 19 | #define bc_rt_warn bc_error 20 | #define bc_rt_error bc_error 21 | #define bc_out_of_memory() bc_error(NULL) 22 | 23 | void bc_error(const char *mesg); 24 | -------------------------------------------------------------------------------- /modules/complex.lake: -------------------------------------------------------------------------------- 1 | -- sorry, take this one up with Microsoft! 2 | if CC == 'cl' then 3 | quit "MSVC does not do C99 complex" 4 | end 5 | 6 | luabuild.test 'test.lua' 7 | 8 | return luabuild.library{'complex',lang='c99',src='lcomplex'} 9 | 10 | -------------------------------------------------------------------------------- /modules/complex/README: -------------------------------------------------------------------------------- 1 | This code provides support for complex numbers in Lua using the functions 2 | available in C99. 3 | 4 | To try the library, just edit Makefile to reflect your installation of Lua and 5 | then run make. This will build the library and run a simple test. For detailed 6 | installation instructions, see 7 | http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html 8 | 9 | There is no manual: see the summary below and a C99 reference manual, e.g. 10 | http://www.dinkumware.com/manuals/default.aspx?manual=compleat&page=complex2.html 11 | 12 | Read also test.lua, which shows the library in action. 13 | 14 | This code is hereby placed in the public domain. 15 | 16 | Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br . 17 | 18 | ------------------------------------------------------------------------------- 19 | 20 | complex library: 21 | __add(z,w) __unm(z) atan(z) log(z) sqrt(z) 22 | __div(z,w) abs(z) atanh(z) new(x,y) tan(z) 23 | __eq(z,w) acos(z) conj(z) pow(z,w) tanh(z) 24 | __mul(z,w) acosh(z) cos(z) proj(z) tostring(z) 25 | __pow(z,w) arg(z) cosh(z) real(z) version 26 | __sub(z,w) asin(z) exp(z) sin(z) I 27 | __tostring(z) asinh(z) imag(z) sinh(z) 28 | 29 | ------------------------------------------------------------------------------- 30 | -------------------------------------------------------------------------------- /modules/complex/test.lua: -------------------------------------------------------------------------------- 1 | -- test complex library 2 | 3 | ------------------------------------------------------------------------------ 4 | local complex=require"complex" 5 | 6 | print(complex.version) 7 | 8 | z=complex.new(3,4) 9 | print(z,"ABS",z:abs()) 10 | print(z,"CONJ",z:conj()) 11 | print(z,"CABS",z:conj():abs()) 12 | print(z,"NEG",-z) 13 | 14 | z=complex.new(0,math.pi) 15 | print(z,"EXP",z:exp()) 16 | 17 | z=complex.new(0,2*math.pi/3) 18 | print(z,"EXP",z:exp(),(2*z:exp():imag())^2) 19 | 20 | --I=complex.new(0,1) 21 | I=complex.I 22 | 23 | z=1 24 | for n=0,7 do 25 | print(n,"MUL",z,"POW",I^n) 26 | z=z*I 27 | end 28 | 29 | z=3+4*I 30 | print(z,"ABS",z:abs()) 31 | print(z,"ARG",z:arg()) 32 | print(z,"SQRT",z:sqrt()) 33 | z=2+I 34 | print(z,"SQR",z^2) 35 | print(z,"CUB",z^3) 36 | 37 | z=2+11*I 38 | print(z,"CBRT",z^(1/3)) 39 | 40 | print(complex.version) 41 | ------------------------------------------------------------------------------ 42 | -------------------------------------------------------------------------------- /modules/curses_c.lake: -------------------------------------------------------------------------------- 1 | local libs = 'curses ' 2 | local curses = find.include_path {'curses.h','ncurses.h'} 3 | if curses then 4 | local _,name = path.splitpath(curses) 5 | defs = name == 'curses.h' and 'HAVE_CURSES_H' or 'HAVE_NCURSES_H' 6 | elseif find.include_path {'ncurses/curses.h'} then 7 | defs = 'HAVE_NCURSES_CURSES_H' 8 | else 9 | quit "luaposix curses: cannot find curses.h; needs ncurses-dev/-devel" 10 | end 11 | 12 | luabuild.lua 'curses' 13 | 14 | return luabuild.library {'curses_c', src='lcurses', libs = libs, defines = defs} 15 | -------------------------------------------------------------------------------- /modules/inotify.lake: -------------------------------------------------------------------------------- 1 | if PLAT ~= 'Linux' then 2 | quit ("linotify is only available for Linux") 3 | end 4 | 5 | luabuild.test 'test.lua' 6 | 7 | return luabuild.library {'inotify',src='linotify'} 8 | -------------------------------------------------------------------------------- /modules/lfs/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003 Kepler Project 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so, subject to the following 8 | conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies 11 | or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 18 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /modules/lfs/lfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaFileSystem 3 | ** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/luafilesystem) 4 | ** 5 | ** $Id: lfs.h,v 1.3 2006/03/10 23:37:32 carregal Exp $ 6 | */ 7 | 8 | /* Define 'chdir' for systems that do not implement it */ 9 | #ifdef NO_CHDIR 10 | #define chdir(p) (-1) 11 | #define chdir_error "Function 'chdir' not provided by system" 12 | #else 13 | #define chdir_error strerror(errno) 14 | #endif 15 | 16 | int luaopen_lfs (lua_State *L); 17 | -------------------------------------------------------------------------------- /modules/linenoise.lake: -------------------------------------------------------------------------------- 1 | -- in this case, we'll assume that the Lua core has always been statically linked 2 | -- against linenoise 3 | 4 | return luabuild.library{'linenoise',src='linenoise', 5 | incdir = path.quote(PWD..'linenoise') -- PWD is luabuild directory 6 | } 7 | -------------------------------------------------------------------------------- /modules/linotify/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Robert Hoelz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /modules/linotify/README: -------------------------------------------------------------------------------- 1 | This is linotify, a binding for Linux's inotify library to Lua. 2 | 3 | --- Building --- 4 | 5 | To build inotify.so, simply chdir to the file this README is in, and 6 | type 'make'. 7 | 8 | --- Usage --- 9 | 10 | All of the constants are contained in the global inotify table. 11 | Constants are named after their counterparts in the C header file 12 | (ex. inotify.IN_ACCESS). 13 | 14 | The only function to be found in the inotify table is init, which 15 | takes no arguments and returns an inotify handle. Ex. 16 | 17 | Inotify handles have a variety of methods: 18 | 19 | handle:read() 20 | Reads events from the handle, returning a table. Each element of the table 21 | is itself a table, with the members of the inotify_event struct as its 22 | keys and values (except for len). If an error occurs, nil, the error 23 | message, and errno are returned. 24 | 25 | handle:close() 26 | Closes the inotify event handle. This is done automatically on garbage 27 | collection. 28 | 29 | handle:addwatch(path, [event_masks...]) 30 | Adds a watch on event_masks for the file located at path, returning a 31 | watch identifier on success, and the traditional nil, error, errno triplet 32 | on error. event_masks is a variadic sequence of integer constants, taken 33 | from inotify.IN_*. All of the values in event_masks are OR'd together. 34 | 35 | handle:rmwatch(watchid) 36 | Removes the watch specified by watchid from the list of watches for this 37 | inotify handle. Returns true on success, and nil, error, errno on error. 38 | 39 | Here's a usage example: 40 | 41 | local inotify = require 'inotify' 42 | local handle = inotify.init() 43 | -- watch my home for new files and renames 44 | local wd = handle:addwatch('/home/rob/', inotify.IN_CREATE, inotify.IN_MOVE) 45 | -- or handle:addwatch('/home/rob', bit.bor(inotify.IN_CREATE, inotify.IN_MOVE)) 46 | 47 | local events = handle:read() 48 | 49 | for _, ev in ipairs(events) do 50 | print(ev.name .. ' was created or renamed') 51 | end 52 | 53 | handle:rmwatch(wd) -- done automatically when you close, I think, but kept to be thorough 54 | handle:close() 55 | -------------------------------------------------------------------------------- /modules/linotify/test.lua: -------------------------------------------------------------------------------- 1 | local inotify = require 'inotify' 2 | local posix = require 'posix' 3 | 4 | posix.unlink 'frodo' 5 | 6 | local handle = inotify.init() 7 | local wd = handle:addwatch(posix.getcwd(),inotify.IN_CREATE) 8 | 9 | if posix.fork() == 0 then 10 | posix.nanosleep(0,20*1e6) 11 | os.execute 'cp README frodo' 12 | posix._exit(0) 13 | end 14 | 15 | local events = handle:read() 16 | print(events[1].name) 17 | assert(events[1].name == "frodo") 18 | handle:close() 19 | -------------------------------------------------------------------------------- /modules/lpeg.lake: -------------------------------------------------------------------------------- 1 | luabuild.lua 're' 2 | luabuild.test 'test.lua' 3 | 4 | return luabuild.library{'lpeg',src='lpeg'} 5 | -------------------------------------------------------------------------------- /modules/lpeg/lpeg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpeg.h,v 1.1 2009/12/23 16:15:36 roberto Exp $ 3 | ** LPeg - PEG pattern matching for Lua 4 | ** Copyright 2009, Lua.org & PUC-Rio (see 'lpeg.html' for license) 5 | ** written by Roberto Ierusalimschy 6 | */ 7 | 8 | #ifndef lpeg_h 9 | #define lpeg_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | #define KEYNEWPATT "lpeg.newpf" 15 | 16 | 17 | /* 18 | ** type of extension functions that define new "patterns" for LPEG 19 | ** It should return the new current position or NULL if match fails 20 | */ 21 | typedef const char *(*PattFunc) (const char *s, /* current position */ 22 | const char *e, /* string end */ 23 | const char *o, /* string start */ 24 | const void *ud); /* user data */ 25 | 26 | /* 27 | ** function to create new patterns based on 'PattFunc' functions. 28 | ** This function is available at *registry[KEYNEWPATT]. (Notice 29 | ** the extra indirection; the userdata at the registry points to 30 | ** a variable that points to the function. In ANSI C a void* cannot 31 | ** point to a function.) 32 | */ 33 | typedef void (*Newpf) (lua_State *L, 34 | PattFunc f, /* pattern */ 35 | const void *ud, /* (user) data to be passed to 'f' */ 36 | size_t l); /* size of data to be passed to 'f' */ 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /modules/lsqlite3.lake: -------------------------------------------------------------------------------- 1 | luabuild.test "test.lua" 2 | 3 | return luabuild.library {"lsqlite3",src="lsqlite3",needs="sqlite3"} 4 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/README: -------------------------------------------------------------------------------- 1 | 2 | LuaSQLite 3 provides a means to manipulate SQLite3 3 | databases directly from lua using Lua 5. 4 | 5 | To use this library you need SQLite3 library. 6 | You can get it from http://www.sqlite.org/ 7 | 8 | Lua 5 is available from http://www.lua.org/ 9 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/doc/pod2html.pl: -------------------------------------------------------------------------------- 1 | #!perl 2 | 3 | use Pod::Html; 4 | 5 | pod2html @ARGV; 6 | 7 | __END__ 8 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/aggregate.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | local db = sqlite3.open_memory() 5 | 6 | assert( db:exec "CREATE TABLE test (col1, col2)" ) 7 | assert( db:exec "INSERT INTO test VALUES (1, 2)" ) 8 | assert( db:exec "INSERT INTO test VALUES (2, 4)" ) 9 | assert( db:exec "INSERT INTO test VALUES (3, 6)" ) 10 | assert( db:exec "INSERT INTO test VALUES (4, 8)" ) 11 | assert( db:exec "INSERT INTO test VALUES (5, 10)" ) 12 | 13 | do 14 | 15 | local square_error_sum = 0 16 | 17 | local function step(ctx, a, b) 18 | local error = a - b 19 | local square_error = error * error 20 | square_error_sum = square_error_sum + square_error 21 | end 22 | 23 | local function final(ctx) 24 | ctx:result_number( square_error_sum / ctx:aggregate_count() ) 25 | end 26 | 27 | assert( db:create_aggregate("my_stats", 2, step, final) ) 28 | 29 | end 30 | 31 | --for a,b in db:urows("SELECT col1, col2 FROM test") 32 | --do print("a b: ", a, b) end 33 | 34 | for my_stats in db:urows("SELECT my_stats(col1, col2) FROM test") 35 | do print("my_stats:", my_stats) end 36 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/function.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | 5 | local db = sqlite3.open_memory() 6 | 7 | assert( db:exec "CREATE TABLE test (col1, col2)" ) 8 | assert( db:exec "INSERT INTO test VALUES (1, 2)" ) 9 | assert( db:exec "INSERT INTO test VALUES (2, 4)" ) 10 | assert( db:exec "INSERT INTO test VALUES (3, 6)" ) 11 | assert( db:exec "INSERT INTO test VALUES (4, 8)" ) 12 | assert( db:exec "INSERT INTO test VALUES (5, 10)" ) 13 | 14 | assert( db:create_function("my_sum", 2, function(ctx, a, b) 15 | ctx:result_number( a + b ) 16 | end)) 17 | 18 | 19 | for col1, col2, sum in db:urows("SELECT *, my_sum(col1, col2) FROM test") do 20 | print(col1, col2, sum) 21 | end 22 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/simple.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | local db = sqlite3.open_memory() 5 | 6 | db:exec[[ 7 | CREATE TABLE test (id INTEGER PRIMARY KEY, content); 8 | 9 | INSERT INTO test VALUES (NULL, 'Hello World'); 10 | INSERT INTO test VALUES (NULL, 'Hello Lua'); 11 | INSERT INTO test VALUES (NULL, 'Hello Sqlite3') 12 | ]] 13 | 14 | for row in db:nrows("SELECT * FROM test") do 15 | print(row.id, row.content) 16 | end 17 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/smart.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | local db = sqlite3.open_memory() 5 | 6 | db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content) ]] 7 | 8 | local stmt = db:prepare[[ INSERT INTO test VALUES (:key, :value) ]] 9 | 10 | stmt:bind_names{ key = 1, value = "Hello World" } 11 | stmt:step() 12 | stmt:reset() 13 | stmt:bind_names{ key = 2, value = "Hello Lua" } 14 | stmt:step() 15 | stmt:reset() 16 | stmt:bind_names{ key = 3, value = "Hello Sqlite3" } 17 | stmt:step() 18 | stmt:finalize() 19 | 20 | for row in db:nrows("SELECT * FROM test") do 21 | print(row.id, row.content) 22 | end 23 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/statement.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | local db = sqlite3.open_memory() 5 | 6 | db:exec[[ 7 | CREATE TABLE test ( 8 | id INTEGER PRIMARY KEY, 9 | content VARCHAR 10 | ); 11 | ]] 12 | 13 | local insert_stmt = assert( db:prepare("INSERT INTO test VALUES (NULL, ?)") ) 14 | 15 | local function insert(data) 16 | insert_stmt:bind_values(data) 17 | insert_stmt:step() 18 | insert_stmt:reset() 19 | end 20 | 21 | local select_stmt = assert( db:prepare("SELECT * FROM test") ) 22 | 23 | local function select() 24 | for row in select_stmt:nrows() do 25 | print(row.id, row.content) 26 | end 27 | end 28 | 29 | insert("Hello World") 30 | print("First:") 31 | select() 32 | 33 | insert("Hello Lua") 34 | print("Second:") 35 | select() 36 | 37 | insert("Hello Sqlite3") 38 | print("Third:") 39 | select() 40 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/examples/tracing.lua: -------------------------------------------------------------------------------- 1 | 2 | require("lsqlite3") 3 | 4 | local db = sqlite3.open_memory() 5 | 6 | db:trace( function(ud, sql) 7 | print("Sqlite Trace:", sql) 8 | end ) 9 | 10 | db:exec[[ 11 | CREATE TABLE test ( id INTEGER PRIMARY KEY, content VARCHAR ); 12 | 13 | INSERT INTO test VALUES (NULL, 'Hello World'); 14 | INSERT INTO test VALUES (NULL, 'Hello Lua'); 15 | INSERT INTO test VALUES (NULL, 'Hello Sqlite3'); 16 | ]] 17 | 18 | for row in db:rows("SELECT * FROM test") do 19 | -- NOP 20 | end 21 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/installpath.lua: -------------------------------------------------------------------------------- 1 | -- Script to find the install path for a C module. Public domain. 2 | 3 | if not arg or not arg[1] then 4 | io.write("Usage: lua installpath.lua modulename\n") 5 | os.exit(1) 6 | end 7 | for p in string.gfind(package.cpath, "[^;]+") do 8 | if string.sub(p, 1, 1) ~= "." then 9 | local p2 = string.gsub(arg[1], "%.", string.sub(package.config, 1, 1)) 10 | io.write(string.gsub(p, "%?", p2), "\n") 11 | return 12 | end 13 | end 14 | error("no suitable installation path found") 15 | -------------------------------------------------------------------------------- /modules/lsqlite3_svn08/lsqlite3-0.8-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "lsqlite3" 2 | version = "0.8-1" 3 | source = { 4 | url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_svn08.zip?uuid=svn_8", 5 | file = "lsqlite3_svn08.zip" 6 | } 7 | description = { 8 | summary = "A binding for Lua to the SQLite3 database library", 9 | detailed = [[ 10 | lsqlite3 is a thin wrapper around the public domain SQLite3 database engine. 11 | The lsqlite3 module supports the creation and manipulation of SQLite3 databases. 12 | After a require('lsqlite3') the exported functions are called with prefix sqlite3. 13 | However, most sqlite3 functions are called via an object-oriented interface to 14 | either database or SQL statement objects. 15 | ]], 16 | license = "MIT/X11", 17 | homepage = "http://lua.sqlite.org/" 18 | } 19 | dependencies = { 20 | "lua >= 5.1" 21 | } 22 | external_dependencies = { 23 | SQLITE = { 24 | header = "sqlite3.h" 25 | } 26 | } 27 | build = { 28 | type = "builtin", 29 | modules = { 30 | lsqlite3 = { 31 | sources = { "lsqlite3.c" }, 32 | libraries = { "sqlite3" }, 33 | incdirs = { "$(SQLITE_INCDIR)" }, 34 | libdirs = { "$(SQLITE_LIBDIR)" } 35 | } 36 | }, 37 | copy_directories = { 'doc', 'examples' } 38 | } 39 | -------------------------------------------------------------------------------- /modules/ltcl.lake: -------------------------------------------------------------------------------- 1 | if not find.include_path 'tcl.h' then 2 | -- Debian/Ubuntu locations 3 | incs = find.include_path {'tcl8.4/tcl.h','tcl8.5/tcl.h','tcl8.6/tcl.h'} 4 | if not incs then 5 | quit "ltcltk: you have to install tcl/tk development files" 6 | end 7 | incs = path.splitpath(incs) -- e.g /usr/include/tcl8.4 8 | _, libs = path.splitpath(incs) -- e.g tcl8.4 9 | else 10 | libs = 'tcl' 11 | end 12 | 13 | luabuild.lua 'ltk' 14 | luabuild.test 'samples/ltcltest.lua' 15 | 16 | return luabuild.library {'ltcl',src='ltcl',libs = libs,incdir={LUADIR,incs},defines='USE_INTERP_RESULT'} 17 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/Makefile: -------------------------------------------------------------------------------- 1 | LUA_INC_DIR=-I/usr/local/include 2 | TCL_INC_DIR=-I/usr/include/tk -I/usr/include 3 | LUA_LIB_DIR=-L/usr/local/lib 4 | TCL_LIB_DIR=-L/usr/include 5 | TCL_LIB=tcl8.5 6 | 7 | INC_DIRS=${LUA_INC_DIR} ${TCL_INC_DIR} 8 | LIB_DIRS=${LUA_LIB_DIR} ${TCL_LIB_DIR} 9 | 10 | INSTALL_ROOT=/usr/local 11 | SO_INST_ROOT=${INSTALL_ROOT}/lib/lua/5.1 12 | LUA_INST_ROOT=${INSTALL_ROOT}/share/lua/5.1 13 | 14 | all: ltcl.so 15 | 16 | ltcl.o: ltcl.c 17 | gcc -O2 ${INC_DIRS} -c $< -o $@ 18 | 19 | ltcl.so: ltcl.o 20 | gcc -shared -fPIC -o $@ ${LIB_DIRS} $< -l${TCL_LIB} 21 | 22 | install: all ltk.lua 23 | cp ltcl.so ${SO_INST_ROOT} 24 | cp ltk.lua ${LUA_INST_ROOT} 25 | 26 | clean: 27 | find . -name "*~" -exec rm {} \; 28 | rm -f *.o *.so *.func *.ps core 29 | for dir in . doc samples; \ 30 | do \ 31 | rm -f $dir/.DS_Store; \ 32 | rm -f $dir/._*; \ 33 | done 34 | 35 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . -name "*~" -exec rm {} \; 4 | rm -f *.o *.so *.func *.ps core 5 | 6 | for dir in . doc samples 7 | do 8 | rm -f $dir/.DS_Store 9 | rm -f $dir/._* 10 | done 11 | 12 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/doc/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, 2011 Gunnar Zötl 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/ltcltk-0.9-2.rockspec: -------------------------------------------------------------------------------- 1 | package = "ltcltk" 2 | version = "0.9-2" 3 | source = { 4 | url = "http://www.tset.de/downloads/ltcltk-0.9-2.tar.gz" 5 | } 6 | description = { 7 | summary = "A binding for lua to the tcl interpreter and to the tk toolkit.", 8 | detailed = [[ 9 | This is a binding of the tcl interpreter to lua. It allows 10 | for calls into tcl, setting and reading variables from tcl and 11 | registering of lua functions for use from tcl. 12 | Also, a binding to the tk toolit is included. 13 | ]], 14 | homepage = "http://www.tset.de/ltcltk/", 15 | license = "MIT/X11", 16 | maintainer = "Gunnar Zötl " 17 | } 18 | supported_platforms = { 19 | "unix", "mac" 20 | } 21 | dependencies = { 22 | "lua >= 5.1" 23 | } 24 | -- does not work because at least on ubuntu tcl.h is in /usr/include/tk, whereas 25 | -- everywhere else it seems to be in /usr/include. I found no way to deal with this 26 | -- in a civil manner, so I resort to a hack. Part 2 at the end of the file. 27 | -- Bad thing is, I lose luarocks' dependency check :( 28 | --external_dependencies = { 29 | -- TCL = { 30 | -- header = "tcl.h" 31 | -- } 32 | --} 33 | build = { 34 | type = "builtin", 35 | modules = { 36 | ltk = "ltk.lua", 37 | ltcl = { 38 | sources = { "ltcl.c" }, 39 | -- change to tcl8.5 or tcl8.4, as needed 40 | libraries = { "tcl8.5" } 41 | }, 42 | }, 43 | copy_directories = { 'doc', 'samples' }, 44 | -- this is part 2 of the abovementioned hack. Not pretty, but at least it works. kinda. 45 | platforms={unix={modules={ltcl={incdirs = { "/usr/include/tk" }}}}} 46 | } 47 | 48 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkaddwidget.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - ltkaddwidget.lua 5 | - 6 | - an example for ltk.addwidget. 7 | - 8 | - Gunnar Zötl , 2010. 9 | - Released under MIT/X11 license. See file LICENSE for details. 10 | --]] 11 | 12 | require "ltk" 13 | 14 | -- these widget types already exist, this is just to demonstrate how 15 | -- ltk.addtkwidget() works 16 | ltk.addtkwidget('button', {'command'}) 17 | 18 | ltk.addtkwidget('text', {'xscrollcommand', 'yscrollcommand'}, { 19 | ['create'] = {'create'}, 20 | ['window'] = {'create'}, 21 | ['bind'] = {3} 22 | }) 23 | 24 | function pressme() 25 | local txt = ltk.wcmd(mytxt) {'get', '0.0', ltk.wcmd(mytxt){'index', 'end'}} 26 | io.write(txt) 27 | ltk.exit() 28 | end 29 | 30 | mytxt = ltk.x_text {} 31 | mybtn = ltk.x_button {text="Press me!", command=pressme} 32 | 33 | ltk.pack {mybtn, side="bottom"} 34 | ltk.pack {mytxt, side="top"} 35 | 36 | ltk.mainloop() 37 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkcheckers.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - ltkcheckers.lua 5 | - 6 | - a simple checkers board with movable pieces 7 | - ported to lua+ltk from a piece of sample code on the tcl/tk wiki 8 | - http://wiki.tcl.tk/884 9 | - 10 | - Gunnar Zötl , 2011. 11 | - Released under MIT/X11 license. See file LICENSE for details. 12 | --]] 13 | 14 | require "ltk" 15 | 16 | local dx = 50 17 | local dy = 50 18 | local colors = {'white', 'black', 'red', 'blue'} 19 | local cx = 0 20 | local cy = 0 21 | 22 | -- the canvas on which we draw 23 | c = ltk.canvas {width = dx * 8, height = dy * 8} 24 | cc = ltk.wcmd(c) 25 | ltk.pack {c} 26 | 27 | -- handler for left-click event: mark position of click 28 | function mark(x, y) 29 | cx = cc {'canvasx', x} 30 | cy = cc {'canvasy', y} 31 | end 32 | 33 | -- handler for drag event: move piece 34 | function move(x, y) 35 | -- "current" is the piece we clicked on 36 | local id = cc {'find', 'withtag', 'current'} 37 | x = cc {'canvasx', x} 38 | y = cc {'canvasy', y} 39 | cc {'move', id, x - cx, y - cy} 40 | cc {'raise', id} 41 | cx = x 42 | cy = y 43 | end 44 | 45 | -- handler for release event: snap to board 46 | function drop() 47 | local id = cc {'find', 'withtag', 'current'} 48 | local cx0 = math.floor(cx / dx) * dx + 2 49 | local cy0 = math.floor(cy / dy) * dy + 2 50 | local cx1 = cx0 + dx - 3 51 | local cy1 = cy0 + dy - 3 52 | cc {'coords', id, cx0, cy0, cx1, cy1} 53 | end 54 | 55 | cc {'bind', 'mv', '', {mark, '%x', '%y'}} 56 | cc {'bind', 'mv', '', {move, '%x', '%y'}} 57 | cc {'bind', 'mv', '', drop} 58 | 59 | -- create a piece 60 | function makepiece (x, y, color, args) 61 | cc {'create', 'oval', x+2, y+2, x+dx-3, y+dy-3, fill=color, tags={args, 'mv'}} 62 | end 63 | 64 | -- create a board field 65 | function makecheck (x, y, color, args) 66 | cc {'create', 'rectangle', x, y, x+dx, y+dy, fill=color, tags={args}} 67 | end 68 | 69 | -- draw board and place pieces 70 | color = 0 71 | for i = 0, 7 do 72 | y = i * dy 73 | for j = 0, 7 do 74 | x = j * dx 75 | makecheck(x, y, colors[color]) 76 | if i < 3 and color > 0 then 77 | makepiece(x, y, colors[2], 'player2') 78 | end 79 | if i > 4 and color > 0 then 80 | makepiece(x, y, colors[3], 'player1') 81 | end 82 | color = 1 - color 83 | end 84 | color = 1 - color 85 | end 86 | 87 | ltk.mainloop() 88 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkfuncplotter.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevedonovan/luabuild/4c2afadb6184911e8fdcd0215f3dceede0aad180/modules/ltcltk-0.9-2/samples/ltkfuncplotter.lua -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkhello.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - ltkhello.lua 5 | - 6 | - a somewhat involved Hello World example. 7 | - 8 | - 9 | - Gunnar Zötl , 2010. 10 | - Released under MIT/X11 license. See file LICENSE for details. 11 | --]] 12 | 13 | require("ltk") 14 | 15 | -- multipurpose destroy event handler, just displays some info. 16 | function destroy(hash, t, T, W, X) 17 | print(string.format("destroy called, #='%s', t='%s', T='%s', W='%s', X='%s'", hash, t, T, W, X)) 18 | print("Widget " .. W) 19 | end 20 | 21 | -- create a button with a simple action that just terminates the program. 22 | -- attach a destroy handler to it just for the sake of doing it 23 | -- 24 | function finished() 25 | ltk.exit() 26 | end 27 | b = ltk.button { } 28 | -- the following could also have been an option for the creation of the button 29 | ltk.wcmd(b){'configure', text='OK'} 30 | ltk.wcmd(b){'configure', command=finished} 31 | ltk.bind{b, '', {destroy, '%#', '%t', '%T', '%W', '%X'}} 32 | 33 | -- create a text widget with a click handler, that inserts additional stuff. 34 | -- also attach a destroy handler to it, again just for the sake of doing it 35 | -- 36 | t = ltk.text {width=40, height=20} 37 | function click(b, x, y) 38 | -- get insert position 39 | local pos = ltk.wcmd(t){'index', 'end'} 40 | -- get char position 41 | local cpos = ltk.wcmd(t){'index', '@'..x..','..y} 42 | ltk.wcmd(t){'insert', pos, string.format("click <%s> at %s\n", b, cpos)} 43 | end 44 | ltk.bind{t, '', {destroy, '%#', '%t', '%T', '%W', '%X'}} 45 | ltk.bind{t, '', {click, '%b', '%x', '%y'}} 46 | -- add some initial text 47 | ltk.wcmd(t){'insert', '0.0', "Hello Lua!\n"} 48 | 49 | -- now for the layout, one under the other 50 | ltk.grid{'configure', t, row=1} 51 | ltk.grid{'configure', b, row=2} 52 | 53 | -- attach a handler to the main window 54 | ltk.bind{'.', '', {destroy, '%#', '%t', '%T', '%W', '%X'}} 55 | 56 | -- and go. 57 | ltk.mainloop() 58 | 59 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkimage.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - ltkimage.lua 5 | - 6 | - an example for some ltk image stuff and idle callbacks 7 | - 8 | - Gunnar Zötl , 2010. 9 | - Released under MIT/X11 license. See file LICENSE for details. 10 | --]] 11 | 12 | require "ltk" 13 | 14 | img = ltk.image{'create', 'photo', width=256, height=256} 15 | imgcmd = ltk.wcmd(img) 16 | 17 | function drawimg() 18 | local drawfn 19 | drawfn = coroutine.wrap(function() 20 | local x, y, z, col 21 | z = 0 22 | while true do 23 | for x=0, 255 do 24 | for y=0, 255 do 25 | col = string.format("#%02X%02X%02X", x, y, z) 26 | imgcmd{'put', col, to = ltk.vals(x, y)} 27 | if y%63 == 0 then 28 | ltk.after{'idle', drawfn} 29 | coroutine.yield() 30 | end 31 | end 32 | end 33 | z = (z + 51) % 256 34 | end 35 | end) 36 | ltk.after{'idle', drawfn} 37 | end 38 | 39 | c=ltk.canvas { width=256, height=256 } 40 | ccmd = ltk.wcmd(c) 41 | ccmd{'create', 'image', 0, 0, image=img, anchor='nw'} 42 | 43 | b = ltk.button {text="Close", command=function() ltk.exit() end} 44 | 45 | ltk.grid{c, row=1} 46 | ltk.grid{b, row=2} 47 | -- show window and all 48 | ltk.update() 49 | 50 | -- initial image 51 | drawimg() 52 | 53 | -- and run 54 | ltk.mainloop() 55 | 56 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/ltkoptionmenu.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - ltkoptionmenu.lua 5 | - 6 | - an example for optionmenus - ltk style. 7 | - 8 | - 9 | - Gunnar Zötl , 2010. 10 | - Released under MIT/X11 license. See file LICENSE for details. 11 | --]] 12 | 13 | require "ltk" 14 | 15 | function handle(om, val) 16 | print("optionMenu '"..om.."' was set to '"..tostring(val).."'") 17 | end 18 | 19 | -- optionmenu with a function 20 | om1, m1 = ltk.tk_optionMenu{handle, 'Func Option 1', 'Func Option 2', 'Func Option 3'} 21 | print("optionMenu '"..om1.."' was created, menu widget is '"..m1.."'") 22 | 23 | -- optionmenu writing selection to tcl variable 24 | om2, m2 = ltk.tk_optionMenu{'optvar', 'Var Option 1', 'Var Option 2', 'Var Option 3'} 25 | print("optionMenu '"..om2.."' was created, menu widget is '"..m2.."'") 26 | 27 | var = "" 28 | function checkvar() 29 | if ltk.var.optvar ~= var then 30 | var = ltk.var.optvar 31 | print("optionMenu '"..om2.."' was set to '"..var.."'") 32 | end 33 | ltk.after{100, checkvar} 34 | end 35 | -- every now and then check wether the variable for the 2nd option menu has changed, 36 | -- for reporting purposes 37 | ltk.after{100, checkvar} 38 | 39 | ltk.grid{om1, om2} 40 | ltk.mainloop() 41 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/renumbertests.lua: -------------------------------------------------------------------------------- 1 | -- renumber test comments in ltcltest.lua 2 | 3 | testno = false 4 | for s in io.lines() do 5 | m = string.match(s, '^-- (%d+)$') 6 | if m then 7 | if not testno then 8 | testno = m * 1 9 | else 10 | testno = testno + 1 11 | end 12 | print("-- "..tostring(testno)) 13 | else 14 | print(s) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /modules/ltcltk-0.9-2/samples/tkhello.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | --[[ 4 | - tkhello.lua 5 | - 6 | - Gunnar Zötl , 2010. 7 | - Released under MIT/X11 license. See file LICENSE for details. 8 | --]] 9 | 10 | -- straight port of Tk8.5 widget example to ltk, original header follows: 11 | -- 12 | --# hello -- 13 | --# Simple Tk script to create a button that prints "Hello, world". 14 | --# Click on the button to terminate the program. 15 | --# 16 | --# RCS: @(#) $Id: hello,v 1.4 2003/09/30 14:54:30 dkf Exp $ 17 | 18 | require "ltk" 19 | 20 | -- The first line below creates the button, and the second line 21 | -- asks the packer to shrink-wrap the application's main window 22 | -- around the button. 23 | 24 | hello = ltk.button{text="Hello, world", command=function() 25 | print "Hello, world!" 26 | ltk.exit() 27 | end} 28 | ltk.pack{hello} 29 | 30 | ltk.mainloop() 31 | -------------------------------------------------------------------------------- /modules/lua-linenoise/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Rob Hoelz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /modules/lua-linenoise/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-fPIC 2 | 3 | linenoise.so: linenoise.o 4 | gcc -o $@ -shared $^ -llinenoise 5 | 6 | clean: 7 | rm -f *.o *.so 8 | -------------------------------------------------------------------------------- /modules/lua-linenoise/README.md: -------------------------------------------------------------------------------- 1 | # lua-linenoise - Lua binding for the linenoise command line library 2 | 3 | Linenoise (https://github.com/antirez/linenoise) is a delightfully simple command 4 | line library. This Lua module is simply a binding for it. 5 | -------------------------------------------------------------------------------- /modules/lua-linenoise/example.lua: -------------------------------------------------------------------------------- 1 | local L = require 'linenoise' 2 | -- L.clearscreen() 3 | print '----- Testing lua-linenoise! ------' 4 | local prompt, history = '? ', 'history.txt' 5 | L.historyload(history) -- load existing history 6 | L.setcompletion(function(c,s) 7 | if s == 'h' then 8 | L.addcompletion(c,'help') 9 | L.addcompletion(c,'halt') 10 | end 11 | end) 12 | local line = L.linenoise(prompt) 13 | while line do 14 | if #line > 0 then 15 | print(line:upper()) 16 | L.historyadd(line) 17 | L.historysave(history) -- save every new line 18 | end 19 | line = L.linenoise(prompt) 20 | end 21 | 22 | -------------------------------------------------------------------------------- /modules/lua-linenoise/linenoise-0.1-1.rockspec: -------------------------------------------------------------------------------- 1 | package = 'linenoise' 2 | version = '0.1-1' 3 | source = { 4 | url = 'https://github.com/downloads/hoelzro/lua-linenoise/lua-linenoise-0.1.tar.gz' 5 | } 6 | description = { 7 | summary = 'A binding for the linenoise command line library', 8 | homepage = 'https://github.com/hoelzro/lua-linenoise', 9 | license = 'MIT/X11', 10 | } 11 | dependencies = { 12 | 'lua >= 5.1' 13 | } 14 | 15 | build = { 16 | type = 'builtin', 17 | modules = { 18 | linenoise = { 19 | sources = { 'linenoise.c' }, 20 | libraries = { 'linenoise' }, 21 | }, 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /modules/luaexpat/src/lxp.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | luaopen_lxp -------------------------------------------------------------------------------- /modules/luaexpat/src/lxp/lom.lua: -------------------------------------------------------------------------------- 1 | -- See Copyright Notice in license.html 2 | -- $Id: lom.lua,v 1.6 2005/06/09 19:18:40 tuler Exp $ 3 | 4 | local lxp = require "lxp" 5 | 6 | local tinsert, tremove = table.insert, table.remove 7 | local assert, type, print = assert, type, print 8 | 9 | local lom = {} 10 | 11 | local function starttag (p, tag, attr) 12 | local stack = p:getcallbacks().stack 13 | local newelement = {tag = tag, attr = attr} 14 | tinsert(stack, newelement) 15 | end 16 | 17 | local function endtag (p, tag) 18 | local stack = p:getcallbacks().stack 19 | local element = tremove(stack) 20 | assert(element.tag == tag) 21 | local level = #stack 22 | tinsert(stack[level], element) 23 | end 24 | 25 | local function text (p, txt) 26 | local stack = p:getcallbacks().stack 27 | local element = stack[#stack] 28 | local n = #element 29 | local n = #element 30 | if type(element[n]) == "string" then 31 | element[n] = element[n] .. txt 32 | else 33 | tinsert(element, txt) 34 | end 35 | end 36 | 37 | function lom.parse (o) 38 | local c = { StartElement = starttag, 39 | EndElement = endtag, 40 | CharacterData = text, 41 | _nonstrict = true, 42 | stack = {{}} 43 | } 44 | local p = lxp.new(c) 45 | local status, err 46 | if type(o) == "string" then 47 | status, err = p:parse(o) 48 | if not status then return nil, err end 49 | else 50 | for l in o do 51 | status, err = p:parse(l) 52 | if not status then return nil, err end 53 | end 54 | end 55 | status, err = p:parse() 56 | if not status then return nil, err end 57 | p:close() 58 | return c.stack[1][1] 59 | end 60 | 61 | return lom 62 | -------------------------------------------------------------------------------- /modules/luaexpat/src/lxplib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** See Copyright Notice in license.html 3 | */ 4 | 5 | #define ParserType "Expat" 6 | 7 | #define StartCdataKey "StartCdataSection" 8 | #define EndCdataKey "EndCdataSection" 9 | #define CharDataKey "CharacterData" 10 | #define CommentKey "Comment" 11 | #define DefaultKey "Default" 12 | #define DefaultExpandKey "DefaultExpand" 13 | #define StartElementKey "StartElement" 14 | #define EndElementKey "EndElement" 15 | #define ExternalEntityKey "ExternalEntityRef" 16 | #define StartNamespaceDeclKey "StartNamespaceDecl" 17 | #define EndNamespaceDeclKey "EndNamespaceDecl" 18 | #define NotationDeclKey "NotationDecl" 19 | #define NotStandaloneKey "NotStandalone" 20 | #define ProcessingInstructionKey "ProcessingInstruction" 21 | #define UnparsedEntityDeclKey "UnparsedEntityDecl" 22 | 23 | int luaopen_lxp (lua_State *L); 24 | -------------------------------------------------------------------------------- /modules/luaexpat/src/test-driver.lua: -------------------------------------------------------------------------------- 1 | os.execute(arg[-1]..' ../tests/test.lua') 2 | os.execute(arg[-1]..' ../tests/test-lom.lua') 3 | -------------------------------------------------------------------------------- /modules/luaexpat/tests/test-lom.lua: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/lua 2 | 3 | local lom = require "lxp.lom" 4 | 5 | local tests = { 6 | [[inside tag `abc']], 7 | [[ 8 | some text 9 | ]], 10 | } 11 | 12 | function table._tostring (tab, indent, spacing) 13 | local s = {} 14 | spacing = spacing or "" 15 | indent = indent or "\t" 16 | table.insert (s, "{\n") 17 | for nome, val in pairs (tab) do 18 | table.insert (s, spacing..indent) 19 | local t = type(nome) 20 | if t == "string" then 21 | table.insert (s, string.format ("[%q] = ", tostring (nome))) 22 | elseif t == "number" or t == "boolean" then 23 | table.insert (s, string.format ("[%s] = ", tostring (nome))) 24 | else 25 | table.insert (s, t) 26 | end 27 | t = type(val) 28 | if t == "string" or t == "number" then 29 | table.insert (s, string.format ("%q", val)) 30 | elseif t == "table" then 31 | table.insert (s, table._tostring (val, indent, spacing..indent)) 32 | else 33 | table.insert (s, t) 34 | end 35 | table.insert (s, ",\n") 36 | end 37 | table.insert (s, spacing.."}") 38 | return table.concat (s) 39 | end 40 | 41 | function table.print (tab, indent, spacing) 42 | io.write (table._tostring (tab, indent, spacing)) 43 | end 44 | 45 | 46 | for i, s in ipairs(tests) do 47 | --s = string.gsub (s, "[\n\r\t]", "") 48 | local ds = assert (lom.parse ([[]]..s)) 49 | print(table._tostring(ds)) 50 | end 51 | -------------------------------------------------------------------------------- /modules/luaposix/AUTHORS: -------------------------------------------------------------------------------- 1 | luaposix is the work of several authors. It is based on two earlier 2 | libraries: 3 | 4 | An earlier version of luaposix (up to 5.1.11) 5 | 6 | Copyright Reuben Thomas 2010-2011 7 | Copyright Natanael Copa 2008-2010 8 | Clean up and bug fixes by Leo Razoumov 2006-10-11 9 | Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 10 | Based on original by Claudio Terra for Lua 3.x, with contributions 11 | by Roberto Ierusalimschy. 12 | 13 | lcurses release 7 14 | 15 | Copyright Tiago Dionizio 2004-2007 16 | Copyright Reuben Thomas 2009-2011 17 | 18 | John Belmonte wrote the example program tree.lua. 19 | -------------------------------------------------------------------------------- /modules/luaposix/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2006-2012 luaposix authors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /modules/luaposix/ChangeLog.old: -------------------------------------------------------------------------------- 1 | History is now tracked in git. 2 | https://github.com/rrthomas/luaposix 3 | 4 | 2008-07-18 Natanael Copa 5 | * fix rpoll to ignore the POLLHUP and POLLNVAL reported at: 6 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=491257 7 | * added crypt(). Patch from dev.openwrt.org 8 | 9 | 2008-06-03 Natanael Copa 10 | * replace luaL_openlib with the newer luaL_register. 11 | * Support for building on Darwin/OSX. Patch from 12 | Felix Fietkau 13 | 14 | 2008-01-29 Natanael Copa 15 | * added openlog(), syslog() and closelog() 16 | * fixed dup() to handle lua files 17 | * renamed exec() to execp() and added a new exec func that uses execv(3) 18 | * added fileno() 19 | 20 | 2008-01-25 Natanael Copa 21 | * created fork luaposix 22 | o added poll() patch from: 23 | http://lua-users.org/lists/lua-l/2007-11/msg00346.html 24 | o cleaned up Makefile 25 | 26 | 2006-10-16 Leo Razoumov 27 | * Added glob wrapper (Pglob) implementated by George 28 | Created corresponding test. 29 | 30 | 2006-10-12 Leo Razoumov 31 | * Starting with Luiz Henrique de Figueiredo (LHF) 2006-04-07 version of 32 | lposix.c fixed the following problems when compiling for Lua-5.1 (Lua-5.1.x) 33 | o Added missing functions to lposix.c: Prmdir, Punlink 34 | o Restored older lposix-5.0 implementation of the following functions: 35 | Pumask, Pchmod 36 | * restored modemuncher.c from lposix-5.0 since April 2006 lposix.c version has broken 37 | implementation of modemunch(...) function. 38 | * Function Ptimes: wrong conversion of clock ticks to seconds. Replaced 39 | scaling by CLOCKS_PER_SEC macro (that should never be used, btw) with 40 | POSIX compliant sysconf(_SC_CLK_TCK) value. 41 | * Update test.lua and tree.lua to reflect lposix.c API changes 42 | * Deleted posix.lua loader file not needed anymore in Lua-5.1 module system 43 | * Remaining problems: Pumask does not take mask in octal form, it only 44 | understand alphabetic notation like "u=rwx" 45 | -------------------------------------------------------------------------------- /modules/luaposix/NEWS: -------------------------------------------------------------------------------- 1 | See the web site (listed in README) for news. 2 | -------------------------------------------------------------------------------- /modules/luaposix/README: -------------------------------------------------------------------------------- 1 | luaposix 2 | -------- 3 | 4 | Reuben Thomas 5 | http://luaforge.net/projects/luaposix 6 | 7 | 8 | This is a POSIX library, including curses, for Lua 5.1 and 5.2. It 9 | is released under the MIT license, like Lua (see COPYING; it's 10 | basically the same as the BSD license). There is no warranty. 11 | 12 | Please report bugs and make suggestions to the email address above, or 13 | use the LuaForge trackers. 14 | 15 | 16 | Installation 17 | ------------ 18 | 19 | luaposix uses the GNU build system. For detailed instructions, see 20 | INSTALL. For a quick start: 21 | 22 | [If using git sources: 23 | 24 | ./bootstrap 25 | ] 26 | 27 | ./configure && make [&& make install] 28 | 29 | The following options may be of interest if you have Lua installed on 30 | non-default paths (as you are likely to on any system supporting more 31 | than one version of Lua): 32 | 33 | --libdir=DIR Install shared library in this directory 34 | --with-lua-prefix=DIR Lua files are in DIR 35 | --with-lua-suffix=ARG Lua binary and library files are suffixed with ARG 36 | 37 | For example, on Debian or Ubuntu: 38 | 39 | CPPFLAGS='-I/usr/include/lua5.1' ./configure --libdir=/usr/local/lib/lua/5.1 --datadir=/usr/local/share/lua/5.1 --with-lua-suffix=5.1 40 | 41 | To run some tests: 42 | 43 | make check 44 | 45 | lunit is required for some of the tests. For a version of lunit that 46 | works with Lua 5.2, see: https://github.com/dcurrie/lunit.git 47 | 48 | 49 | Use 50 | --- 51 | 52 | The library is split into two modules. The basic POSIX APIs are in 53 | "posix"; the curses APIs in "curses". 54 | 55 | There is some HTML documentation for the curses module; to obtain it, 56 | run 57 | 58 | make doc 59 | 60 | For the posix module, see lposix.c. For detailed documentation on 61 | POSIX APIs, read the POSIX and curses man pages, or an online POSIX 62 | reference such as: 63 | 64 | http://www.opengroup.org/onlinepubs/007904875/toc.htm 65 | 66 | To see a summary of which POSIX APIs are available, run 67 | 68 | make show-funcs 69 | 70 | 71 | Example code 72 | ------------ 73 | 74 | See the example program tree.lua, along with the tests in 75 | tests*.lua. 76 | 77 | GNU Zile 2.5.0 and later is written in Lua, using luaposix, so it 78 | contains plenty of example code. See the lua branch of its git 79 | repository at: http://git.savannah.gnu.org/cgit/zile.git/log/?h=lua 80 | -------------------------------------------------------------------------------- /modules/luaposix/curses.lua: -------------------------------------------------------------------------------- 1 | --- Lua bindings for curses 2 | local M = require "curses_c" 3 | local curses = M 4 | 5 | -- These Lua functions detect number of args, like Unified Funcs in Perl Curses 6 | -- see http://pjb.com.au/comp/lua/lcurses.html 7 | -- see http://search.cpan.org/perldoc?Curses 8 | 9 | function M.addch (...) 10 | if #{...} == 3 then 11 | return curses.stdscr():mvaddch(...) 12 | else 13 | return curses.stdscr():addch(...) 14 | end 15 | end 16 | 17 | function M.addstr(...) -- detect number of args, like Unified Funcs in Perl Curses 18 | if #{...} == 3 then 19 | return curses.stdscr():mvaddstr(...) 20 | else 21 | return curses.stdscr():addstr(...) 22 | end 23 | end 24 | 25 | function M.attrset (a) return curses.stdscr():attrset(a) end 26 | function M.clear () return curses.stdscr():clear() end 27 | function M.clrtobot () return curses.stdscr():clrtobot() end 28 | function M.clrtoeol () return curses.stdscr():clrtoeol() end 29 | 30 | function M.getch (...) 31 | local c 32 | if #{...} == 2 then 33 | c = curses.stdscr():mvgetch(...) 34 | else 35 | c = curses.stdscr():getch() 36 | end 37 | if c < 256 then 38 | return string.char(c) 39 | end 40 | -- could kludge-test for utf8, e.g. c3 a9 20 c3 aa 20 c3 ab 20 e2 82 ac 0a 41 | return c 42 | end 43 | 44 | function M.getstr (...) 45 | if #{...} > 1 then 46 | return curses.stdscr():mvgetstr(...) 47 | else 48 | return curses.stdscr():getstr(...) 49 | end 50 | end 51 | M.getnstr = M.getstr 52 | 53 | function M.getyx () return curses.stdscr():getyx() end 54 | function M.keypad (b) return curses.stdscr():keypad(b) end 55 | function M.move (y,x) return curses.stdscr():move(y,x) end 56 | function M.refresh () return curses.stdscr():refresh() end 57 | function M.timeout (t) return curses.stdscr():timeout(t) end 58 | 59 | return M 60 | -------------------------------------------------------------------------------- /modules/luaposix/lua52compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lua 5.2 compatibility 3 | * (c) Reuben Thomas (maintainer) 2010-2011 4 | * This file is in the public domain. 5 | */ 6 | 7 | #if LUA_VERSION_NUM > 501 8 | #define luaL_reg luaL_Reg 9 | #define lua_objlen lua_rawlen 10 | #define lua_strlen lua_rawlen 11 | #define luaL_openlib(L,n,l,nup) luaL_setfuncs((L),(l),(nup)) 12 | #define luaL_register(L,n,l) luaL_newlib((L),(l)) 13 | 14 | #if LUA_VERSION_NUM > 502 15 | #define luaL_checkint(L,n) (int)luaL_checkinteger(L,n) 16 | #define luaL_optint(L,n,d) (int)luaL_optinteger(L,n,d) 17 | #endif 18 | 19 | #include 20 | static int luaL_typerror(lua_State *L, int narg, const char *tname) 21 | { 22 | const char *msg = lua_pushfstring(L, "%s expected, got %s", 23 | tname, luaL_typename(L, narg)); 24 | return luaL_argerror(L, narg, msg); 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /modules/luaposix/tests-curses.lua: -------------------------------------------------------------------------------- 1 | -- Trivial test that we can load the module 2 | require "curses" 3 | -------------------------------------------------------------------------------- /modules/luaposix/tests-fcntl.lua: -------------------------------------------------------------------------------- 1 | lunit = require "lunit" 2 | bit = bit32 or require "bit" 3 | 4 | module("test_fcntl", lunit.testcase, package.seeall) 5 | 6 | function test_sane_getfl() 7 | local posix = require "posix" 8 | local fd = posix.fileno(io.stdin) 9 | local flags = posix.fcntl(fd, posix.F_GETFL) 10 | assert_number(flags) 11 | assert(flags >= 0, "returned flags are negative") 12 | end 13 | 14 | function test_setfl_works() 15 | local posix = require "posix" 16 | local fd = posix.fileno(io.stdin) 17 | local flags = posix.fcntl(fd, posix.F_GETFL) 18 | -- Remove NONBLOCK, if any 19 | posix.fcntl(fd, posix.F_SETFL, bit.band(flags, bit.bnot(posix.O_NONBLOCK))) 20 | flags = posix.fcntl(fd, posix.F_GETFL) 21 | assert(bit.band(flags, posix.O_NONBLOCK) == 0, "Removal of O_NONBLOCK failed") 22 | posix.fcntl(fd, posix.F_SETFL, bit.bor(flags, posix.O_NONBLOCK)) 23 | flags = posix.fcntl(fd, posix.F_GETFL) 24 | assert(bit.band(flags, posix.O_NONBLOCK) ~= 0, "Set of O_NONBLOCK failed") 25 | end 26 | 27 | function test_negative_fd_fails() 28 | local posix = require "posix" 29 | ret, msg, errno = posix.fcntl(-7, posix.F_GETFL) 30 | assert_nil(ret) 31 | end 32 | 33 | function test_nonopen_fd_fails() 34 | local posix = require "posix" 35 | ret, msg, errno = posix.fcntl(666, posix.F_GETFL) 36 | assert_nil(ret) 37 | end 38 | 39 | function test_wrong_userdata_fails() 40 | local posix = require "posix" 41 | assert_error("Passing wrong type instead of fd does not bomb out", 42 | function() 43 | posix.fcntl("foobar", posix.F_GETFL) 44 | end) 45 | end 46 | -------------------------------------------------------------------------------- /modules/luaposix/tree.lua: -------------------------------------------------------------------------------- 1 | -- tree view of the file system like the "tree" unix utility 2 | -- John Belmonte 3 | 4 | local posix = require('posix') 5 | 6 | unpack = unpack or table.unpack 7 | 8 | local leaf_indent = '| ' 9 | local tail_leaf_indent = ' ' 10 | local leaf_prefix = '|-- ' 11 | local tail_leaf_prefix = '`-- ' 12 | local link_prefix = ' -> ' 13 | 14 | local function printf(...) 15 | io.write(string.format(...)) 16 | end 17 | 18 | local function do_directory(directory, level, prefix) 19 | local num_dirs = 0 20 | local num_files = 0 21 | local files = posix.dir(directory) 22 | local last_file_index = #files 23 | table.sort(files) 24 | for i, name in ipairs(files) do 25 | if name ~= '.' and name ~= '..' then 26 | local full_name = string.format('%s/%s', directory, name) 27 | local info = assert(posix.stat(full_name)) 28 | local is_tail = (i==last_file_index) 29 | local prefix2 = is_tail and tail_leaf_prefix or leaf_prefix 30 | local link = '' 31 | if info.type == 'link' then 32 | linked_name = assert(posix.readlink(full_name)) 33 | link = string.format('%s%s', link_prefix, linked_name) 34 | end 35 | printf('%s%s%s%s\n', prefix, prefix2, name, link) 36 | if info.type == 'directory' then 37 | local indent = is_tail and tail_leaf_indent or leaf_indent 38 | -- TODO: cache string concatination 39 | sub_dirs, sub_files = do_directory(full_name, level+1, 40 | prefix .. indent) 41 | num_dirs = num_dirs + sub_dirs + 1 42 | num_files = num_files + sub_files 43 | else 44 | num_files = num_files + 1 45 | end 46 | end 47 | end 48 | return num_dirs, num_files 49 | end 50 | 51 | local function fore(directory) 52 | print(directory) 53 | num_dirs, num_files = do_directory(directory, 0, '') 54 | printf('\n%d directories, %d files\n', num_dirs, num_files) 55 | end 56 | 57 | directory = (#arg > 0) and arg[1] or '.' 58 | fore(directory) 59 | -------------------------------------------------------------------------------- /modules/luasignal/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 Jesse Luehrs 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /modules/luasignal/README: -------------------------------------------------------------------------------- 1 | LuaSignal v0.1 2 | Jesse Luehrs (jluehrs2@uiuc.edu) 3 | 4 | OVERVIEW 5 | ======== 6 | LuaSignal is a library for handling and generating POSIX signals from within 7 | Lua. 8 | 9 | INSTALL 10 | ======= 11 | To install, modify Make.config to point to the appropriate paths, then type 12 | 'make' and 'make install'. 13 | 14 | DOCUMENTATION 15 | ============= 16 | API documentation can be found in the doc/ directory. It was autogenerated from the source files by LuaDoc (http://luadoc.luaforge.net/). 17 | 18 | A few things to be aware of when using LuaSignal: 19 | - LuaSignal is not reentrant, since it keeps the active Lua state in a global 20 | variable to be accessed from the signal handler. Therefore, it is not safe to 21 | use LuaSignal from multiple threads. 22 | - LuaSignal is implemented using debug hooking API that Lua provides. Other 23 | programs or libraries that also use Lua debugging hooks may miss events that 24 | occur at the moment a signal fires, because of limitations in the Lua hook 25 | API. Programs that modify debugging hooks during program execution could also 26 | exhibit random failures, since they can be interrupted by a signal, which 27 | will also modify the hooks. 28 | 29 | CHANGES 30 | ======= 31 | 0.1 32 | - First public release 33 | 34 | COPYRIGHT AND LICENSE 35 | ===================== 36 | Copyright (C) 2007 Jesse Luehrs 37 | 38 | This code is distributed under the MIT license; a copy is in the LICENSE file 39 | distributed with the source. 40 | -------------------------------------------------------------------------------- /modules/luasignal/TODO: -------------------------------------------------------------------------------- 1 | - more tests, and automated tests if possible 2 | - kill, suspend, and mask are completely untested, so they may or may not 3 | work at all 4 | - refactor a lot of the common code between the functions - mask and suspend in 5 | particular 6 | -------------------------------------------------------------------------------- /modules/luasignal/src/queue.c: -------------------------------------------------------------------------------- 1 | #include "queue.h" 2 | #include 3 | 4 | static int _queue_resize(queue* q, int new_cap) 5 | { 6 | int* new_queue; 7 | int i; 8 | 9 | if (new_cap <= q->cap) { 10 | return 0; 11 | } 12 | if ((new_queue = (int*)malloc(new_cap * sizeof(int))) == NULL) { 13 | return 0; 14 | } 15 | if (q->front <= q->back) { 16 | q->front = q->front + q->cap; 17 | } 18 | for (i = q->back; i < q->front; ++i) { 19 | new_queue[i - q->back] = q->queue[i % q->cap]; 20 | } 21 | free(q->queue); 22 | q->queue = new_queue; 23 | q->cap = new_cap; 24 | q->front = q->size; 25 | q->back = 0; 26 | 27 | return 1; 28 | } 29 | 30 | int queue_init(queue* q, int cap) 31 | { 32 | if (cap < 1) { 33 | return 0; 34 | } 35 | if ((q->queue = (int*)malloc(cap * sizeof(int))) == NULL) { 36 | return 0; 37 | } 38 | q->size = 0; 39 | q->cap = cap; 40 | q->front = 0; 41 | q->back = 0; 42 | 43 | return 1; 44 | } 45 | 46 | int enqueue(queue* q, int item) 47 | { 48 | if (q->size == q->cap) { 49 | if (!_queue_resize(q, 2 * q->cap)) { 50 | return 0; 51 | } 52 | } 53 | q->queue[q->front++] = item; 54 | q->front %= q->cap; 55 | ++q->size; 56 | 57 | return 1; 58 | } 59 | 60 | int dequeue(queue* q) 61 | { 62 | int ret; 63 | 64 | if (q->size == 0) { 65 | return -1; 66 | } 67 | ret = q->queue[q->back++]; 68 | q->back %= q->cap; 69 | --q->size; 70 | 71 | return ret; 72 | } 73 | 74 | void queue_delete(queue* q) 75 | { 76 | free(q->queue); 77 | q->queue = NULL; 78 | q->size = 0; 79 | q->cap = 0; 80 | } 81 | -------------------------------------------------------------------------------- /modules/luasignal/src/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_H 2 | #define QUEUE_H 3 | 4 | typedef struct _queue { 5 | int* queue; 6 | int size; 7 | int cap; 8 | int front; 9 | int back; 10 | } queue; 11 | 12 | int queue_init(queue* q, int cap); 13 | int enqueue(queue* q, int item); 14 | int dequeue(queue* q); 15 | void queue_delete(queue* q); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /modules/luasignal/src/signal.luadoc: -------------------------------------------------------------------------------- 1 | --- 2 | -- LuaSignal - Signal handling library for Lua 5.1 3 | module "signal" 4 | --- 5 | -- Set a signal handler. 6 | -- @param signal String name of the signal to be handled (i.e. INT, ALRM) 7 | -- @param handler Function to be called when the signal is received. Also, the 8 | -- string "ignore" can be passed to cause the signal to be 9 | -- ignored, "default" to cause the signal to use Lua's default 10 | -- handler, and "cdefault" to cause the signal to use your 11 | -- system's default behavior (since Lua overrides some signal 12 | -- handlers to provide things like error messages and stack 13 | -- traces) 14 | function signal(signal, handler) 15 | --- 16 | -- Pause program execution for a given amount of time. This is a thin wrapper 17 | -- around the alarm() POSIX function. 18 | -- @param signal String name of the signal to be handled (i.e. INT, ALRM) 19 | -- @return See your system's man page for the alarm() function 20 | function alarm(signal) 21 | --- 22 | -- Send a signal to a process. This is a thin wrapper around the kill() POSIX 23 | -- function. 24 | -- @param pid PID of the process to receive the signal 25 | -- @param signal String name of the signal to be handled (i.e. INT, ALRM) 26 | -- @return See your system's man page for the kill() function 27 | function kill(pid, signal) 28 | --- 29 | -- Send a signal to the current process. This is a thin wrapper around the 30 | -- raise() POSIX function. 31 | -- @param signal String name of the signal to be handled (i.e. INT, ALRM) 32 | -- @return See your system's man page for the raise() function 33 | function raise(signal) 34 | 35 | -------------------------------------------------------------------------------- /modules/luasignal/src/signames.c: -------------------------------------------------------------------------------- 1 | #include "signames.h" 2 | #include 3 | #include 4 | #include 5 | 6 | const char* sig_to_name(int sig) 7 | { 8 | static char signame[7]; 9 | 10 | #ifdef SIGRTMIN 11 | if (sig >= SIGRTMIN && sig <= SIGRTMAX) { 12 | snprintf(signame, 7, "RT%d", sig - SIGRTMIN); 13 | 14 | return signame; 15 | } 16 | else { 17 | #endif 18 | int i; 19 | 20 | for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); ++i) { 21 | if (sigs[i].sig == sig) { 22 | return sigs[i].name; 23 | } 24 | } 25 | 26 | return NULL; 27 | #ifdef SIGRTMIN 28 | } 29 | #endif 30 | } 31 | 32 | int name_to_sig(const char* name) 33 | { 34 | #ifdef SIGRTMIN 35 | if (strncmp(name, "RT", 2) == 0) { 36 | int rtsig; 37 | 38 | rtsig = atoi(name + 2); 39 | 40 | return rtsig + SIGRTMIN; 41 | } 42 | else { 43 | #endif 44 | int i; 45 | 46 | for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); ++i) { 47 | if (strcmp(sigs[i].name, name) == 0) { 48 | return sigs[i].sig; 49 | } 50 | } 51 | 52 | return -1; 53 | #ifdef SIGRTMIN 54 | } 55 | #endif 56 | } 57 | -------------------------------------------------------------------------------- /modules/luasocket/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevedonovan/luabuild/4c2afadb6184911e8fdcd0215f3dceede0aad180/modules/luasocket/LICENSE -------------------------------------------------------------------------------- /modules/luasocket/NEW: -------------------------------------------------------------------------------- 1 | What's New 2 | 3 | This is just a bug-fix/update release. 4 | 5 | * Improved: http.request() now supports deprecated HTTP/0.9 6 | servers (Florian Berger) 7 | * Fixed: could return "timedout" instead of "timeout" (Leo Leo) 8 | * Fixed: crash when reading '*a' on closed socket (Paul Ducklin); 9 | * Fixed: return values are consistent when reading from closed sockets; 10 | * Fixed: case sensitivity in headers of multipart messages in 11 | smtp.message() (Graham Henstridge); 12 | * Fixed a couple instances of error() being called instead of base.error(). These would cause an error when an error was reported. :) (Ketmar Dark); 13 | * Fixed: test script now uses pairs() iterator instead of the old 14 | Lua syntax (Robert Dodier). 15 | -------------------------------------------------------------------------------- /modules/luasocket/README: -------------------------------------------------------------------------------- 1 | This is a branch of LuaSocket 2.0.2 that contains patches by Wurldtech. 2 | 3 | 4 | This is the LuaSocket 2.0.2. It has been tested on WinXP, Mac OS X, 5 | and Linux. Please use the Lua mailing list to report any bugs 6 | (or "features") you encounter. 7 | 8 | Have fun, 9 | Diego Nehab. 10 | -------------------------------------------------------------------------------- /modules/luasocket/etc/b64.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to convert to and from Base64 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: b64.lua,v 1.8 2004/06/16 04:28:21 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local ltn12 = require("ltn12") 8 | local mime = require("mime") 9 | local source = ltn12.source.file(io.stdin) 10 | local sink = ltn12.sink.file(io.stdout) 11 | local convert 12 | if arg and arg[1] == '-d' then 13 | convert = mime.decode("base64") 14 | else 15 | local base64 = mime.encode("base64") 16 | local wrap = mime.wrap() 17 | convert = ltn12.filter.chain(base64, wrap) 18 | end 19 | sink = ltn12.sink.chain(convert, sink) 20 | ltn12.pump.all(source, sink) 21 | -------------------------------------------------------------------------------- /modules/luasocket/etc/check-memory.lua: -------------------------------------------------------------------------------- 1 | function load(s) 2 | collectgarbage() 3 | local a = gcinfo() 4 | _G[s] = require(s) 5 | collectgarbage() 6 | local b = gcinfo() 7 | print(s .. ":\t " .. (b-a) .. "k") 8 | end 9 | 10 | load("socket.url") 11 | load("ltn12") 12 | load("socket") 13 | load("mime") 14 | load("socket.tp") 15 | load("socket.smtp") 16 | load("socket.http") 17 | load("socket.ftp") 18 | -------------------------------------------------------------------------------- /modules/luasocket/etc/eol.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to adjust end of line markers. 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: eol.lua,v 1.8 2005/11/22 08:33:29 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local mime = require("mime") 8 | local ltn12 = require("ltn12") 9 | local marker = '\n' 10 | if arg and arg[1] == '-d' then marker = '\r\n' end 11 | local filter = mime.normalize(marker) 12 | local source = ltn12.source.chain(ltn12.source.file(io.stdin), filter) 13 | local sink = ltn12.sink.file(io.stdout) 14 | ltn12.pump.all(source, sink) 15 | -------------------------------------------------------------------------------- /modules/luasocket/etc/forward.lua: -------------------------------------------------------------------------------- 1 | -- load our favourite library 2 | local dispatch = require("dispatch") 3 | local handler = dispatch.newhandler() 4 | 5 | -- make sure the user knows how to invoke us 6 | if table.getn(arg) < 1 then 7 | print("Usage") 8 | print(" lua forward.lua ...") 9 | os.exit(1) 10 | end 11 | 12 | -- function to move data from one socket to the other 13 | local function move(foo, bar) 14 | local live 15 | while 1 do 16 | local data, error, partial = foo:receive(2048) 17 | live = data or error == "timeout" 18 | data = data or partial 19 | local result, error = bar:send(data) 20 | if not live or not result then 21 | foo:close() 22 | bar:close() 23 | break 24 | end 25 | end 26 | end 27 | 28 | -- for each tunnel, start a new server 29 | for i, v in ipairs(arg) do 30 | -- capture forwarding parameters 31 | local _, _, iport, ohost, oport = string.find(v, "([^:]+):([^:]+):([^:]+)") 32 | assert(iport, "invalid arguments") 33 | -- create our server socket 34 | local server = assert(handler.tcp()) 35 | assert(server:setoption("reuseaddr", true)) 36 | assert(server:bind("*", iport)) 37 | assert(server:listen(32)) 38 | -- handler for the server object loops accepting new connections 39 | handler:start(function() 40 | while 1 do 41 | local client = assert(server:accept()) 42 | assert(client:settimeout(0)) 43 | -- for each new connection, start a new client handler 44 | handler:start(function() 45 | -- handler tries to connect to peer 46 | local peer = assert(handler.tcp()) 47 | assert(peer:settimeout(0)) 48 | assert(peer:connect(ohost, oport)) 49 | -- if sucessful, starts a new handler to send data from 50 | -- client to peer 51 | handler:start(function() 52 | move(client, peer) 53 | end) 54 | -- afte starting new handler, enter in loop sending data from 55 | -- peer to client 56 | move(peer, client) 57 | end) 58 | end 59 | end) 60 | end 61 | 62 | -- simply loop stepping the server 63 | while 1 do 64 | handler:step() 65 | end 66 | -------------------------------------------------------------------------------- /modules/luasocket/etc/qp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Little program to convert to and from Quoted-Printable 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: qp.lua,v 1.5 2004/06/17 21:46:22 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local ltn12 = require("ltn12") 8 | local mime = require("mime") 9 | local convert 10 | arg = arg or {} 11 | local mode = arg and arg[1] or "-et" 12 | if mode == "-et" then 13 | local normalize = mime.normalize() 14 | local qp = mime.encode("quoted-printable") 15 | local wrap = mime.wrap("quoted-printable") 16 | convert = ltn12.filter.chain(normalize, qp, wrap) 17 | elseif mode == "-eb" then 18 | local qp = mime.encode("quoted-printable", "binary") 19 | local wrap = mime.wrap("quoted-printable") 20 | convert = ltn12.filter.chain(qp, wrap) 21 | else convert = mime.decode("quoted-printable") end 22 | local source = ltn12.source.chain(ltn12.source.file(io.stdin), convert) 23 | local sink = ltn12.sink.file(io.stdout) 24 | ltn12.pump.all(source, sink) 25 | -------------------------------------------------------------------------------- /modules/luasocket/samples/README: -------------------------------------------------------------------------------- 1 | This directory contains some sample programs using 2 | LuaSocket. This code is not supported. 3 | 4 | listener.lua -- socket to stdout 5 | talker.lua -- stdin to socket 6 | 7 | listener.lua and talker.lua are about the simplest 8 | applications you can write using LuaSocket. Run 9 | 10 | 'lua listener.lua' and 'lua talker.lua' 11 | 12 | on different terminals. Whatever you type on talk.lua will 13 | be printed by listen.lua. 14 | 15 | lpr.lua -- lpr client 16 | 17 | This is a cool program written by David Burgess to print 18 | files using the Line Printer Daemon protocol, widely used in 19 | Unix machines. It uses the lp.lua implementation, in the 20 | etc directory. Just run 'lua lpr.lua 21 | queue=' and the file will print! 22 | 23 | cddb.lua -- CDDB client 24 | 25 | This is the first try on a simple CDDB client. Not really 26 | useful, but one day it might become a module. 27 | 28 | daytimeclnt.lua -- day time client 29 | 30 | Just run the program to retrieve the hour and date in 31 | readable form from any server running an UDP daytime daemon. 32 | 33 | echoclnt.lua -- UDP echo client 34 | echosrvr.lua -- UDP echo server 35 | 36 | These are a UDP echo client/server pair. They work with 37 | other client and servers as well. 38 | 39 | tinyirc.lua -- irc like broadcast server 40 | 41 | This is a simple server that waits simultaneously on two 42 | server sockets for telnet connections. Everything it 43 | receives from the telnet clients is broadcasted to every 44 | other connected client. It tests the select function and 45 | shows how to create a simple server whith LuaSocket. Just 46 | run tinyirc.lua and then open as many telnet connections 47 | as you want to ports 8080 and 8081. 48 | 49 | Good luck, 50 | Diego. 51 | -------------------------------------------------------------------------------- /modules/luasocket/samples/cddb.lua: -------------------------------------------------------------------------------- 1 | local socket = require("socket") 2 | local http = require("socket.http") 3 | 4 | if not arg or not arg[1] or not arg[2] then 5 | print("luasocket cddb.lua []") 6 | os.exit(1) 7 | end 8 | 9 | local server = arg[3] or "http://freedb.freedb.org/~cddb/cddb.cgi" 10 | 11 | function parse(body) 12 | local lines = string.gfind(body, "(.-)\r\n") 13 | local status = lines() 14 | local code, message = socket.skip(2, string.find(status, "(%d%d%d) (.*)")) 15 | if tonumber(code) ~= 210 then 16 | return nil, code, message 17 | end 18 | local data = {} 19 | for l in lines do 20 | local c = string.sub(l, 1, 1) 21 | if c ~= '#' and c ~= '.' then 22 | local key, value = socket.skip(2, string.find(l, "(.-)=(.*)")) 23 | value = string.gsub(value, "\\n", "\n") 24 | value = string.gsub(value, "\\\\", "\\") 25 | value = string.gsub(value, "\\t", "\t") 26 | data[key] = value 27 | end 28 | end 29 | return data, code, message 30 | end 31 | 32 | local host = socket.dns.gethostname() 33 | local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6" 34 | local url = string.format(query, server, arg[1], arg[2], host) 35 | local body, headers, code = http.get(url) 36 | 37 | if code == 200 then 38 | local data, code, error = parse(body) 39 | if not data then 40 | print(error or code) 41 | else 42 | for i,v in pairs(data) do 43 | io.write(i, ': ', v, '\n') 44 | end 45 | end 46 | else print(error) end 47 | -------------------------------------------------------------------------------- /modules/luasocket/samples/daytimeclnt.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: daytime protocol client 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: daytimeclnt.lua,v 1.11 2004/06/21 06:07:57 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local socket = require"socket" 8 | host = host or "127.0.0.1" 9 | port = port or 13 10 | if arg then 11 | host = arg[1] or host 12 | port = arg[2] or port 13 | end 14 | host = socket.dns.toip(host) 15 | udp = socket.udp() 16 | print("Using host '" ..host.. "' and port " ..port.. "...") 17 | udp:setpeername(host, port) 18 | udp:settimeout(3) 19 | sent, err = udp:send("anything") 20 | if err then print(err) os.exit() end 21 | dgram, err = udp:receive() 22 | if not dgram then print(err) os.exit() end 23 | io.write(dgram) 24 | -------------------------------------------------------------------------------- /modules/luasocket/samples/echoclnt.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: echo protocol client 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: echoclnt.lua,v 1.10 2005/01/02 22:44:00 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local socket = require("socket") 8 | host = host or "localhost" 9 | port = port or 7 10 | if arg then 11 | host = arg[1] or host 12 | port = arg[2] or port 13 | end 14 | host = socket.dns.toip(host) 15 | udp = assert(socket.udp()) 16 | assert(udp:setpeername(host, port)) 17 | print("Using remote host '" ..host.. "' and port " .. port .. "...") 18 | while 1 do 19 | line = io.read() 20 | if not line or line == "" then os.exit() end 21 | assert(udp:send(line)) 22 | dgram = assert(udp:receive()) 23 | print(dgram) 24 | end 25 | -------------------------------------------------------------------------------- /modules/luasocket/samples/echosrvr.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- UDP sample: echo protocol server 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: echosrvr.lua,v 1.12 2005/11/22 08:33:29 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local socket = require("socket") 8 | host = host or "127.0.0.1" 9 | port = port or 7 10 | if arg then 11 | host = arg[1] or host 12 | port = arg[2] or port 13 | end 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") 15 | udp = assert(socket.udp()) 16 | assert(udp:setsockname(host, port)) 17 | assert(udp:settimeout(5)) 18 | ip, port = udp:getsockname() 19 | assert(ip, port) 20 | print("Waiting packets on " .. ip .. ":" .. port .. "...") 21 | while 1 do 22 | dgram, ip, port = udp:receivefrom() 23 | if dgram then 24 | print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) 25 | udp:sendto(dgram, ip, port) 26 | else 27 | print(ip) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/luasocket/samples/listener.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- TCP sample: Little program to dump lines received at a given port 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: listener.lua,v 1.11 2005/01/02 22:44:00 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local socket = require("socket") 8 | host = host or "*" 9 | port = port or 8080 10 | if arg then 11 | host = arg[1] or host 12 | port = arg[2] or port 13 | end 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") 15 | s = assert(socket.bind(host, port)) 16 | i, p = s:getsockname() 17 | assert(i, p) 18 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") 19 | c = assert(s:accept()) 20 | print("Connected. Here is the stuff:") 21 | l, e = c:receive() 22 | while not e do 23 | print(l) 24 | l, e = c:receive() 25 | end 26 | print(e) 27 | -------------------------------------------------------------------------------- /modules/luasocket/samples/lpr.lua: -------------------------------------------------------------------------------- 1 | local lp = require("socket.lp") 2 | 3 | local function usage() 4 | print('\nUsage: lua lpr.lua [filename] [keyword=val...]\n') 5 | print('Valid keywords are :') 6 | print( 7 | ' host=remote host or IP address (default "localhost")\n' .. 8 | ' queue=remote queue or printer name (default "printer")\n' .. 9 | ' port=remote port number (default 515)\n' .. 10 | ' user=sending user name\n' .. 11 | ' format=["binary" | "text" | "ps" | "pr" | "fortran"] (default "binary")\n' .. 12 | ' banner=true|false\n' .. 13 | ' indent=number of columns to indent\n' .. 14 | ' mail=email of address to notify when print is complete\n' .. 15 | ' title=title to use for "pr" format\n' .. 16 | ' width=width for "text" or "pr" formats\n' .. 17 | ' class=\n' .. 18 | ' job=\n' .. 19 | ' name=\n' .. 20 | ' localbind=true|false\n' 21 | ) 22 | return nil 23 | end 24 | 25 | if not arg or not arg[1] then 26 | return usage() 27 | end 28 | 29 | do 30 | local opt = {} 31 | local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)" 32 | for i = 2, table.getn(arg), 1 do 33 | string.gsub(arg[i], pat, function(name, value) opt[name] = value end) 34 | end 35 | if not arg[2] then 36 | return usage() 37 | end 38 | if arg[1] ~= "query" then 39 | opt.file = arg[1] 40 | r,e=lp.send(opt) 41 | io.stdout:write(tostring(r or e),'\n') 42 | else 43 | r,e=lp.query(opt) 44 | io.stdout:write(tostring(r or e), '\n') 45 | end 46 | end 47 | 48 | -- trivial tests 49 | --lua lp.lua lp.lua queue=default host=localhost 50 | --lua lp.lua lp.lua queue=default host=localhost format=binary localbind=1 51 | --lua lp.lua query queue=default host=localhost 52 | -------------------------------------------------------------------------------- /modules/luasocket/samples/talker.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- TCP sample: Little program to send text lines to a given host/port 3 | -- LuaSocket sample files 4 | -- Author: Diego Nehab 5 | -- RCS ID: $Id: talker.lua,v 1.9 2005/01/02 22:44:00 diego Exp $ 6 | ----------------------------------------------------------------------------- 7 | local socket = require("socket") 8 | host = host or "localhost" 9 | port = port or 8080 10 | if arg then 11 | host = arg[1] or host 12 | port = arg[2] or port 13 | end 14 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") 15 | c = assert(socket.connect(host, port)) 16 | print("Connected! Please type stuff (empty line to stop):") 17 | l = io.read() 18 | while l and l ~= "" and not e do 19 | assert(c:send(l .. "\n")) 20 | l = io.read() 21 | end 22 | -------------------------------------------------------------------------------- /modules/luasocket/src/auxiliar.h: -------------------------------------------------------------------------------- 1 | #ifndef AUXILIAR_H 2 | #define AUXILIAR_H 3 | /*=========================================================================*\ 4 | * Auxiliar routines for class hierarchy manipulation 5 | * LuaSocket toolkit (but completely independent of other LuaSocket modules) 6 | * 7 | * A LuaSocket class is a name associated with Lua metatables. A LuaSocket 8 | * group is a name associated with a class. A class can belong to any number 9 | * of groups. This module provides the functionality to: 10 | * 11 | * - create new classes 12 | * - add classes to groups 13 | * - set the class of objects 14 | * - check if an object belongs to a given class or group 15 | * - get the userdata associated to objects 16 | * - print objects in a pretty way 17 | * 18 | * LuaSocket class names follow the convention {}. Modules 19 | * can define any number of classes and groups. The module tcp.c, for 20 | * example, defines the classes tcp{master}, tcp{client} and tcp{server} and 21 | * the groups tcp{client,server} and tcp{any}. Module functions can then 22 | * perform type-checking on their arguments by either class or group. 23 | * 24 | * LuaSocket metatables define the __index metamethod as being a table. This 25 | * table has one field for each method supported by the class, and a field 26 | * "class" with the class name. 27 | * 28 | * The mapping from class name to the corresponding metatable and the 29 | * reverse mapping are done using lauxlib. 30 | \*=========================================================================*/ 31 | 32 | #include "lua.h" 33 | #include "lauxlib.h" 34 | 35 | int auxiliar_open(lua_State *L); 36 | void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); 37 | void auxiliar_add2group(lua_State *L, const char *classname, const char *group); 38 | void auxiliar_setclass(lua_State *L, const char *classname, int objidx); 39 | void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); 40 | void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); 41 | void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); 42 | void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); 43 | int auxiliar_checkboolean(lua_State *L, int objidx); 44 | int auxiliar_tostring(lua_State *L); 45 | int auxiliar_typeerror(lua_State *L, int narg, const char *tname); 46 | 47 | #endif /* AUXILIAR_H */ 48 | -------------------------------------------------------------------------------- /modules/luasocket/src/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUF_H 2 | #define BUF_H 3 | /*=========================================================================*\ 4 | * Input/Output interface for Lua programs 5 | * LuaSocket toolkit 6 | * 7 | * Line patterns require buffering. Reading one character at a time involves 8 | * too many system calls and is very slow. This module implements the 9 | * LuaSocket interface for input/output on connected objects, as seen by 10 | * Lua programs. 11 | * 12 | * Input is buffered. Output is *not* buffered because there was no simple 13 | * way of making sure the buffered output data would ever be sent. 14 | * 15 | * The module is built on top of the I/O abstraction defined in io.h and the 16 | * timeout management is done with the timeout.h interface. 17 | \*=========================================================================*/ 18 | #include "lua.h" 19 | 20 | #include "io.h" 21 | #include "timeout.h" 22 | 23 | /* buffer size in bytes */ 24 | #define BUF_SIZE 8192 25 | 26 | /* buffer control structure */ 27 | typedef struct t_buffer_ { 28 | double birthday; /* throttle support info: creation time, */ 29 | size_t sent, received; /* bytes sent, and bytes received */ 30 | p_io io; /* IO driver used for this buffer */ 31 | p_timeout tm; /* timeout management for this buffer */ 32 | size_t first, last; /* index of first and last bytes of stored data */ 33 | char data[BUF_SIZE]; /* storage space for buffer data */ 34 | } t_buffer; 35 | typedef t_buffer *p_buffer; 36 | 37 | int buffer_open(lua_State *L); 38 | void buffer_init(p_buffer buf, p_io io, p_timeout tm); 39 | int buffer_meth_send(lua_State *L, p_buffer buf); 40 | int buffer_meth_receive(lua_State *L, p_buffer buf); 41 | int buffer_meth_getstats(lua_State *L, p_buffer buf); 42 | int buffer_meth_setstats(lua_State *L, p_buffer buf); 43 | int buffer_isempty(p_buffer buf); 44 | 45 | #endif /* BUF_H */ 46 | -------------------------------------------------------------------------------- /modules/luasocket/src/except.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPT_H 2 | #define EXCEPT_H 3 | /*=========================================================================*\ 4 | * Exception control 5 | * LuaSocket toolkit (but completely independent from other modules) 6 | * 7 | * This provides support for simple exceptions in Lua. During the 8 | * development of the HTTP/FTP/SMTP support, it became aparent that 9 | * error checking was taking a substantial amount of the coding. These 10 | * function greatly simplify the task of checking errors. 11 | * 12 | * The main idea is that functions should return nil as its first return 13 | * value when it finds an error, and return an error message (or value) 14 | * following nil. In case of success, as long as the first value is not nil, 15 | * the other values don't matter. 16 | * 17 | * The idea is to nest function calls with the "try" function. This function 18 | * checks the first value, and calls "error" on the second if the first is 19 | * nil. Otherwise, it returns all values it received. 20 | * 21 | * The protect function returns a new function that behaves exactly like the 22 | * function it receives, but the new function doesn't throw exceptions: it 23 | * returns nil followed by the error message instead. 24 | * 25 | * With these two function, it's easy to write functions that throw 26 | * exceptions on error, but that don't interrupt the user script. 27 | \*=========================================================================*/ 28 | 29 | #include "lua.h" 30 | 31 | int except_open(lua_State *L); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /modules/luasocket/src/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef INET_H 2 | #define INET_H 3 | /*=========================================================================*\ 4 | * Internet domain functions 5 | * LuaSocket toolkit 6 | * 7 | * This module implements the creation and connection of internet domain 8 | * sockets, on top of the socket.h interface, and the interface of with the 9 | * resolver. 10 | * 11 | * The function inet_aton is provided for the platforms where it is not 12 | * available. The module also implements the interface of the internet 13 | * getpeername and getsockname functions as seen by Lua programs. 14 | * 15 | * The Lua functions toip and tohostname are also implemented here. 16 | \*=========================================================================*/ 17 | #include "lua.h" 18 | #include "socket.h" 19 | #include "timeout.h" 20 | 21 | #ifdef _WIN32 22 | #define INET_ATON 23 | #endif 24 | 25 | int inet_open(lua_State *L); 26 | 27 | const char *inet_trycreate(p_socket ps, int family, int type); 28 | const char *inet_tryconnect(p_socket ps, const char *address, 29 | const char *serv, p_timeout tm, struct addrinfo *connecthints); 30 | const char *inet_trybind(p_socket ps, const char *address, const char *serv, 31 | struct addrinfo *bindhints); 32 | const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); 33 | const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); 34 | 35 | int inet_meth_getpeername(lua_State *L, p_socket ps, int family); 36 | int inet_meth_getsockname(lua_State *L, p_socket ps, int family); 37 | 38 | int inet_optfamily(lua_State* L, int narg, const char* def); 39 | int inet_optsocktype(lua_State* L, int narg, const char* def); 40 | 41 | #ifdef INET_ATON 42 | int inet_aton(const char *cp, struct in_addr *inp); 43 | #endif 44 | 45 | #endif /* INET_H */ 46 | -------------------------------------------------------------------------------- /modules/luasocket/src/io.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Input/Output abstraction 3 | * LuaSocket toolkit 4 | \*=========================================================================*/ 5 | #include "io.h" 6 | 7 | /*=========================================================================*\ 8 | * Exported functions 9 | \*=========================================================================*/ 10 | /*-------------------------------------------------------------------------*\ 11 | * Initializes C structure 12 | \*-------------------------------------------------------------------------*/ 13 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { 14 | io->send = send; 15 | io->recv = recv; 16 | io->error = error; 17 | io->ctx = ctx; 18 | } 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * I/O error strings 22 | \*-------------------------------------------------------------------------*/ 23 | const char *io_strerror(int err) { 24 | switch (err) { 25 | case IO_DONE: return NULL; 26 | case IO_CLOSED: return "closed"; 27 | case IO_TIMEOUT: return "timeout"; 28 | default: return "unknown error"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /modules/luasocket/src/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | /*=========================================================================*\ 4 | * Input/Output abstraction 5 | * LuaSocket toolkit 6 | * 7 | * This module defines the interface that LuaSocket expects from the 8 | * transport layer for streamed input/output. The idea is that if any 9 | * transport implements this interface, then the buffer.c functions 10 | * automatically work on it. 11 | * 12 | * The module socket.h implements this interface, and thus the module tcp.h 13 | * is very simple. 14 | \*=========================================================================*/ 15 | #include 16 | #include "lua.h" 17 | 18 | #include "timeout.h" 19 | 20 | /* IO error codes */ 21 | enum { 22 | IO_DONE = 0, /* operation completed successfully */ 23 | IO_TIMEOUT = -1, /* operation timed out */ 24 | IO_CLOSED = -2, /* the connection has been closed */ 25 | IO_UNKNOWN = -3 26 | }; 27 | 28 | /* interface to error message function */ 29 | typedef const char *(*p_error) ( 30 | void *ctx, /* context needed by send */ 31 | int err /* error code */ 32 | ); 33 | 34 | /* interface to send function */ 35 | typedef int (*p_send) ( 36 | void *ctx, /* context needed by send */ 37 | const char *data, /* pointer to buffer with data to send */ 38 | size_t count, /* number of bytes to send from buffer */ 39 | size_t *sent, /* number of bytes sent uppon return */ 40 | p_timeout tm /* timeout control */ 41 | ); 42 | 43 | /* interface to recv function */ 44 | typedef int (*p_recv) ( 45 | void *ctx, /* context needed by recv */ 46 | char *data, /* pointer to buffer where data will be writen */ 47 | size_t count, /* number of bytes to receive into buffer */ 48 | size_t *got, /* number of bytes received uppon return */ 49 | p_timeout tm /* timeout control */ 50 | ); 51 | 52 | /* IO driver definition */ 53 | typedef struct t_io_ { 54 | void *ctx; /* context needed by send/recv */ 55 | p_send send; /* send function pointer */ 56 | p_recv recv; /* receive function pointer */ 57 | p_error error; /* strerror function */ 58 | } t_io; 59 | typedef t_io *p_io; 60 | 61 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); 62 | const char *io_strerror(int err); 63 | 64 | #endif /* IO_H */ 65 | 66 | -------------------------------------------------------------------------------- /modules/luasocket/src/luasocket.h: -------------------------------------------------------------------------------- 1 | #ifndef LUASOCKET_H 2 | #define LUASOCKET_H 3 | /*=========================================================================*\ 4 | * LuaSocket toolkit 5 | * Networking support for the Lua language 6 | * Diego Nehab 7 | * 9/11/1999 8 | \*=========================================================================*/ 9 | #include "lua.h" 10 | 11 | /*-------------------------------------------------------------------------*\ 12 | * Current socket library version 13 | \*-------------------------------------------------------------------------*/ 14 | #define LUASOCKET_VERSION "LuaSocket 2.1-rc1 (Prosody)" 15 | #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2012 Diego Nehab" 16 | #define LUASOCKET_AUTHORS "Diego Nehab" 17 | 18 | /*-------------------------------------------------------------------------*\ 19 | * This macro prefixes all exported API functions 20 | \*-------------------------------------------------------------------------*/ 21 | #ifndef LUASOCKET_API 22 | #define LUASOCKET_API extern 23 | #endif 24 | 25 | /*-------------------------------------------------------------------------*\ 26 | * Initializes the library. 27 | \*-------------------------------------------------------------------------*/ 28 | LUASOCKET_API int luaopen_socket_core(lua_State *L); 29 | 30 | #endif /* LUASOCKET_H */ 31 | -------------------------------------------------------------------------------- /modules/luasocket/src/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef MIME_H 2 | #define MIME_H 3 | /*=========================================================================*\ 4 | * Core MIME support 5 | * LuaSocket toolkit 6 | * 7 | * This module provides functions to implement transfer content encodings 8 | * and formatting conforming to RFC 2045. It is used by mime.lua, which 9 | * provide a higher level interface to this functionality. 10 | \*=========================================================================*/ 11 | #include "lua.h" 12 | 13 | /*-------------------------------------------------------------------------*\ 14 | * Current MIME library version 15 | \*-------------------------------------------------------------------------*/ 16 | #define MIME_VERSION "MIME 1.0.3-rc1" 17 | #define MIME_COPYRIGHT "Copyright (C) 2004-2012 Diego Nehab" 18 | #define MIME_AUTHORS "Diego Nehab" 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * This macro prefixes all exported API functions 22 | \*-------------------------------------------------------------------------*/ 23 | #ifndef MIME_API 24 | #define MIME_API extern 25 | #endif 26 | 27 | MIME_API int luaopen_mime_core(lua_State *L); 28 | 29 | #endif /* MIME_H */ 30 | -------------------------------------------------------------------------------- /modules/luasocket/src/options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIONS_H 2 | #define OPTIONS_H 3 | /*=========================================================================*\ 4 | * Common option interface 5 | * LuaSocket toolkit 6 | * 7 | * This module provides a common interface to socket options, used mainly by 8 | * modules UDP and TCP. 9 | \*=========================================================================*/ 10 | 11 | #include "lua.h" 12 | #include "socket.h" 13 | 14 | /* option registry */ 15 | typedef struct t_opt { 16 | const char *name; 17 | int (*func)(lua_State *L, p_socket ps); 18 | } t_opt; 19 | typedef t_opt *p_opt; 20 | 21 | /* supported options for setoption */ 22 | int opt_set_dontroute(lua_State *L, p_socket ps); 23 | int opt_set_broadcast(lua_State *L, p_socket ps); 24 | int opt_set_reuseaddr(lua_State *L, p_socket ps); 25 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps); 26 | int opt_set_keepalive(lua_State *L, p_socket ps); 27 | int opt_set_linger(lua_State *L, p_socket ps); 28 | int opt_set_reuseaddr(lua_State *L, p_socket ps); 29 | int opt_set_reuseport(lua_State *L, p_socket ps); 30 | int opt_set_ip_multicast_if(lua_State *L, p_socket ps); 31 | int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps); 32 | int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); 33 | int opt_set_ip_add_membership(lua_State *L, p_socket ps); 34 | int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); 35 | int opt_set_ip6_v6only(lua_State *L, p_socket ps); 36 | 37 | /* supported options for getoption */ 38 | int opt_get_reuseaddr(lua_State *L, p_socket ps); 39 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); 40 | int opt_get_keepalive(lua_State *L, p_socket ps); 41 | int opt_get_linger(lua_State *L, p_socket ps); 42 | int opt_get_reuseaddr(lua_State *L, p_socket ps); 43 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); 44 | int opt_get_ip_multicast_if(lua_State *L, p_socket ps); 45 | 46 | /* invokes the appropriate option handler */ 47 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); 48 | int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /modules/luasocket/src/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | /*=========================================================================*\ 4 | * Select implementation 5 | * LuaSocket toolkit 6 | * 7 | * Each object that can be passed to the select function has to export 8 | * method getfd() which returns the descriptor to be passed to the 9 | * underlying select function. Another method, dirty(), should return 10 | * true if there is data ready for reading (required for buffered input). 11 | \*=========================================================================*/ 12 | 13 | int select_open(lua_State *L); 14 | 15 | #endif /* SELECT_H */ 16 | -------------------------------------------------------------------------------- /modules/luasocket/src/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_H 2 | #define TCP_H 3 | /*=========================================================================*\ 4 | * TCP object 5 | * LuaSocket toolkit 6 | * 7 | * The tcp.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created tcp object, that has not been bound or connected. Server 13 | * objects are tcp objects bound to some local address. Client objects are 14 | * tcp objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | \*=========================================================================*/ 17 | #include "lua.h" 18 | 19 | #include "buffer.h" 20 | #include "timeout.h" 21 | #include "socket.h" 22 | 23 | typedef struct t_tcp_ { 24 | t_socket sock; 25 | t_io io; 26 | t_buffer buf; 27 | t_timeout tm; 28 | int family; 29 | } t_tcp; 30 | 31 | typedef t_tcp *p_tcp; 32 | 33 | int tcp_open(lua_State *L); 34 | 35 | #endif /* TCP_H */ 36 | -------------------------------------------------------------------------------- /modules/luasocket/src/test-driver.lua: -------------------------------------------------------------------------------- 1 | local lua = arg[-1] 2 | io.stderr:write '----LuaSocket test: should take about a minute\n' 3 | if package.config:match '^/' then -- i.e. Unix... 4 | os.execute (lua..' ../test/testsrvr.lua &') 5 | else 6 | os.execute('start '..lua..' ../test/testsrvr.lua') 7 | end 8 | os.execute (lua..' ../test/testclnt.lua') 9 | 10 | -------------------------------------------------------------------------------- /modules/luasocket/src/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEOUT_H 2 | #define TIMEOUT_H 3 | /*=========================================================================*\ 4 | * Timeout management functions 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | #include "lua.h" 8 | 9 | /* timeout control structure */ 10 | typedef struct t_timeout_ { 11 | double block; /* maximum time for blocking calls */ 12 | double total; /* total number of miliseconds for operation */ 13 | double start; /* time of start of operation */ 14 | } t_timeout; 15 | typedef t_timeout *p_timeout; 16 | 17 | int timeout_open(lua_State *L); 18 | void timeout_init(p_timeout tm, double block, double total); 19 | double timeout_get(p_timeout tm); 20 | double timeout_getretry(p_timeout tm); 21 | p_timeout timeout_markstart(p_timeout tm); 22 | double timeout_getstart(p_timeout tm); 23 | double timeout_gettime(void); 24 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); 25 | 26 | #define timeout_iszero(tm) ((tm)->block == 0.0) 27 | 28 | #endif /* TIMEOUT_H */ 29 | -------------------------------------------------------------------------------- /modules/luasocket/src/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef UDP_H 2 | #define UDP_H 3 | /*=========================================================================*\ 4 | * UDP object 5 | * LuaSocket toolkit 6 | * 7 | * The udp.h module provides LuaSocket with support for UDP protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. UDP objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | \*=========================================================================*/ 15 | #include "lua.h" 16 | 17 | #include "timeout.h" 18 | #include "socket.h" 19 | 20 | /* can't be larger than wsocket.c MAXCHUNK!!! */ 21 | #define UDP_DATAGRAMSIZE 8192 22 | 23 | typedef struct t_udp_ { 24 | t_socket sock; 25 | t_timeout tm; 26 | int family; 27 | } t_udp; 28 | typedef t_udp *p_udp; 29 | 30 | int udp_open(lua_State *L); 31 | 32 | #endif /* UDP_H */ 33 | -------------------------------------------------------------------------------- /modules/luasocket/src/unix.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIX_H 2 | #define UNIX_H 3 | /*=========================================================================*\ 4 | * Unix domain object 5 | * LuaSocket toolkit 6 | * 7 | * This module is just an example of how to extend LuaSocket with a new 8 | * domain. 9 | \*=========================================================================*/ 10 | #include "lua.h" 11 | 12 | #include "buffer.h" 13 | #include "timeout.h" 14 | #include "socket.h" 15 | 16 | typedef struct t_unix_ { 17 | t_socket sock; 18 | t_io io; 19 | t_buffer buf; 20 | t_timeout tm; 21 | } t_unix; 22 | typedef t_unix *p_unix; 23 | 24 | LUASOCKET_API int luaopen_socket_unix(lua_State *L); 25 | 26 | #endif /* UNIX_H */ 27 | -------------------------------------------------------------------------------- /modules/luasocket/src/usocket.h: -------------------------------------------------------------------------------- 1 | #ifndef USOCKET_H 2 | #define USOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Unix 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | 8 | /*=========================================================================*\ 9 | * BSD include files 10 | \*=========================================================================*/ 11 | /* error codes */ 12 | #include 13 | /* close function */ 14 | #include 15 | /* fnctnl function and associated constants */ 16 | #include 17 | /* struct sockaddr */ 18 | #include 19 | /* socket function */ 20 | #include 21 | /* struct timeval */ 22 | #include 23 | /* gethostbyname and gethostbyaddr functions */ 24 | #include 25 | /* sigpipe handling */ 26 | #include 27 | /* IP stuff*/ 28 | #include 29 | #include 30 | /* TCP options (nagle algorithm disable) */ 31 | #include 32 | 33 | #ifndef SO_REUSEPORT 34 | #define SO_REUSEPORT SO_REUSEADDR 35 | #endif 36 | 37 | typedef int t_socket; 38 | typedef t_socket *p_socket; 39 | typedef struct sockaddr_storage t_sockaddr_storage; 40 | 41 | #define SOCKET_INVALID (-1) 42 | 43 | #endif /* USOCKET_H */ 44 | -------------------------------------------------------------------------------- /modules/luasocket/src/wsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef WSOCKET_H 2 | #define WSOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Win32 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | 8 | /*=========================================================================*\ 9 | * WinSock include files 10 | \*=========================================================================*/ 11 | #include 12 | #include 13 | 14 | typedef int socklen_t; 15 | typedef SOCKADDR_STORAGE t_sockaddr_storage; 16 | typedef SOCKET t_socket; 17 | typedef t_socket *p_socket; 18 | 19 | #define SOCKET_INVALID (INVALID_SOCKET) 20 | 21 | #ifndef SO_REUSEPORT 22 | #define SO_REUSEPORT SO_REUSEADDR 23 | #endif 24 | 25 | #endif /* WSOCKET_H */ 26 | -------------------------------------------------------------------------------- /modules/luasocket/test/README: -------------------------------------------------------------------------------- 1 | This provides the automated test scripts used to make sure the library 2 | is working properly. 3 | 4 | The files provided are: 5 | 6 | testsrvr.lua -- test server 7 | testclnt.lua -- test client 8 | 9 | To run these tests, just run lua on the server and then on the client. 10 | 11 | Good luck, 12 | Diego. 13 | -------------------------------------------------------------------------------- /modules/luasocket/test/driver.lua: -------------------------------------------------------------------------------- 1 | local lua = arg[-1] 2 | io.stderr:write '----LuaSocket test: should take about a minute\n' 3 | if package.config:match '^/' then -- i.e. Unix... 4 | os.execute (lua..' testsrvr.lua &') 5 | else 6 | os.execute('start '..lua..' testsrvr.lua') 7 | end 8 | os.execute (lua..' testclnt.lua') 9 | 10 | -------------------------------------------------------------------------------- /modules/luasocket/test/find-connect-limit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | --[[ 3 | Find out how many TCP connections we can make. 4 | 5 | Use ulimit to increase the max number of descriptors: 6 | 7 | ulimit -n 10000 8 | ulimit -n 9 | 10 | You'll probably need to be root to do this. 11 | ]] 12 | 13 | require "socket" 14 | 15 | host = arg[1] or "google.com" 16 | port = arg[2] or 80 17 | 18 | connections = {} 19 | 20 | repeat 21 | c = assert(socket.connect(hostip or host, 80)) 22 | table.insert(connections, c) 23 | 24 | if not hostip then 25 | hostip = c:getpeername() 26 | print("resolved", host, "to", hostip) 27 | end 28 | 29 | print("connection #", #connections, c, "fd", c:getfd()) 30 | 31 | until false 32 | 33 | -------------------------------------------------------------------------------- /modules/luasocket/test/tcp-getoptions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | require"socket" 4 | 5 | port = 8765 6 | 7 | function options(o) 8 | print("options for", o) 9 | 10 | for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do 11 | print("getoption", opt, o:getoption(opt)) 12 | end 13 | 14 | print("getoption", "linger", 15 | "on", o:getoption("linger").on, 16 | "timeout", o:getoption("linger").timeout) 17 | end 18 | 19 | local m = socket.tcp() 20 | 21 | options(m) 22 | 23 | assert(m:bind("*", port)) 24 | assert(m:listen()) 25 | 26 | options(m) 27 | 28 | m:close() 29 | 30 | local m = socket.bind("*", port) 31 | 32 | options(m) 33 | 34 | local c = socket.connect("localhost", port) 35 | 36 | options(c) 37 | 38 | local s = m:accept() 39 | 40 | options(s) 41 | 42 | -------------------------------------------------------------------------------- /modules/luasocket/test/testsrvr.lua: -------------------------------------------------------------------------------- 1 | socket = require("socket") 2 | host = host or "127.0.0.1" 3 | port = port or "8443" 4 | server = assert(socket.bind(host, port)) 5 | loadstring = loadstring or load -- Lua 5.2 compat 6 | ack = "\n"; 7 | while 1 do 8 | print("server: waiting for client connection..."); 9 | control = assert(server:accept()); 10 | while 1 do 11 | command, emsg = control:receive(); 12 | if emsg == "closed" then 13 | control:close() 14 | break 15 | end 16 | if command == 'quit' then 17 | control:close() 18 | print 'shutting down server' 19 | return 20 | end 21 | assert(command, emsg) 22 | assert(control:send(ack)); 23 | print(command); 24 | (loadstring(command))(); 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /modules/luasocket/test/testsupport.lua: -------------------------------------------------------------------------------- 1 | function readfile(name) 2 | local f = io.open(name, "rb") 3 | if not f then return nil end 4 | local s = f:read("*a") 5 | f:close() 6 | return s 7 | end 8 | 9 | function similar(s1, s2) 10 | return string.lower(string.gsub(s1 or "", "%s", "")) == 11 | string.lower(string.gsub(s2 or "", "%s", "")) 12 | end 13 | 14 | function fail(msg) 15 | msg = msg or "failed" 16 | error(msg, 2) 17 | end 18 | 19 | function compare(input, output) 20 | local original = readfile(input) 21 | local recovered = readfile(output) 22 | if original ~= recovered then fail("comparison failed") 23 | else print("ok") end 24 | end 25 | 26 | local G = _G 27 | local set = rawset 28 | local warn = print 29 | 30 | local setglobal = function(table, key, value) 31 | warn("changed " .. key) 32 | set(table, key, value) 33 | end 34 | 35 | setmetatable(G, { 36 | __newindex = setglobal 37 | }) 38 | -------------------------------------------------------------------------------- /modules/luasocket/test/udp-zero-length-send: -------------------------------------------------------------------------------- 1 | #!/usr/bin/lua 2 | 3 | --[[ 4 | Show that luasocket returns an error message on zero-length UDP sends, 5 | even though the send is valid, and in fact the UDP packet is sent 6 | to the peer: 7 | 8 | % sudo tcpdump -i lo -n 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 12 | 13 | ]] 14 | 15 | require"socket" 16 | 17 | s = assert(socket.udp()) 18 | r = assert(socket.udp()) 19 | assert(r:setsockname("*", 5432)) 20 | assert(s:setpeername("127.0.0.1", 5432)) 21 | 22 | ssz, emsg = s:send("") 23 | 24 | print(ssz == 0 and "OK" or "FAIL",[[send:("")]], ssz, emsg) 25 | 26 | -------------------------------------------------------------------------------- /modules/luasocket/test/udp-zero-length-send-recv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/lua 2 | 3 | --[[ 4 | Show that luasocket returns an error message on zero-length UDP sends, 5 | even though the send is valid, and in fact the UDP packet is sent 6 | to the peer: 7 | 8 | % sudo tcpdump -i lo -n 9 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode 10 | listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes 11 | 13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0 12 | 13 | ]] 14 | 15 | require"socket" 16 | 17 | s = assert(socket.udp()) 18 | r = assert(socket.udp()) 19 | assert(r:setsockname("*", 5432)) 20 | assert(s:setpeername("127.0.0.1", 5432)) 21 | 22 | ok, emsg = s:send("") 23 | if ok ~= 0 then 24 | print("send of zero failed with:", ok, emsg) 25 | end 26 | 27 | assert(r:settimeout(2)) 28 | 29 | ok, emsg = r:receive() 30 | 31 | if not ok or string.len(ok) ~= 0 then 32 | print("fail - receive of zero failed with:", ok, emsg) 33 | os.exit(1) 34 | end 35 | 36 | print"ok" 37 | 38 | -------------------------------------------------------------------------------- /modules/luasql.odbc.lake: -------------------------------------------------------------------------------- 1 | local defines 2 | if not WINDOWS then 3 | if not find.include_path 'sql.h' then 4 | quit("luasql-odbc: cannot find sql.h; need to install unixodbc-dev") 5 | end 6 | defines = 'UNIXODBC' 7 | -- otherwise, if using Informix, 8 | -- defines = 'INFORMIX' 9 | end 10 | 11 | return luabuild.library{'luasql/odbc', 12 | src='luasql ls_odbc', 13 | llua = 'luasql.odbc', 14 | libs ='odbc32', 15 | defines = defines, 16 | } 17 | -------------------------------------------------------------------------------- /modules/luasql/README: -------------------------------------------------------------------------------- 1 | LuaSQL 2.1 2 | http://www.keplerproject.org/luasql/ 3 | 4 | LuaSQL is a simple interface from Lua to a DBMS. It enables a Lua program to: 5 | 6 | * Connect to ODBC, ADO, Oracle, MySQL, SQLite and PostgreSQL databases; 7 | * Execute arbitrary SQL statements; 8 | * Retrieve results in a row-by-row cursor fashion. 9 | 10 | LuaSQL is free software and uses the same license as Lua 5.1. 11 | 12 | 13 | Source code for LuaSQL can be downloaded from the LuaForge page. 14 | 15 | If you are using LuaBinaries a Windows binary version of LuaSQL can be found at the same LuaForge page. 16 | 17 | LuaSQL 2.1.1 [29/Oct/2007] 18 | * Fixed a bug in the SQLite3 error handling (patch by David Burgess) 19 | * Fixed bug [#1834] for SQLite 3 (found by Savin Zlobec, patch by Marc Nijdam) 20 | * Fixed bug [#1770] for SQLite 3 (found by Enrico Tassi, patch by Marc Nijdam) -------------------------------------------------------------------------------- /modules/luasql/example.lua: -------------------------------------------------------------------------------- 1 | local sql = require 'luasql.odbc' 2 | local env = sql.odbc() 3 | local con = env:connect 'AURA' 4 | local cur = con:execute 'SELECT EventID FROM [Event Summaries]' 5 | local row = cur:fetch({},'a') 6 | while row do 7 | print(row.EventID) 8 | row = cur:fetch(row,'a') 9 | end 10 | cur:close() 11 | con:close() 12 | env:close() 13 | -------------------------------------------------------------------------------- /modules/luasql/src/luasql.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: luasql.h,v 1.12 2009/02/07 23:16:23 tomas Exp $ 3 | ** See Copyright Notice in license.html 4 | */ 5 | 6 | #ifndef _LUASQL_ 7 | #define _LUASQL_ 8 | 9 | #ifndef LUASQL_API 10 | #define LUASQL_API 11 | #endif 12 | 13 | #if !defined LUA_VERSION_NUM 14 | /* Lua 5.0 */ 15 | #define luaL_Reg luaL_reg 16 | 17 | #define lua_pushinteger(L, n) \ 18 | lua_pushnumber(L, (lua_Number)n) 19 | #endif 20 | 21 | #define LUASQL_PREFIX "LuaSQL: " 22 | #define LUASQL_TABLENAME "luasql" 23 | #define LUASQL_ENVIRONMENT "Each driver must have an environment metatable" 24 | #define LUASQL_CONNECTION "Each driver must have a connection metatable" 25 | #define LUASQL_CURSOR "Each driver must have a cursor metatable" 26 | 27 | LUASQL_API int luasql_faildirect (lua_State *L, const char *err); 28 | LUASQL_API int luasql_failmsg (lua_State *L, const char *err, const char *m); 29 | LUASQL_API int luasql_createmeta (lua_State *L, const char *name, const luaL_Reg *methods); 30 | LUASQL_API void luasql_setmeta (lua_State *L, const char *name); 31 | LUASQL_API void luasql_set_info (lua_State *L); 32 | 33 | #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 34 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /modules/lxp.lake: -------------------------------------------------------------------------------- 1 | if not find.include_path 'expat.h' then 2 | quit("luaexpat: cannot find expat.h; need to install libexpat-dev") 3 | end 4 | 5 | luabuild.lua('lxp/lom.lua','lxp') 6 | luabuild.test 'test-driver.lua' 7 | 8 | return luabuild.library{'lxp',src='lxplib',libs='expat'} 9 | -------------------------------------------------------------------------------- /modules/manifest: -------------------------------------------------------------------------------- 1 | lpeg = "lpeg" 2 | lfs = "lfs" 3 | complex = "complex" 4 | winapi = "winapi-1.4" 5 | M["socket.core"] = "luasocket/src" 6 | M["mime.core"] = "luasocket/src" 7 | posix_c = "luaposix" 8 | curses_c = "luaposix" 9 | ltcl = "ltcltk-0.9-2" 10 | lsqlite3 = "lsqlite3_svn08" 11 | linenoise = "lua-linenoise" 12 | lxp = "luaexpat/src" 13 | struct = "struct" 14 | inotify = "linotify" 15 | M["luasql.odbc"] = "luasql/src" 16 | 17 | bc="bc" 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /modules/mime.core.lake: -------------------------------------------------------------------------------- 1 | ----- building mime/core ----- 2 | 3 | luabuild.lua('mime') 4 | 5 | return luabuild.library {'mime/core',src='mime'} 6 | -------------------------------------------------------------------------------- /modules/posix_c.lake: -------------------------------------------------------------------------------- 1 | local libs 2 | local cfg = {HAVE_CRYPT=true, HAVE_CRYPT_H=true, VERSION = "5.1.20"} 3 | if PLAT~='Darwin' then 4 | libs = 'crypt ' 5 | else 6 | cfg.HAVE_CRYPT_H = false 7 | end 8 | if PLAT=='Linux' then 9 | libs = libs .. 'rt' 10 | end 11 | 12 | cfg.HAVE_SYS_STATVFS_H = find.include_path 'sys/statvfs.h' ~= nil 13 | cfg.HAVE_STATVFS = cfg.HAVE_SYS_STATVFS_H ~= nil 14 | 15 | luabuild.write_config_header('config.h',cfg) 16 | 17 | luabuild.lua 'posix' 18 | luabuild.test 'tests-posix.lua' 19 | 20 | return luabuild.library {'posix_c',src='lposix',libs=libs,incdir='.'} 21 | -------------------------------------------------------------------------------- /modules/socket.core.lake: -------------------------------------------------------------------------------- 1 | ----- building socket/core ----- 2 | COMMON='timeout buffer auxiliar options io' 3 | COMMON = COMMON..' '..choose(WINDOWS,'wsocket','usocket') 4 | SCORE=COMMON..' luasocket inet tcp udp except select' 5 | 6 | luabuild.lua('ftp.lua http.lua smtp.lua headers.lua tp.lua url.lua','socket') 7 | luabuild.lua('socket.lua ltn12.lua') 8 | luabuild.test 'test-driver.lua' 9 | 10 | defines='LUASOCKET_DEBUG' 11 | if not luabuild.config.no_lua51_compat then 12 | defines = defines..' LUA_COMPAT_ALL' 13 | end 14 | if WINDOWS then 15 | libs = 'ws2_32' 16 | defines = defines..' _WIN32_WINNT=0x0501 IPV6_V6ONLY=27 INET_PTON' 17 | end 18 | 19 | -- needs='sockets', 20 | return luabuild.library {'socket/core',src=SCORE,defines=defines,libs=libs} 21 | -------------------------------------------------------------------------------- /modules/struct/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010 Lua.org, PUC-Rio. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /modules/winapi-1.4/wutils.h: -------------------------------------------------------------------------------- 1 | #ifndef WUTILS_H 2 | #define WUTILS_H 3 | typedef int Ref; 4 | 5 | extern int mutex_locked; 6 | 7 | Ref make_ref(lua_State *L, int idx); 8 | void release_ref(lua_State *L, Ref ref); 9 | int push_ref(lua_State *L, Ref ref); 10 | 11 | int push_error_msg(lua_State *L, LPCSTR msg) ; 12 | int push_error(lua_State *L); 13 | int push_error_code(lua_State *L, int err); 14 | int push_ok(lua_State *L); 15 | int push_bool(lua_State *L, int bval); 16 | void throw_error(lua_State *L, LPCSTR msg); 17 | BOOL call_lua_direct(lua_State *L, Ref ref, int idx, LPCSTR text, int discard); 18 | void make_message_window(); 19 | BOOL call_lua(lua_State *L, Ref ref, int idx, LPCSTR text, int discard); 20 | void lock_mutex(); 21 | void release_mutex(); 22 | void setup_mutex(); 23 | 24 | // encoding and converting text 25 | void set_encoding(int e); 26 | int get_encoding(); 27 | 28 | LPWSTR wstring_buff(LPCSTR text, LPWSTR wbuf, int bufsz); 29 | int push_wstring_l(lua_State *L, LPCWSTR us, int len); 30 | int push_wstring(lua_State *L, LPCWSTR us); 31 | 32 | HKEY split_registry_key(Str path, char *keypath); 33 | 34 | int mb_const (LPCSTR name); 35 | LPCSTR mb_result (int res); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /modules/winapi.lake: -------------------------------------------------------------------------------- 1 | if not WINDOWS then quit("sorry, wrong operating system!") end 2 | 3 | local defines = 'PSAPI_VERSION=1' 4 | local libs = 'kernel32 user32 psapi advapi32 shell32' 5 | 6 | if BUILD_PLAT == 'Windows' then 7 | libs = libs..' Mpr' 8 | else 9 | defines = defines .. ' NO_WINNET' 10 | end 11 | 12 | return luabuild.library{'winapi',src='winapi wutils', 13 | defines=defines,libs=libs 14 | } 15 | -------------------------------------------------------------------------------- /setpath: -------------------------------------------------------------------------------- 1 | export PATH="$(pwd)/bin:$PATH" 2 | # this is needed for static tests (temporary fix) 3 | export LUA_PATH_5_2="$(pwd)/lua/?.lua;;" 4 | -------------------------------------------------------------------------------- /shared.config: -------------------------------------------------------------------------------- 1 | --- building the kitchen sink --- 2 | if PLAT == 'Windows' then 3 | include = 'lfs winapi socket.core ' 4 | if CC == 'gcc' then include = include .. 'complex' end 5 | else 6 | include = 'lfs complex socket.core posix_c curses_c ltcl' 7 | readline = false 8 | end 9 | OPTIMIZE='O2' 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /srlua/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for srlua 2 | 3 | # change these to reflect your Lua installation 4 | LUA= /tmp/lhf/lua-5.2.0 5 | LUAINC= $(LUA)/src 6 | LUALIB= $(LUA)/src 7 | LUABIN= $(LUA)/src 8 | 9 | # these will probably work if Lua has been installed globally 10 | #LUA= /usr/local 11 | #LUAINC= $(LUA)/include 12 | #LUALIB= $(LUA)/lib 13 | #LUABIN= $(LUA)/bin 14 | 15 | # probably no need to change anything below here 16 | CC= gcc 17 | CFLAGS= $(INCS) $(WARN) -O2 $G 18 | WARN= -ansi -pedantic -Wall -Wextra 19 | INCS= -I$(LUAINC) 20 | LIBS= -L$(LUALIB) -llua -lm -ldl 21 | EXPORT= -Wl,-E 22 | # for Mac OS X comment the previous line above or do 'make EXPORT=' 23 | 24 | T= a.out 25 | S= srlua 26 | OBJS= srlua.o 27 | TEST= test.lua 28 | 29 | all: test 30 | 31 | test: $T 32 | ./$T * 33 | 34 | $T: $S $(TEST) glue 35 | ./glue $S $(TEST) $T 36 | chmod +x $T 37 | 38 | $S: $(OBJS) 39 | $(CC) -o $@ $(EXPORT) $(OBJS) $(LIBS) 40 | 41 | clean: 42 | rm -f $(OBJS) $T $S core core.* a.out *.o glue 43 | 44 | # eof 45 | -------------------------------------------------------------------------------- /srlua/README: -------------------------------------------------------------------------------- 1 | This is a self-running Lua interpreter. It is meant to be combined with a 2 | Lua program (which may be in either text or precompiled form) into a single, 3 | stand-alone program that will run the given Lua program when it is run. 4 | 5 | The command-line arguments will be available to the Lua program in a table 6 | called "arg" and also as '...'. All standard Lua libraries will be available 7 | too. If you want to use a different set of libraries, just copy linit.c from 8 | the Lua source, add it to srlua.c and edit luaL_openlibs to suit your needs. 9 | 10 | The Makefile is targeted at Unix systems. Just edit it to reflect your 11 | installation of Lua. Then run make. This will build srlua and glue, and run 12 | a simple test. For each Lua program that you want to turn into a stand-alone 13 | program, do 14 | glue srlua prog.lua a.out 15 | chmod +x a.out 16 | Of course, you can use any name instead of a.out. 17 | 18 | For Windows, you need to create srlua.exe and glue.exe first. Then for each 19 | Lua program that you want to turn into a stand-alone program, do 20 | glue srlua.exe prog.lua prog.exe 21 | Of course, you can use any name instead of prog.exe. 22 | 23 | This code is hereby placed in the public domain. 24 | Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br . 25 | -------------------------------------------------------------------------------- /srlua/glue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * glue.c 3 | * glue exe and script 4 | * Luiz Henrique de Figueiredo 5 | * 19 Feb 2005 09:14:06 6 | * This code is hereby placed in the public domain. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "glue.h" 14 | 15 | static void cannot(const char* what, const char* name) 16 | { 17 | fprintf(stderr,"cannot %s %s: %s\n",what,name,strerror(errno)); 18 | exit(EXIT_FAILURE); 19 | } 20 | 21 | static long copy(const char* name, FILE* out, const char* outname) 22 | { 23 | FILE* f; 24 | long size, offs; 25 | int first = 1; 26 | f=fopen(name,"rb"); 27 | if (f==NULL) cannot("open",name); 28 | if (fseek(f,0,SEEK_END)!=0) cannot("seek",name); 29 | size=ftell(f); 30 | if (fseek(f,0,SEEK_SET)!=0) cannot("seek",name); 31 | for (;;) 32 | { 33 | char b[BUFSIZ]; 34 | int n=fread(&b,1,sizeof(b),f); 35 | if (n==0) { if (ferror(f)) cannot("read",name); else break; } 36 | offs = 0; 37 | if (first) { 38 | if (b[0] == '#' && b[1] == '!' && b[2] == '/') { // get rid of shebang! 39 | offs += 3; 40 | while (b[offs] != '\n') 41 | ++offs; 42 | ++offs; // past line feed! 43 | size -= offs; // adjust size of written file 44 | } 45 | first = 0; 46 | } 47 | if (fwrite(&b[offs],n-offs,1,out)!=1) cannot("write",outname); 48 | } 49 | fclose(f); 50 | return size; 51 | } 52 | 53 | int main(int argc, char* argv[]) 54 | { 55 | Glue t= { GLUESIG, 0, 0 }; 56 | FILE* f; 57 | if (argc<4) 58 | { 59 | fprintf(stderr,"usage: glue c.exe prog.lua prog.exe\n"); 60 | return 1; 61 | } 62 | f=fopen(argv[3],"wb"); 63 | if (f==NULL) cannot("open",argv[3]); 64 | t.size1=copy(argv[1],f,argv[3]); 65 | t.size2=copy(argv[2],f,argv[3]); 66 | t.sig[GLUETYP]= (argv[4]!=NULL) ? argv[4][0] : 'L'; 67 | if (fwrite(&t,sizeof(t),1,f)!=1) cannot("write",argv[3]); 68 | if (fclose(f)!=0) cannot("close",argv[3]); 69 | #ifndef _WIN32 70 | { 71 | char path[256]; 72 | sprintf(path,"chmod +x %s",argv[3]); 73 | if (system(path)!=0) cannot("chmod",argv[3]); 74 | } 75 | #endif 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /srlua/glue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * glue.h 3 | * glue exe and script 4 | * Luiz Henrique de Figueiredo 5 | * 25 Aug 2004 22:06:50 6 | * This code is hereby placed in the public domain. 7 | */ 8 | 9 | #define GLUESIG "%%glue:L" 10 | #define GLUELEN (sizeof(GLUESIG)-1) 11 | #define GLUETYP (sizeof(GLUESIG)-2) 12 | 13 | typedef struct { char sig[GLUELEN]; long size1, size2; } Glue; 14 | -------------------------------------------------------------------------------- /srlua/test.lua: -------------------------------------------------------------------------------- 1 | -- test srlua 2 | 3 | print("hello from inside "..arg[0]) 4 | print(...) 5 | print"bye!" 6 | 7 | print("hello again from inside "..arg[0]) 8 | for i=0,#arg do 9 | print(i,arg[i]) 10 | end 11 | print"bye!" 12 | -------------------------------------------------------------------------------- /test-dynamic.bat: -------------------------------------------------------------------------------- 1 | lua lake -f test.lake 2 | -------------------------------------------------------------------------------- /test-static: -------------------------------------------------------------------------------- 1 | lua lake NAME=lua52s -f test.lake 2 | -------------------------------------------------------------------------------- /test-static.bat: -------------------------------------------------------------------------------- 1 | lua lake NAME=lua52s -f test.lake 2 | -------------------------------------------------------------------------------- /test.lake: -------------------------------------------------------------------------------- 1 | local name = NAME 2 | if not name then 3 | name = LUA53 and 'lua53' or 'lua52' 4 | end 5 | local testfile = name..'.tests' 6 | local f,err = io.open(testfile) 7 | if not f then quit(err) end 8 | 9 | local EXE = path.abs(path.join('bin',name)) 10 | if WINDOWS then 11 | EXE = EXE .. '.exe' 12 | REMOVE = 'del' 13 | else 14 | REMOVE = 'rm' 15 | end 16 | 17 | local tests = {} 18 | 19 | for line in f:lines() do 20 | local args = utils.split(line,'\t') 21 | local mod = args[1] 22 | local luatest = args[2] 23 | local tname = args[3] 24 | local depends = args[4] 25 | local test = target(tname,{luatest,depends}, 26 | EXE..' '..luatest..' > $(TARGET) || $(REMOVE) $(TARGET)') 27 | test.dir = path.splitpath(luatest) 28 | table.insert(tests,test) 29 | end 30 | 31 | default(tests) 32 | 33 | -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | This is where the test output files arrive. rm test/*.output if you want to re-run the tests 2 | -------------------------------------------------------------------------------- /tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . setpath 4 | 5 | while [ $# -gt 0 ] 6 | do 7 | case "$1" in 8 | (*=*) eval $1;; 9 | -h|--help) echo "optionally LUA53=1, STATIC=1"; exit;; 10 | esac 11 | shift 12 | done 13 | 14 | if [[ $LUA53 == "" ]] 15 | then 16 | L53='' 17 | L='lua52' 18 | else 19 | L53='LUA53=1' 20 | L='lua53' 21 | fi 22 | 23 | # see if we can build luaish properly! 24 | pushd luaish 25 | soar -o luaish lua.lua -lconfig -lluaish.lua < t.lua 26 | srlua -o ../bin/luaish -l $L luaish 27 | popd 28 | if ! luaish < luaish/t.lua 29 | then 30 | echo "luaish test borked" 31 | exit 32 | fi 33 | 34 | lake -f test.lake $L53 35 | -------------------------------------------------------------------------------- /tests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem see if we can wrap Lake successfully as an exe 3 | call srlua -m "lfs winapi" -o flake lake 4 | flake -h 5 | set L53= 6 | if defined LUA53 (set L53="LUA53=1") 7 | lake %L53% -f test.lake 8 | --------------------------------------------------------------------------------