├── src ├── dep │ ├── luaposix │ │ ├── sys │ │ │ ├── .deps │ │ │ │ ├── msg.Plo │ │ │ │ ├── stat.Plo │ │ │ │ ├── time.Plo │ │ │ │ ├── times.Plo │ │ │ │ ├── wait.Plo │ │ │ │ ├── resource.Plo │ │ │ │ ├── socket.Plo │ │ │ │ ├── statvfs.Plo │ │ │ │ └── utsname.Plo │ │ │ ├── time.c │ │ │ ├── utsname.c │ │ │ ├── times.c │ │ │ ├── wait.c │ │ │ ├── statvfs.c │ │ │ └── resource.c │ │ ├── AUTHORS │ │ ├── COPYING │ │ ├── posix.c │ │ ├── utime.c │ │ ├── glob.c │ │ ├── ctype.c │ │ ├── libgen.c │ │ ├── fnmatch.c │ │ ├── strlcpy_.c │ │ ├── dirent.c │ │ ├── sched.c │ │ ├── grp.c │ │ ├── pwd.c │ │ ├── getopt.c │ │ ├── stdio.c │ │ ├── config.h │ │ └── compat-5.2.h │ ├── lpeg │ │ ├── lpeg-128.gif │ │ ├── lpprint.h │ │ ├── lpcode.h │ │ ├── lpcap.h │ │ ├── makefile │ │ ├── lpvm.h │ │ ├── lptree.h │ │ ├── HISTORY │ │ └── lptypes.h │ └── lua-5.2.4 │ │ ├── doc │ │ ├── logo.gif │ │ ├── osi-certified-72x60.png │ │ ├── manual.css │ │ ├── lua.css │ │ ├── lua.1 │ │ └── luac.1 │ │ ├── README │ │ ├── src │ │ ├── lua.hpp │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lfunc.h │ │ ├── ldebug.h │ │ ├── lualib.h │ │ ├── ltm.h │ │ ├── lstring.h │ │ ├── ltable.h │ │ ├── lvm.h │ │ ├── ldo.h │ │ ├── lzio.h │ │ ├── lzio.c │ │ ├── linit.c │ │ ├── lmem.h │ │ ├── ltm.c │ │ ├── lctype.h │ │ ├── llex.h │ │ ├── lctype.c │ │ ├── lmem.c │ │ ├── lcode.h │ │ ├── lopcodes.c │ │ ├── lparser.h │ │ ├── ldump.c │ │ ├── lcorolib.c │ │ ├── lfunc.c │ │ └── lbitlib.c │ │ └── Makefile ├── example │ ├── ruby │ │ ├── hello.rb │ │ └── test.rb │ ├── scheme │ │ ├── hello.scm │ │ └── test.scm │ ├── cgi │ │ ├── uptime.cgi │ │ └── hello.cgi │ ├── python │ │ ├── hello.py │ │ ├── time.py │ │ └── test.py │ ├── lua │ │ ├── hello.lua │ │ ├── arg.lua │ │ ├── file.lua │ │ ├── ping.lua │ │ ├── iframe.lua │ │ └── test-all.lua │ ├── c │ │ ├── segfault.c │ │ ├── hello.c │ │ ├── arg.c │ │ ├── content-length.c │ │ ├── sleep.c │ │ ├── test.c │ │ └── file.c │ ├── nim │ │ ├── hello.nim │ │ └── test.nim │ ├── d │ │ ├── hello.d │ │ └── test.d │ ├── c++ │ │ └── hello.cpp │ ├── go │ │ ├── hello.go │ │ └── test.go │ ├── haskell │ │ ├── hello_stub.c │ │ └── hello.hs │ ├── crystal │ │ ├── hello.cr │ │ └── test.cr │ └── rust │ │ ├── hello.rs │ │ └── test.rs ├── module │ ├── lua.lua │ ├── so.lua │ ├── cgi.lua │ └── guile.c ├── api │ ├── crystal │ │ └── Modserver.cr │ ├── d │ │ └── modserver.d │ ├── rust │ │ ├── cmodserver.rs │ │ └── modserver.rs │ ├── nim │ │ └── modserver.nim │ ├── go │ │ └── src │ │ │ └── modserver │ │ │ └── modserver.go │ ├── lua │ │ └── modserver.lua │ └── c │ │ ├── modserver.h │ │ └── modserver.c ├── util.c ├── util.lua └── config.conf ├── .gitignore ├── Makefile └── readme.md /src/dep/luaposix/sys/.deps/msg.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/stat.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/time.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/times.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/wait.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/resource.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/socket.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/statvfs.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/.deps/utsname.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /src/example/ruby/hello.rb: -------------------------------------------------------------------------------- 1 | def run(s) 2 | rwrite(s, "hello from Ruby") 3 | end 4 | -------------------------------------------------------------------------------- /src/example/scheme/hello.scm: -------------------------------------------------------------------------------- 1 | (define (run s) 2 | (rwrite s "hello from Scheme")) 3 | -------------------------------------------------------------------------------- /src/dep/lpeg/lpeg-128.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ers35/modserver/HEAD/src/dep/lpeg/lpeg-128.gif -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ers35/modserver/HEAD/src/dep/lua-5.2.4/doc/logo.gif -------------------------------------------------------------------------------- /src/example/cgi/uptime.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf "Content-Type: text/plain; charset=UTF-8\n\n" 4 | uptime 5 | -------------------------------------------------------------------------------- /src/example/python/hello.py: -------------------------------------------------------------------------------- 1 | from modserver import * 2 | 3 | def run(s): 4 | rwrite(s, "hello from Python") 5 | -------------------------------------------------------------------------------- /src/example/cgi/hello.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Content-Type: text/html; charset=UTF-8" 4 | echo "" 5 | echo "hello from CGI" 6 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ers35/modserver/HEAD/src/dep/lua-5.2.4/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /src/example/lua/hello.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | function servlet:run() 4 | self:rwrite("hello from Lua") 5 | end 6 | 7 | return servlet 8 | -------------------------------------------------------------------------------- /src/example/python/time.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from modserver import * 3 | 4 | def run(s): 5 | rwrite(s, str(datetime.now())) 6 | -------------------------------------------------------------------------------- /src/example/c/segfault.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "modserver.h" 3 | 4 | int run(servlet *s) 5 | { 6 | raise(SIGSEGV); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/example/nim/hello.nim: -------------------------------------------------------------------------------- 1 | import modserver 2 | 3 | proc run(s: PServlet): int{.exportc.} = 4 | var reply = "hello from Nim" 5 | discard rwrite(s, reply, reply.len) 6 | return 0 7 | -------------------------------------------------------------------------------- /src/example/c/hello.c: -------------------------------------------------------------------------------- 1 | #include "modserver.h" 2 | 3 | int run(servlet *s) 4 | { 5 | const char reply[] = "hello from C"; 6 | rwrite(s, reply, sizeof(reply) - 1); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/example/d/hello.d: -------------------------------------------------------------------------------- 1 | import modserver; 2 | 3 | extern (C) int run(servlet *s) 4 | { 5 | string reply = "hello from D"; 6 | rwrite(s, reply.ptr, reply.length); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.2.4, released on 25 Feb 2015. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /src/example/c/arg.c: -------------------------------------------------------------------------------- 1 | #include "modserver.h" 2 | 3 | int run(servlet *s) 4 | { 5 | const char *name = get_arg(s, "name"); 6 | rprintf(s, "hello, %s", name ? name : "no name"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | old 2 | .old 3 | old.txt 4 | todo.txt 5 | note.txt 6 | *.o 7 | *.so 8 | *.a 9 | __pycache__ 10 | src/dep/lua-5.2.4/src/lua 11 | src/dep/lua-5.2.4/src/luac 12 | src/modserver 13 | src/modserver.lua.c 14 | -------------------------------------------------------------------------------- /src/example/c++/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "modserver.h" 3 | 4 | extern "C" int run(servlet *s) 5 | { 6 | std::string reply = "hello from C++"; 7 | rwrite(s, reply.c_str(), reply.length()); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/example/go/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import api "modserver" 4 | import "C" 5 | import "unsafe" 6 | 7 | //export run 8 | func run(s unsafe.Pointer) int { 9 | api.Rwrite(s, "hello from Go") 10 | return 0 11 | } 12 | 13 | func main() {} 14 | -------------------------------------------------------------------------------- /src/example/lua/arg.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | -- http://127.0.0.1:8080/arg?name=kenny 4 | 5 | function servlet:run() 6 | local name = self:get_arg("name") or "no name" 7 | self:rwrite("hello, " .. name) 8 | end 9 | 10 | return servlet 11 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/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 | -------------------------------------------------------------------------------- /src/module/lua.lua: -------------------------------------------------------------------------------- 1 | local mod = {} 2 | 3 | function mod.load_servlet(path) 4 | local chunk = assert(loadfile(path)) 5 | local servlet = chunk() 6 | assert(servlet.run, "The servlet must have a run() function: " .. path) 7 | return servlet 8 | end 9 | 10 | return mod 11 | -------------------------------------------------------------------------------- /src/module/so.lua: -------------------------------------------------------------------------------- 1 | local mod = {} 2 | 3 | function mod.load_servlet(path) 4 | local servlet = { 5 | -- init is optional. 6 | init = package.loadlib(path, "init"), 7 | run = assert(package.loadlib(path, "run")), 8 | } 9 | return servlet 10 | end 11 | 12 | return mod 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | cd src && $(MAKE) all 3 | run: 4 | cd src && $(MAKE) run 5 | test: 6 | cd src && $(MAKE) test 7 | install: 8 | cd src && $(MAKE) install 9 | clean: 10 | cd src && $(MAKE) clean 11 | modserver-git.zip: 12 | git archive HEAD --output $@ 13 | .PHONY: run test install clean modserver-git.zip 14 | -------------------------------------------------------------------------------- /src/example/haskell/hello_stub.c: -------------------------------------------------------------------------------- 1 | #include "modserver.h" 2 | #include 3 | 4 | int init(servlet *s) 5 | { 6 | static int argc = 1; 7 | static char *argv[] = {"hello.hs.so", NULL}, **argv_ = argv; 8 | hs_init(&argc, &argv_); 9 | return 0; 10 | } 11 | 12 | int cleanup(servlet *s) 13 | { 14 | hs_exit(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/example/ruby/test.rb: -------------------------------------------------------------------------------- 1 | def run(s) 2 | set_status(s, 200) 3 | set_header(s, "Content-Type", "text/plain; charset=UTF-8") 4 | arg = get_arg(s, "arg") 5 | unless arg.nil? 6 | rwrite(s, arg) 7 | end 8 | rwrite(s, get_method(s)) 9 | header = get_header(s, "User-Agent") 10 | unless header.nil? 11 | rwrite(s, header) 12 | end 13 | rflush(s) 14 | end 15 | -------------------------------------------------------------------------------- /src/example/crystal/hello.cr: -------------------------------------------------------------------------------- 1 | require "../../api/crystal/Modserver" 2 | 3 | fun init = init(text: UInt8*): Int32 4 | GC.init 5 | LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null) 6 | return 0 7 | end 8 | 9 | fun run = run(s: Modserver::Servlet*): Int32 10 | reply = "hello from Crystal" 11 | Modserver.rwrite(s, reply, reply.bytesize) 12 | return 0 13 | end 14 | -------------------------------------------------------------------------------- /src/example/c/content-length.c: -------------------------------------------------------------------------------- 1 | #include "modserver.h" 2 | #include 3 | 4 | int run(servlet *s) 5 | { 6 | const char reply[] = "Testing setting the Content-Length header"; 7 | char str_length[128]; 8 | snprintf(str_length, sizeof(str_length), "%lu", sizeof(reply) - 1); 9 | set_header(s, "Content-Length", str_length); 10 | rprintf(s, reply); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/example/python/test.py: -------------------------------------------------------------------------------- 1 | from modserver import * 2 | 3 | def run(s): 4 | set_status(s, 200) 5 | set_header(s, "Content-Type", "text/plain; charset=UTF-8") 6 | arg = get_arg(s, "arg") 7 | if arg: 8 | rwrite(s, arg + "\n") 9 | rwrite(s, get_method(s) + "\n") 10 | header = get_header(s, "User-Agent") 11 | if header: 12 | rwrite(s, header + "\n") 13 | rflush(s) 14 | -------------------------------------------------------------------------------- /src/example/scheme/test.scm: -------------------------------------------------------------------------------- 1 | (define (run s) 2 | (set_status s 200) 3 | (set_header s "Content-Type" "text/plain; charset=UTF-8") 4 | (let ((arg (get_arg s "arg"))) 5 | (if (string? arg) 6 | (rwrite s arg))) 7 | (rwrite s (get_method s)) 8 | (let ((header (get_header s "User-Agent"))) 9 | (if (string? header) 10 | (rwrite s header))) 11 | (rflush s)) 12 | 13 | ;(display run) 14 | ;(display (current-module)) 15 | -------------------------------------------------------------------------------- /src/example/rust/hello.rs: -------------------------------------------------------------------------------- 1 | // Rust experts: please provide feedback if there is a better way to accomplish this. 2 | 3 | #![crate_type = "dylib"] 4 | 5 | #[path="../../api/rust/modserver.rs"] 6 | pub mod modserver; 7 | use modserver::*; 8 | 9 | #[no_mangle] 10 | pub extern "C" fn run(s: *mut Servlet) -> u32 { 11 | let reply = String::from("hello from Rust"); 12 | let bytes = reply.into_bytes(); 13 | rwrite(s, bytes); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/example/c/sleep.c: -------------------------------------------------------------------------------- 1 | #include "modserver.h" 2 | #include "unistd.h" 3 | 4 | int run(servlet *s) 5 | { 6 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 7 | for (int count = 0; count < 5; ++count) 8 | { 9 | rprintf(s, "count: %i\n", count); 10 | // Without the rflush() the user would have to wait 5 seconds to see any output. 11 | rflush(s); 12 | sleep(1); 13 | } 14 | rprintf(s, "done\n"); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/example/haskell/hello.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ForeignFunctionInterface #-} 2 | 3 | module Hello where 4 | 5 | import Foreign 6 | import Foreign.C.String 7 | import Foreign.C.Types 8 | 9 | foreign import ccall "modserver.h rwrite" rwrite :: Ptr () -> CString -> CInt -> IO CInt 10 | foreign export ccall run :: Ptr () -> IO CInt 11 | 12 | run :: Ptr () -> IO CInt 13 | run s = do 14 | reply <- newCString "hello from Haskell" 15 | rwrite s reply 18 16 | free reply 17 | return 0 18 | -------------------------------------------------------------------------------- /src/api/crystal/Modserver.cr: -------------------------------------------------------------------------------- 1 | lib Modserver 2 | type Servlet = Void* 3 | 4 | fun get_arg(s: Servlet*, name: UInt8*) : UInt8* 5 | fun get_method(s: Servlet*) : UInt8* 6 | fun get_header(s: Servlet*, name: UInt8*) : UInt8* 7 | fun set_status(s: Servlet*, status: Int32) : Void 8 | fun set_header(s: Servlet*, name: UInt8*, value: UInt8*) : Void 9 | fun rwrite(s: Servlet*, buffer: UInt8*, length: UInt32) : UInt64 10 | fun rprintf(s: Servlet*, format: UInt8*, ...) : Int32 11 | fun rflush(s: Servlet*) : Void 12 | end 13 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/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 | -------------------------------------------------------------------------------- /src/api/d/modserver.d: -------------------------------------------------------------------------------- 1 | extern (C) 2 | { 3 | struct servlet; 4 | const(char)* get_arg(servlet *s, const char *name); 5 | const(char)* get_method(servlet *s); 6 | const(char)* get_header(servlet *s, const char *name); 7 | void set_status(servlet *s, int status); 8 | void set_header(servlet *s, const char *name, const char *value); 9 | size_t rwrite(servlet *s, const char *buffer, size_t length); 10 | int rprintf(servlet *s, const char *format, ...); 11 | void rflush(servlet *s); 12 | } 13 | 14 | // https://dlang.org/dll-linux.html 15 | // https://dlang.org/spec/interfaceToC.html 16 | -------------------------------------------------------------------------------- /src/example/lua/file.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | function servlet:run() 4 | local f = io.open("example/lua/file.lua", "r") 5 | if f then 6 | local length = f:seek("end") 7 | f:seek("set") 8 | self:set_header("Content-Length", tostring(length)) 9 | self:set_header("Content-Type", "text/plain; charset=UTF-8") 10 | while true do 11 | local buf = f:read(4096) 12 | if buf then 13 | self:rwrite(buf) 14 | else 15 | break 16 | end 17 | end 18 | f:close() 19 | else 20 | self:rwrite("file not found") 21 | end 22 | end 23 | 24 | return servlet 25 | -------------------------------------------------------------------------------- /src/dep/luaposix/AUTHORS: -------------------------------------------------------------------------------- 1 | luaposix is the work of several authors (see git history for 2 | contributors). It is based on two earlier 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 | John Belmonte wrote the example program tree.lua. 14 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/example/go/test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import api "modserver" 4 | import "C" 5 | import "unsafe" 6 | 7 | //export run 8 | func run(s unsafe.Pointer) int { 9 | api.Set_status(s, 200) 10 | api.Set_header(s, "Content-Type", "text/plain; charset=UTF-8") 11 | arg := api.Get_arg(s, "arg") 12 | if len(arg) > 0 { 13 | api.Rwrite(s, arg) 14 | api.Rwrite(s, "\n") 15 | } 16 | method := api.Get_method(s) 17 | api.Rwrite(s, method) 18 | api.Rwrite(s, "\n") 19 | header := api.Get_header(s, "User-Agent") 20 | if len(header) > 0 { 21 | api.Rwrite(s, header) 22 | } 23 | api.Rwrite(s, "\n") 24 | api.Rflush(s) 25 | return 0 26 | } 27 | 28 | func main() {} 29 | -------------------------------------------------------------------------------- /src/api/rust/cmodserver.rs: -------------------------------------------------------------------------------- 1 | use std::os::raw::c_char; 2 | 3 | pub enum StructServlet { } 4 | pub type Servlet = StructServlet; 5 | 6 | extern { 7 | pub fn get_arg(s: *mut Servlet, name: *const c_char) -> *const c_char; 8 | pub fn get_method(s: *mut Servlet) -> *const c_char; 9 | pub fn get_header(s: *mut Servlet, name: *const c_char) -> *const c_char; 10 | pub fn set_status(s: *mut Servlet, status: u32); 11 | pub fn set_header(s: *mut Servlet, name: *const c_char, value: *const c_char); 12 | pub fn rwrite(s: *mut Servlet, buffer: *const c_char, length: usize) -> usize; 13 | pub fn rprintf(s: *mut Servlet, format: *const c_char, ...) -> i32; 14 | pub fn rflush(s: *mut Servlet); 15 | } 16 | -------------------------------------------------------------------------------- /src/example/d/test.d: -------------------------------------------------------------------------------- 1 | import modserver; 2 | import core.stdc.string; 3 | 4 | extern (C) int run(servlet *s) 5 | { 6 | const char *arg = get_arg(s, "arg"); 7 | 8 | const char *method = get_method(s); 9 | assert(strcmp(method, "GET") == 0); 10 | 11 | const char *val0 = get_header(s, "User-Agent"); 12 | const char *val1 = get_header(s, "user-agent"); 13 | if (val0 && val1) 14 | { 15 | assert(strcmp(val0, val1) == 0); 16 | rprintf(s, val0); 17 | } 18 | 19 | set_status(s, 200); 20 | 21 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 22 | 23 | if (arg) 24 | { 25 | rprintf(s, arg); 26 | } 27 | 28 | rprintf(s, "The number is: %u\n", 42); 29 | 30 | rflush(s); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/example/c/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "modserver.h" 4 | 5 | int run(servlet *s) 6 | { 7 | const char *arg = get_arg(s, "arg"); 8 | 9 | const char *method = get_method(s); 10 | assert(strcmp(method, "GET") == 0); 11 | 12 | const char *val0 = get_header(s, "User-Agent"); 13 | const char *val1 = get_header(s, "user-agent"); 14 | if (val0 && val1) 15 | { 16 | assert(strcmp(val0, val1) == 0); 17 | rprintf(s, val0); 18 | } 19 | 20 | set_status(s, 200); 21 | 22 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 23 | 24 | if (arg) 25 | { 26 | rprintf(s, arg); 27 | } 28 | 29 | rprintf(s, "The number is: %u\n", 42); 30 | 31 | rflush(s); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/example/rust/test.rs: -------------------------------------------------------------------------------- 1 | // Rust experts: please provide feedback if there is a better way to accomplish this. 2 | 3 | #![crate_type = "dylib"] 4 | 5 | #[path="../../api/rust/modserver.rs"] 6 | pub mod modserver; 7 | use modserver::*; 8 | 9 | #[no_mangle] 10 | pub extern "C" fn run(s: *mut Servlet) -> u32 { 11 | set_status(s, 200); 12 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 13 | match get_arg(s, "arg") { 14 | Some(x) => { rwrite(s, x.into_bytes()); }, 15 | None => { } 16 | } 17 | let method = get_method(s); 18 | let bytes = method.into_bytes(); 19 | rwrite(s, bytes); 20 | match get_header(s, "User-Agent") { 21 | Some(x) => { rwrite(s, x.into_bytes()); }, 22 | None => { } 23 | } 24 | rflush(s); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/example/nim/test.nim: -------------------------------------------------------------------------------- 1 | import modserver 2 | 3 | # http://127.0.0.1:8080/example/nim/test.nim.so?test=abc 4 | 5 | proc run(s: PServlet): int{.exportc.} = 6 | set_status(s, 200) 7 | set_header(s, "Content-Type", "text/plain; charset=UTF-8") 8 | rflush(s) 9 | 10 | var arg = get_arg(s, "test") 11 | if arg != nil: 12 | discard rprintf(s, "get_arg(s, \"test\") = %s\n", arg) 13 | 14 | var header = get_header(s, "User-Agent") 15 | if header != nil: 16 | discard rprintf(s, "get_header(s, \"User-Agent\") = %s\n", header) 17 | 18 | var the_method = get_method(s) 19 | if the_method != nil: 20 | discard rprintf(s, "get_method(s) = %s\n", the_method) 21 | 22 | var reply = "hello from Nim" 23 | discard rwrite(s, reply, reply.len) 24 | 25 | rflush(s) 26 | 27 | return 0 28 | -------------------------------------------------------------------------------- /src/example/c/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "modserver.h" 3 | 4 | int run(servlet *s) 5 | { 6 | FILE *f = fopen("example/c/file.c", "r"); 7 | if (f) 8 | { 9 | fseek(f, 0, SEEK_END); 10 | long length = ftell(f); 11 | rewind(f); 12 | char str_length[128]; 13 | snprintf(str_length, sizeof(str_length), "%lu", length); 14 | set_header(s, "Content-Length", str_length); 15 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 16 | char buf[BUFSIZ]; 17 | while (1) 18 | { 19 | size_t bytes_read = fread(buf, 1, sizeof(buf), f); 20 | if (bytes_read > 0) 21 | { 22 | rwrite(s, buf, bytes_read); 23 | } 24 | else 25 | { 26 | break; 27 | } 28 | } 29 | fclose(f); 30 | } 31 | else 32 | { 33 | rprintf(s, "file not found"); 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/api/nim/modserver.nim: -------------------------------------------------------------------------------- 1 | type 2 | Servlet {.pure, final.} = object 3 | PServlet* = ptr Servlet 4 | 5 | proc get_arg*(s: PServlet, name: cstring): cstring{.cdecl, importc: "get_arg".} 6 | proc get_method*(s: PServlet): cstring{.cdecl, importc: "get_method".} 7 | proc get_header*(s: PServlet, name: cstring): cstring{.cdecl, importc: "get_header".} 8 | proc set_status*(s: PServlet, status: cint): void{.cdecl, importc: "set_status".} 9 | proc set_header*(s: PServlet, name: cstring, value: cstring): void{.cdecl, importc: "set_header".} 10 | proc rwrite*(s: PServlet, buffer: cstring, length: int): int{.cdecl, importc: "rwrite".} 11 | proc rprintf*(s: PServlet, format: cstring): cint{.cdecl, varargs, importc: "rprintf".} 12 | proc rflush*(s: PServlet): void{.cdecl, importc: "rflush".} 13 | 14 | # https://github.com/nim-lang/Nim/blob/master/lib/wrappers/sqlite3.nim 15 | # posix.nim uses int for size_t 16 | -------------------------------------------------------------------------------- /src/dep/lpeg/lpprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $ 3 | */ 4 | 5 | 6 | #if !defined(lpprint_h) 7 | #define lpprint_h 8 | 9 | 10 | #include "lptree.h" 11 | #include "lpvm.h" 12 | 13 | 14 | #if defined(LPEG_DEBUG) 15 | 16 | void printpatt (Instruction *p, int n); 17 | void printtree (TTree *tree, int ident); 18 | void printktable (lua_State *L, int idx); 19 | void printcharset (const byte *st); 20 | void printcaplist (Capture *cap, Capture *limit); 21 | void printinst (const Instruction *op, const Instruction *p); 22 | 23 | #else 24 | 25 | #define printktable(L,idx) \ 26 | luaL_error(L, "function only implemented in debug mode") 27 | #define printtree(tree,i) \ 28 | luaL_error(L, "function only implemented in debug mode") 29 | #define printpatt(p,n) \ 30 | luaL_error(L, "function only implemented in debug mode") 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/module/cgi.lua: -------------------------------------------------------------------------------- 1 | local mod = {} 2 | 3 | local function run(self, path) 4 | local f = io.popen(path) 5 | if f then 6 | while true do 7 | -- 6.2. Response Types 8 | -- https://tools.ietf.org/html/rfc3875#section-6.2 9 | local header = f:read("*l") 10 | if not header or #header == 0 then 11 | break 12 | end 13 | local key, value = header:match("([%a-]+)%s*:%s*(.+)") 14 | if key and value then 15 | self:set_header(key, value) 16 | end 17 | end 18 | while true do 19 | local body = f:read(4096) 20 | if not body then 21 | break 22 | end 23 | self:rwrite(body) 24 | end 25 | f:close() 26 | end 27 | end 28 | 29 | function mod.load_servlet(path) 30 | local servlet = {} 31 | 32 | function servlet:run() 33 | run(self, path) 34 | end 35 | 36 | return servlet 37 | end 38 | 39 | return mod 40 | 41 | -- https://tools.ietf.org/html/rfc3875 42 | -------------------------------------------------------------------------------- /src/dep/lpeg/lpcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcode.h,v 1.7 2015/06/12 18:24:45 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcode_h) 6 | #define lpcode_h 7 | 8 | #include "lua.h" 9 | 10 | #include "lptypes.h" 11 | #include "lptree.h" 12 | #include "lpvm.h" 13 | 14 | int tocharset (TTree *tree, Charset *cs); 15 | int checkaux (TTree *tree, int pred); 16 | int fixedlenx (TTree *tree, int count, int len); 17 | int hascaptures (TTree *tree); 18 | int lp_gc (lua_State *L); 19 | Instruction *compile (lua_State *L, Pattern *p); 20 | void realloccode (lua_State *L, Pattern *p, int nsize); 21 | int sizei (const Instruction *i); 22 | 23 | 24 | #define PEnullable 0 25 | #define PEnofail 1 26 | 27 | /* 28 | ** nofail(t) implies that 't' cannot fail with any input 29 | */ 30 | #define nofail(t) checkaux(t, PEnofail) 31 | 32 | /* 33 | ** (not nullable(t)) implies 't' cannot match without consuming 34 | ** something 35 | */ 36 | #define nullable(t) checkaux(t, PEnullable) 37 | 38 | #define fixedlen(t) fixedlenx(t, 0, 0) 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/example/crystal/test.cr: -------------------------------------------------------------------------------- 1 | require "../../api/crystal/Modserver" 2 | 3 | fun init = init(text: UInt8*): Int32 4 | GC.init 5 | LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null) 6 | return 0 7 | end 8 | 9 | fun run = run(s: Modserver::Servlet*): Int32 10 | Modserver.set_status(s, 200) 11 | Modserver.set_header(s, "Content-Type", "text/plain; charset=UTF-8") 12 | arg = Modserver.get_arg(s, "arg") 13 | if arg 14 | Modserver.rprintf(s, "%s\n", arg) 15 | end 16 | reply = "hello from Crystal" 17 | Modserver.rwrite(s, reply, reply.bytesize) 18 | method = Modserver.get_method(s) 19 | Modserver.rprintf(s, "\n%s\n", method) 20 | header = Modserver.get_header(s, "User-Agent") 21 | Modserver.rprintf(s, "%s\n", header) 22 | Modserver.rflush(s) 23 | return 0 24 | end 25 | 26 | # https://crystal-lang.org/docs/syntax_and_semantics/c_bindings/fun.html 27 | # https://github.com/crystal-lang/crystal-sqlite3 28 | # https://github.com/crystal-lang/crystal-sqlite3/blob/master/src/sqlite3/lib_sqlite3.cr 29 | # http://stackoverflow.com/a/32921404 30 | -------------------------------------------------------------------------------- /src/example/lua/ping.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | local socket = require("posix.sys.socket") 4 | 5 | function servlet:run() 6 | self:rwrite([[ 7 | 8 | 9 | Ping 10 | 11 |
12 | Host: 13 | 14 |
15 |
16 | ]])
17 |   local host = self:get_arg("host")
18 |   if host then
19 |     local addr = socket.getaddrinfo(host, nil, {
20 |       family = socket.AF_UNSPEC, socktype = socket.SOCK_STREAM}
21 |     )
22 |     if addr and addr[1] and addr[1].addr then
23 |       local ip = addr[1].addr
24 |       local command = "ping -c 10 " .. ip
25 |       self:rwrite("$ " .. command .. "\n")
26 |       self:rflush()
27 |       for line in io.popen(command):lines() do
28 |         self:rwrite(line .. "\n")
29 |         self:rflush()
30 |       end
31 |     else
32 |       self:rwrite("invalid host")
33 |     end
34 |     self:rwrite([[
35 | 
36 | 37 | 38 | ]]) 39 | end 40 | end 41 | 42 | return servlet 43 | -------------------------------------------------------------------------------- /src/example/lua/iframe.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | function servlet:run() 4 | self:rwrite([[ 5 | 6 | 7 | 8 | iframe 9 | 16 | 17 | 18 | ]]) 19 | local servlets = { 20 | "/example/c/hello.c.so", 21 | "/example/c++/hello.cpp.so", 22 | "/example/crystal/hello.cr.so", 23 | "/example/cgi/hello.cgi", 24 | "/example/d/hello.d.so", 25 | "/example/go/hello.go.so", 26 | "/example/haskell/hello.hs.so", 27 | "/example/lua/hello.lua", 28 | "/example/nim/hello.nim.so", 29 | "/example/python/hello.py", 30 | "/example/ruby/hello.rb", 31 | "/example/rust/hello.rs.so", 32 | "/example/scheme/hello.scm", 33 | } 34 | for i, servlet in ipairs(servlets) do 35 | self:rwrite(([[%s]] .. "\n"):format(servlet, servlet)) 36 | self:rwrite(([[]] .. "\n"):format(servlet)) 37 | end 38 | self:rwrite([[ 39 | 40 | 41 | ]]) 42 | end 43 | 44 | return servlet 45 | -------------------------------------------------------------------------------- /src/dep/luaposix/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2006-2016 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 | -------------------------------------------------------------------------------- /src/example/lua/test-all.lua: -------------------------------------------------------------------------------- 1 | local servlet = {} 2 | 3 | function servlet:run() 4 | self:rwrite([[ 5 | 6 | 7 | 8 | iframe 9 | 17 | 18 | 19 | ]]) 20 | local servlets = { 21 | "/example/c/test.c.so", 22 | "/example/c/content-length.c.so", 23 | "/example/crystal/test.cr.so", 24 | "/example/cgi/test.cgi", 25 | "/example/d/test.d.so", 26 | "/example/go/test.go.so", 27 | "/example/haskell/test.hs.so", 28 | "/example/lua/test.lua", 29 | "/example/nim/test.nim.so", 30 | "/example/python/test.py", 31 | "/example/ruby/test.rb", 32 | "/example/rust/test.rs.so", 33 | "/example/scheme/test.scm", 34 | } 35 | for i, servlet in ipairs(servlets) do 36 | self:rwrite(([[%s]] .. "\n"):format(servlet, servlet)) 37 | self:rwrite(([[]] .. "\n"):format(servlet)) 38 | end 39 | self:rwrite([[ 40 | 41 | 42 | ]]) 43 | end 44 | 45 | return servlet 46 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lpeg/lpcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcap.h,v 1.2 2015/02/27 17:13:17 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcap_h) 6 | #define lpcap_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* kinds of captures */ 13 | typedef enum CapKind { 14 | Cclose, Cposition, Cconst, Cbackref, Carg, Csimple, Ctable, Cfunction, 15 | Cquery, Cstring, Cnum, Csubst, Cfold, Cruntime, Cgroup 16 | } CapKind; 17 | 18 | 19 | typedef struct Capture { 20 | const char *s; /* subject position */ 21 | unsigned short idx; /* extra info (group name, arg index, etc.) */ 22 | byte kind; /* kind of capture */ 23 | byte siz; /* size of full capture + 1 (0 = not a full capture) */ 24 | } Capture; 25 | 26 | 27 | typedef struct CapState { 28 | Capture *cap; /* current capture */ 29 | Capture *ocap; /* (original) capture list */ 30 | lua_State *L; 31 | int ptop; /* index of last argument to 'match' */ 32 | const char *s; /* original string */ 33 | int valuecached; /* value stored in cache slot */ 34 | } CapState; 35 | 36 | 37 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); 38 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop); 39 | int finddyncap (Capture *cap, Capture *last); 40 | 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/dep/lpeg/makefile: -------------------------------------------------------------------------------- 1 | LIBNAME = lpeg 2 | LUADIR = ../lua/ 3 | 4 | COPT = -O2 5 | # COPT = -DLPEG_DEBUG -g 6 | 7 | CWARNS = -Wall -Wextra -pedantic \ 8 | -Waggregate-return \ 9 | -Wcast-align \ 10 | -Wcast-qual \ 11 | -Wdisabled-optimization \ 12 | -Wpointer-arith \ 13 | -Wshadow \ 14 | -Wsign-compare \ 15 | -Wundef \ 16 | -Wwrite-strings \ 17 | -Wbad-function-cast \ 18 | -Wdeclaration-after-statement \ 19 | -Wmissing-prototypes \ 20 | -Wnested-externs \ 21 | -Wstrict-prototypes \ 22 | # -Wunreachable-code \ 23 | 24 | 25 | CFLAGS = $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC 26 | CC = gcc 27 | 28 | FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o 29 | 30 | # For Linux 31 | linux: 32 | $(MAKE) lpeg.a 33 | 34 | # For Mac OS 35 | macosx: 36 | $(MAKE) lpeg.a 37 | 38 | lpeg.a: $(FILES) 39 | ar rcs lpeg.a $(FILES) 40 | 41 | $(FILES): makefile 42 | 43 | test: test.lua re.lua lpeg.so 44 | ./test.lua 45 | 46 | clean: 47 | rm -f $(FILES) lpeg.so lpeg.a 48 | 49 | 50 | lpcap.o: lpcap.c lpcap.h lptypes.h 51 | lpcode.o: lpcode.c lptypes.h lpcode.h lptree.h lpvm.h lpcap.h 52 | lpprint.o: lpprint.c lptypes.h lpprint.h lptree.h lpvm.h lpcap.h 53 | lptree.o: lptree.c lptypes.h lpcap.h lpcode.h lptree.h lpvm.h lpprint.h 54 | lpvm.o: lpvm.c lpcap.h lptypes.h lpvm.h lpprint.h lptree.h 55 | 56 | -------------------------------------------------------------------------------- /src/dep/luaposix/posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | 13 | #include "ctype.c" 14 | #include "dirent.c" 15 | #include "errno.c" 16 | #include "fcntl.c" 17 | #include "fnmatch.c" 18 | #include "getopt.c" 19 | #include "glob.c" 20 | #include "grp.c" 21 | #include "libgen.c" 22 | #include "poll.c" 23 | #include "pwd.c" 24 | #include "sched.c" 25 | #include "signal.c" 26 | #include "stdio.c" 27 | #include "stdlib.c" 28 | #include "sys/msg.c" 29 | #include "sys/resource.c" 30 | #include "sys/socket.c" 31 | #include "sys/stat.c" 32 | #include "sys/statvfs.c" 33 | #include "sys/time.c" 34 | #include "sys/times.c" 35 | #include "sys/utsname.c" 36 | #include "sys/wait.c" 37 | #include "syslog.c" 38 | #include "termio.c" 39 | #include "time.c" 40 | #include "unistd.c" 41 | #include "utime.c" 42 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* 13 | Lua's file:read() function lacks a way to read a line of a limited length. That is an 14 | easy denial of service if the user never sends a newline. 15 | */ 16 | static int cutil_fgets(lua_State *l) 17 | { 18 | luaL_Stream *stream = luaL_checkudata(l, -1, LUA_FILEHANDLE); 19 | int size = luaL_checknumber(l, -2); 20 | FILE *f = stream->f; 21 | luaL_Buffer b; 22 | luaL_buffinit(l, &b); 23 | char *p = luaL_prepbuffsize(&b, size); 24 | if (fgets(p, size, f) == NULL) 25 | { 26 | // discard the buffer 27 | luaL_pushresult(&b); 28 | lua_pop(l, 1); 29 | 30 | lua_pushnil(l); 31 | if (feof(f)) 32 | { 33 | lua_pushstring(l, "EOF"); 34 | lua_pushnil(l); 35 | } 36 | else if (ferror(f)) 37 | { 38 | lua_pushstring(l, strerror(errno)); 39 | lua_pushnumber(l, errno); 40 | } 41 | return 3; 42 | } 43 | size_t len = strlen(p); 44 | luaL_addsize(&b, len); 45 | luaL_pushresult(&b); 46 | return 1; 47 | } 48 | 49 | static const luaL_Reg cutil[] = 50 | { 51 | {"fgets", cutil_fgets}, 52 | {NULL, NULL}, 53 | }; 54 | 55 | LUALIB_API int luaopen_cutil(lua_State *l) 56 | { 57 | luaL_newlib(l, cutil); 58 | return 1; 59 | } 60 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48: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 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 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 | /* returns the key, given the value of a table entry */ 21 | #define keyfromval(v) \ 22 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 23 | 24 | 25 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); 26 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); 27 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 28 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 31 | LUAI_FUNC Table *luaH_new (lua_State *L); 32 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); 33 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 34 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 35 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 36 | LUAI_FUNC int luaH_getn (Table *t); 37 | 38 | 39 | #if defined(LUA_DEBUG) 40 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 41 | LUAI_FUNC int luaH_isdummy (Node *n); 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/luaposix/utime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Set File Times. 14 | 15 | @module posix.utime 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "_helpers.c" 24 | 25 | 26 | /*** 27 | Change file last access and modification times. 28 | @function utime 29 | @see utime(2) 30 | @string path existing file path 31 | @int[opt=now] mtime modification time 32 | @int[opt=now] atime access time 33 | @treturn[1] int `0`, if successful 34 | @return[2] nil 35 | @treturn[2] string error message 36 | @treturn[2] int errnum 37 | */ 38 | static int 39 | Putime(lua_State *L) 40 | { 41 | struct utimbuf times; 42 | time_t currtime = time(NULL); 43 | const char *path = luaL_checkstring(L, 1); 44 | times.modtime = optint(L, 2, currtime); 45 | times.actime = optint(L, 3, currtime); 46 | checknargs(L, 3); 47 | return pushresult(L, utime(path, ×), path); 48 | } 49 | 50 | 51 | static const luaL_Reg posix_utime_fns[] = 52 | { 53 | LPOSIX_FUNC( Putime ), 54 | {NULL, NULL} 55 | }; 56 | 57 | 58 | LUALIB_API int 59 | luaopen_posix_utime(lua_State *L) 60 | { 61 | luaL_register(L, "posix.utime", posix_utime_fns); 62 | lua_pushliteral(L, "posix.utime for " LUA_VERSION " / " PACKAGE_STRING); 63 | lua_setfield(L, -2, "version"); 64 | 65 | return 1; 66 | } 67 | -------------------------------------------------------------------------------- /src/api/go/src/modserver/modserver.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | /* 4 | #cgo CFLAGS: -I../../../c 5 | #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup 6 | #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all 7 | #include "modserver.h" 8 | */ 9 | import "C" 10 | 11 | import "unsafe" 12 | 13 | //type Servlet C.servlet 14 | //type Servlet unsafe.Pointer 15 | 16 | func to_ptr(str string) (unsafe.Pointer) { 17 | str_slice := []byte(str) 18 | str_ptr := unsafe.Pointer(&str_slice[0]) 19 | return str_ptr 20 | } 21 | 22 | func Get_arg(s unsafe.Pointer, name string) (string) { 23 | name_ptr := to_ptr(name) 24 | arg := C.get_arg((*C.servlet)(s), (*C.char)(name_ptr)) 25 | arg_string := C.GoString(arg) 26 | return arg_string 27 | } 28 | 29 | func Get_method(s unsafe.Pointer) (string) { 30 | method := C.get_method((*C.servlet)(s)) 31 | method_string := C.GoString(method) 32 | return method_string 33 | } 34 | 35 | func Get_header(s unsafe.Pointer, name string) (string) { 36 | name_ptr := to_ptr(name) 37 | value := C.get_header((*C.servlet)(s), (*C.char)(name_ptr)) 38 | value_string := C.GoString(value) 39 | return value_string 40 | } 41 | 42 | func Set_status(s unsafe.Pointer, status int32) { 43 | C.set_status((*C.servlet)(s), (C.int)(status)) 44 | } 45 | 46 | func Set_header(s unsafe.Pointer, name string, value string) { 47 | name_ptr := to_ptr(name) 48 | value_ptr := to_ptr(value) 49 | C.set_header((*C.servlet)(s), (*C.char)(name_ptr), (*C.char)(value_ptr)) 50 | } 51 | 52 | func Rwrite(s unsafe.Pointer, buffer string) (C.size_t) { 53 | buffer_ptr := to_ptr(buffer) 54 | return C.rwrite((*C.servlet)(s), (*C.char)(buffer_ptr), C.size_t(len(buffer))) 55 | } 56 | 57 | func Rflush(s unsafe.Pointer) { 58 | C.rflush((*C.servlet)(s)) 59 | } 60 | 61 | // https://github.com/golang/go/wiki/cgo 62 | // https://github.com/golang/go/issues/14985 63 | -------------------------------------------------------------------------------- /src/dep/lpeg/lpvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpvm_h) 6 | #define lpvm_h 7 | 8 | #include "lpcap.h" 9 | 10 | 11 | /* Virtual Machine's instructions */ 12 | typedef enum Opcode { 13 | IAny, /* if no char, fail */ 14 | IChar, /* if char != aux, fail */ 15 | ISet, /* if char not in buff, fail */ 16 | ITestAny, /* in no char, jump to 'offset' */ 17 | ITestChar, /* if char != aux, jump to 'offset' */ 18 | ITestSet, /* if char not in buff, jump to 'offset' */ 19 | ISpan, /* read a span of chars in buff */ 20 | IBehind, /* walk back 'aux' characters (fail if not possible) */ 21 | IRet, /* return from a rule */ 22 | IEnd, /* end of pattern */ 23 | IChoice, /* stack a choice; next fail will jump to 'offset' */ 24 | IJmp, /* jump to 'offset' */ 25 | ICall, /* call rule at 'offset' */ 26 | IOpenCall, /* call rule number 'key' (must be closed to a ICall) */ 27 | ICommit, /* pop choice and jump to 'offset' */ 28 | IPartialCommit, /* update top choice to current position and jump */ 29 | IBackCommit, /* "fails" but jump to its own 'offset' */ 30 | IFailTwice, /* pop one choice and then fail */ 31 | IFail, /* go back to saved state on choice and jump to saved offset */ 32 | IGiveup, /* internal use */ 33 | IFullCapture, /* complete capture of last 'off' chars */ 34 | IOpenCapture, /* start a capture */ 35 | ICloseCapture, 36 | ICloseRunTime 37 | } Opcode; 38 | 39 | 40 | 41 | typedef union Instruction { 42 | struct Inst { 43 | byte code; 44 | byte aux; 45 | short key; 46 | } i; 47 | int offset; 48 | byte buff[1]; 49 | } Instruction; 50 | 51 | 52 | void printpatt (Instruction *p, int n); 53 | const char *match (lua_State *L, const char *o, const char *s, const char *e, 54 | Instruction *op, Capture *capture, int ptop); 55 | 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/dep/lpeg/lptree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lptree_h) 6 | #define lptree_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* 13 | ** types of trees 14 | */ 15 | typedef enum TTag { 16 | TChar = 0, TSet, TAny, /* standard PEG elements */ 17 | TTrue, TFalse, 18 | TRep, 19 | TSeq, TChoice, 20 | TNot, TAnd, 21 | TCall, 22 | TOpenCall, 23 | TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */ 24 | TGrammar, /* sib1 is initial (and first) rule */ 25 | TBehind, /* match behind */ 26 | TCapture, /* regular capture */ 27 | TRunTime /* run-time capture */ 28 | } TTag; 29 | 30 | /* number of siblings for each tree */ 31 | extern const byte numsiblings[]; 32 | 33 | 34 | /* 35 | ** Tree trees 36 | ** The first sibling of a tree (if there is one) is immediately after 37 | ** the tree. A reference to a second sibling (ps) is its position 38 | ** relative to the position of the tree itself. A key in ktable 39 | ** uses the (unique) address of the original tree that created that 40 | ** entry. NULL means no data. 41 | */ 42 | typedef struct TTree { 43 | byte tag; 44 | byte cap; /* kind of capture (if it is a capture) */ 45 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ 46 | union { 47 | int ps; /* occasional second sibling */ 48 | int n; /* occasional counter */ 49 | } u; 50 | } TTree; 51 | 52 | 53 | /* 54 | ** A complete pattern has its tree plus, if already compiled, 55 | ** its corresponding code 56 | */ 57 | typedef struct Pattern { 58 | union Instruction *code; 59 | int codesize; 60 | TTree tree[1]; 61 | } Pattern; 62 | 63 | 64 | /* number of siblings for each tree */ 65 | extern const byte numsiblings[]; 66 | 67 | /* access to siblings */ 68 | #define sib1(t) ((t) + 1) 69 | #define sib2(t) ((t) + (t)->u.ps) 70 | 71 | 72 | 73 | 74 | 75 | 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /src/dep/luaposix/glob.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Generate pathnames matching a shell-style pattern. 14 | 15 | Functions generating a table of filenames that match a shell-style 16 | pattern string. 17 | 18 | @module posix.glob 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "_helpers.c" 26 | 27 | 28 | /*** 29 | Find all files in this directory matching a shell pattern. 30 | @function glob 31 | @string[opt="*"] pat shell glob pattern 32 | @treturn table matching filenames 33 | @see glob(3) 34 | @see glob.lua 35 | */ 36 | static int 37 | Pglob(lua_State *L) 38 | { 39 | const char *pattern = optstring(L, 1, "*"); 40 | glob_t globres; 41 | 42 | checknargs(L, 1); 43 | if (glob(pattern, 0, NULL, &globres)) 44 | return pusherror(L, pattern); 45 | else 46 | { 47 | unsigned int i; 48 | lua_newtable(L); 49 | for (i=1; i<=globres.gl_pathc; i++) 50 | { 51 | lua_pushstring(L, globres.gl_pathv[i-1]); 52 | lua_rawseti(L, -2, i); 53 | } 54 | globfree(&globres); 55 | return 1; 56 | } 57 | } 58 | 59 | 60 | static const luaL_Reg posix_glob_fns[] = 61 | { 62 | LPOSIX_FUNC( Pglob ), 63 | {NULL, NULL} 64 | }; 65 | 66 | 67 | LUALIB_API int 68 | luaopen_posix_glob(lua_State *L) 69 | { 70 | luaL_register(L, "posix.glob", posix_glob_fns); 71 | lua_pushliteral(L, "posix.glob for " LUA_VERSION " / " PACKAGE_STRING); 72 | lua_setfield(L, -2, "version"); 73 | 74 | return 1; 75 | } 76 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 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 | 44 | /* 45 | ** these libs are preloaded and must be required before used 46 | */ 47 | static const luaL_Reg preloadedlibs[] = { 48 | {NULL, NULL} 49 | }; 50 | 51 | 52 | LUALIB_API void luaL_openlibs (lua_State *L) { 53 | const luaL_Reg *lib; 54 | /* call open functions from 'loadedlibs' and set results to global table */ 55 | for (lib = loadedlibs; lib->func; lib++) { 56 | luaL_requiref(L, lib->name, lib->func, 1); 57 | lua_pop(L, 1); /* remove lib */ 58 | } 59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 60 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 61 | for (lib = preloadedlibs; lib->func; lib++) { 62 | lua_pushcfunction(L, lib->func); 63 | lua_setfield(L, -2, lib->name); 64 | } 65 | lua_pop(L, 1); /* remove _PRELOAD table */ 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/dep/luaposix/ctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Character tests. 14 | 15 | @module posix.ctype 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | 25 | static int 26 | bind_ctype(lua_State *L, int (*cb)(int)) 27 | { 28 | const char *s = luaL_checkstring(L, 1); 29 | char c = *s; 30 | checknargs(L, 1); 31 | lua_pop(L, 1); 32 | return pushintresult(cb((int)c)); 33 | } 34 | 35 | 36 | /*** 37 | Check for any printable character except space. 38 | @function isgraph 39 | @see isgraph(3) 40 | @string character to act on 41 | @treturn int non-zero if character is not in the class 42 | */ 43 | static int 44 | Pisgraph(lua_State *L) 45 | { 46 | return bind_ctype(L, &isgraph); 47 | } 48 | 49 | 50 | /*** 51 | Check for any printable character including space. 52 | @function isprint 53 | @string character to act on 54 | @treturn int non-zero if character is not in the class 55 | @see isprint(3) 56 | */ 57 | static int 58 | Pisprint(lua_State *L) 59 | { 60 | return bind_ctype(L, &isprint); 61 | } 62 | 63 | 64 | static const luaL_Reg posix_ctype_fns[] = 65 | { 66 | LPOSIX_FUNC( Pisgraph ), 67 | LPOSIX_FUNC( Pisprint ), 68 | {NULL, NULL} 69 | }; 70 | 71 | 72 | LUALIB_API int 73 | luaopen_posix_ctype(lua_State *L) 74 | { 75 | luaL_register(L, "posix.ctype", posix_ctype_fns); 76 | lua_pushliteral(L, "posix.ctype for " LUA_VERSION " / " PACKAGE_STRING); 77 | lua_setfield(L, -2, "version"); 78 | 79 | return 1; 80 | } 81 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Get and Set System Date and Time. 14 | 15 | @module posix.sys.time 16 | */ 17 | 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "_helpers.c" 24 | 25 | 26 | /*** 27 | Time value. 28 | @table PosixTimeval 29 | @int tv_sec seconds elapsed 30 | @int tv_usec remainder in microseconds 31 | @see posix.time.PosixTimespec 32 | */ 33 | static int 34 | pushtimeval(lua_State *L, struct timeval *tv) 35 | { 36 | if (!tv) 37 | return lua_pushnil(L), 1; 38 | 39 | lua_createtable(L, 0, 2); 40 | setintegerfield(tv, tv_sec); 41 | setintegerfield(tv, tv_usec); 42 | 43 | settypemetatable("PosixTimeval"); 44 | return 1; 45 | } 46 | 47 | 48 | /*** 49 | Get time of day. 50 | @function gettimeofday 51 | @treturn PosixTimeval time elapsed since *epoch* 52 | @see gettimeofday(2) 53 | */ 54 | static int 55 | Pgettimeofday(lua_State *L) 56 | { 57 | struct timeval tv; 58 | checknargs(L, 0); 59 | if (gettimeofday(&tv, NULL) == -1) 60 | return pusherror(L, "gettimeofday"); 61 | 62 | return pushtimeval(L, &tv); 63 | } 64 | 65 | 66 | static const luaL_Reg posix_sys_time_fns[] = 67 | { 68 | LPOSIX_FUNC( Pgettimeofday ), 69 | {NULL, NULL} 70 | }; 71 | 72 | 73 | LUALIB_API int 74 | luaopen_posix_sys_time(lua_State *L) 75 | { 76 | luaL_register(L, "posix.sys.time", posix_sys_time_fns); 77 | lua_pushliteral(L, "posix.sys.time for " LUA_VERSION " / " PACKAGE_STRING); 78 | lua_setfield(L, -2, "version"); 79 | 80 | return 1; 81 | } 82 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/util.lua: -------------------------------------------------------------------------------- 1 | local util = {} 2 | 3 | local cutil = require("cutil") 4 | local errno = require("posix.errno") 5 | local fcntl = require("posix.fcntl") 6 | local signal = require("posix.signal") 7 | 8 | function util.set_nonblocking(fd) 9 | local current_flags = assert(fcntl.fcntl(fd, fcntl.F_GETFL)) 10 | assert(fcntl.fcntl(fd, fcntl.F_SETFL, bit32.bor(current_flags, fcntl.O_NONBLOCK))) 11 | end 12 | 13 | function util.set_close_on_exec(fd) 14 | local current_flags = assert(fcntl.fcntl(fd, fcntl.F_GETFD)) 15 | assert(fcntl.fcntl(fd, fcntl.F_SETFD, bit32.bor(current_flags, fcntl.FD_CLOEXEC))) 16 | end 17 | 18 | function util.fgets(length, file) 19 | while true do 20 | local buffer, errmsg, errnum = cutil.fgets(length, file) 21 | if errnum ~= errno.EINTR then 22 | return buffer, errmsg, errnum 23 | end 24 | end 25 | end 26 | 27 | --[[ 28 | A process may only set one signal handler per signal type. Certain language 29 | implementations set signal handlers. This poses a problem because the handlers conflict 30 | with each other. Assume that the signal handlers are only used for debugging crashes and 31 | set them all to SIG_DFL to have the parent process report the crash instead. 32 | Unfortunately, useful debugging information like stack traces are lost. Perhaps creating 33 | a core dump when a servlet crashes is a reasonable compromise. 34 | --]] 35 | function util.set_default_signal_handlers() 36 | for _, signal_name in ipairs{ 37 | "SIGINT", 38 | "SIGSEGV", 39 | "SIGABRT", 40 | "SIGFPE", 41 | "SIGILL", 42 | "SIGBUS", 43 | "SIGCHLD", 44 | } do 45 | signal.signal(signal[signal_name], signal.SIG_DFL) 46 | end 47 | -- Prefer handling SIGPIPE at each write call instead of terminating the process. 48 | signal.signal(signal.SIGPIPE, signal.SIG_IGN) 49 | end 50 | 51 | function util.test() 52 | local f = io.tmpfile() 53 | f:write(("1234567890"):rep(4096)) 54 | f:seek("set") 55 | local str = util.fgets(128, f) 56 | print(str, #str) 57 | f:close() 58 | end 59 | -- util.test() 60 | 61 | return util 62 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.14.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/config.conf: -------------------------------------------------------------------------------- 1 | -- IPv4 2 | listen "0.0.0.0:8080" 3 | -- IPv6 4 | listen "::1:8080" 5 | 6 | -- set the user and group 7 | --user "www-data" 8 | --user ("www-data", "www-data") 9 | 10 | -- automatically reload the server when a servlet is modified 11 | reload "on" 12 | --reload "off" 13 | 14 | -- Lua 15 | load_module ("module.lua", {"lua", "luac"}) 16 | load_servlet "example/lua/hello.lua" 17 | load_servlet "example/lua/ping.lua" 18 | load_servlet "example/lua/file.lua" 19 | load_servlet "example/lua/empty.lua" 20 | load_servlet ("example/lua/iframe.lua", "/") 21 | load_servlet ("example/lua/arg.lua", "/arg") 22 | load_servlet ("example/lua/test-all.lua", "/test-all") 23 | 24 | -- Shared Object for any language that can export C symbols 25 | load_module ("module.so", "so") 26 | load_servlet "example/c/hello.c.so" 27 | load_servlet "example/c/test.c.so" 28 | load_servlet "example/c/sleep.c.so" 29 | load_servlet "example/c/arg.c.so" 30 | load_servlet "example/c/file.c.so" 31 | --load_servlet "example/c/segfault.c.so" 32 | load_servlet "example/c/content-length.c.so" 33 | load_servlet "example/c++/hello.cpp.so" 34 | load_servlet "example/crystal/hello.cr.so" 35 | load_servlet "example/crystal/test.cr.so" 36 | load_servlet "example/d/hello.d.so" 37 | load_servlet "example/d/test.d.so" 38 | load_servlet "example/go/hello.go.so" 39 | load_servlet "example/go/test.go.so" 40 | load_servlet "example/haskell/hello.hs.so" 41 | load_servlet "example/rust/hello.rs.so" 42 | load_servlet "example/rust/test.rs.so" 43 | load_servlet "example/nim/hello.nim.so" 44 | load_servlet "example/nim/test.nim.so" 45 | 46 | -- CGI 47 | load_module ("module.cgi", "cgi") 48 | load_servlet "example/cgi/hello.cgi" 49 | load_servlet "example/cgi/uptime.cgi" 50 | 51 | -- Python 52 | load_module ("module.python", "py") 53 | load_servlet "example/python/hello.py" 54 | load_servlet "example/python/time.py" 55 | load_servlet "example/python/test.py" 56 | 57 | -- Ruby 58 | load_module ("module.ruby", "rb") 59 | load_servlet "example/ruby/hello.rb" 60 | load_servlet "example/ruby/test.rb" 61 | 62 | -- Guile Scheme 63 | load_module ("module.guile", "scm") 64 | load_servlet "example/scheme/hello.scm" 65 | load_servlet "example/scheme/test.scm" 66 | -------------------------------------------------------------------------------- /src/api/rust/modserver.rs: -------------------------------------------------------------------------------- 1 | // Rust experts: please provide feedback if there is a better way to accomplish this. 2 | 3 | use std::ffi::{CStr, CString}; 4 | 5 | pub mod cmodserver; 6 | 7 | pub type Servlet = cmodserver::Servlet; 8 | 9 | pub fn get_arg(s: *mut cmodserver::Servlet, name: &str) -> Option { 10 | unsafe { 11 | let c_name = CString::new(name).unwrap(); 12 | let c_arg = cmodserver::get_arg(s, c_name.as_ptr()); 13 | if !c_arg.is_null() { 14 | let arg = CStr::from_ptr(c_arg); 15 | return Some(arg.to_string_lossy().into_owned()); 16 | } 17 | else { 18 | return None; 19 | } 20 | } 21 | } 22 | 23 | pub fn get_method(s: *mut cmodserver::Servlet) -> String { 24 | unsafe { 25 | let c_method = cmodserver::get_method(s); 26 | let method = CStr::from_ptr(c_method); 27 | return method.to_string_lossy().into_owned(); 28 | } 29 | } 30 | 31 | pub fn get_header(s: *mut cmodserver::Servlet, name: &str) -> Option { 32 | unsafe { 33 | let c_name = CString::new(name).unwrap(); 34 | let c_value = cmodserver::get_header(s, c_name.as_ptr()); 35 | if !c_value.is_null() { 36 | let value = CStr::from_ptr(c_value); 37 | return Some(value.to_string_lossy().into_owned()); 38 | } 39 | else { 40 | return None; 41 | } 42 | } 43 | } 44 | 45 | pub fn set_status(s: *mut cmodserver::Servlet, status: u32) { 46 | unsafe { 47 | cmodserver::set_status(s, status); 48 | } 49 | } 50 | 51 | pub fn set_header(s: *mut cmodserver::Servlet, name: &str, value: &str) { 52 | unsafe { 53 | let c_name = CString::new(name).unwrap(); 54 | let c_value = CString::new(value).unwrap(); 55 | cmodserver::set_header(s, c_name.as_ptr(), c_value.as_ptr()); 56 | } 57 | } 58 | 59 | pub fn rwrite(s: *mut cmodserver::Servlet, buffer: Vec) -> usize { 60 | unsafe { 61 | let length = buffer.len(); 62 | let c_buffer = CString::from_vec_unchecked(buffer); 63 | let ret = cmodserver::rwrite(s, c_buffer.as_ptr(), length); 64 | return ret; 65 | } 66 | } 67 | 68 | pub fn rflush(s: *mut cmodserver::Servlet) { 69 | unsafe { 70 | cmodserver::rflush(s); 71 | } 72 | } 73 | 74 | // https://doc.rust-lang.org/book/ffi.html 75 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/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 | line-height: 1.25 ; 15 | } 16 | 17 | h1, h2, h3, h4 { 18 | font-family: Verdana, Geneva, sans-serif ; 19 | font-weight: normal ; 20 | font-style: normal ; 21 | } 22 | 23 | h2 { 24 | padding-top: 0.4em ; 25 | padding-bottom: 0.4em ; 26 | padding-left: 0.8em ; 27 | padding-right: 0.8em ; 28 | background-color: #D0D0FF ; 29 | border-radius: 8px ; 30 | border: solid #a0a0a0 1px ; 31 | } 32 | 33 | h3 { 34 | padding-left: 0.5em ; 35 | border-left: solid #D0D0FF 1em ; 36 | } 37 | 38 | table h3 { 39 | padding-left: 0px ; 40 | border-left: none ; 41 | } 42 | 43 | a:link { 44 | color: #000080 ; 45 | background-color: inherit ; 46 | text-decoration: none ; 47 | } 48 | 49 | a:visited { 50 | background-color: inherit ; 51 | text-decoration: none ; 52 | } 53 | 54 | a:link:hover, a:visited:hover { 55 | color: #000080 ; 56 | background-color: #D0D0FF ; 57 | border-radius: 4px ; 58 | } 59 | 60 | a:link:active, a:visited:active { 61 | color: #FF0000 ; 62 | } 63 | 64 | h1 a img { 65 | vertical-align: text-bottom ; 66 | } 67 | 68 | hr { 69 | border: 0 ; 70 | height: 1px ; 71 | color: #a0a0a0 ; 72 | background-color: #a0a0a0 ; 73 | display: none ; 74 | } 75 | 76 | table hr { 77 | display: block ; 78 | } 79 | 80 | :target { 81 | background-color: #F8F8F8 ; 82 | padding: 8px ; 83 | border: solid #a0a0a0 2px ; 84 | border-radius: 8px ; 85 | } 86 | 87 | .footer { 88 | color: gray ; 89 | font-size: x-small ; 90 | } 91 | 92 | input[type=text] { 93 | border: solid #a0a0a0 2px ; 94 | border-radius: 2em ; 95 | background-image: url('images/search.png') ; 96 | background-repeat: no-repeat ; 97 | background-position: 4px center ; 98 | padding-left: 20px ; 99 | height: 2em ; 100 | } 101 | 102 | pre.session { 103 | background-color: #F8F8F8 ; 104 | padding: 1em ; 105 | border-radius: 8px ; 106 | } 107 | -------------------------------------------------------------------------------- /src/api/lua/modserver.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | The servlet API is written in Lua. A C API that calls the Lua API is provided for use by 3 | languages that can call C. Additional API wrappers are available for other languages. 4 | --]] 5 | local api = {} 6 | 7 | local http = require("http") 8 | 9 | function api:get_arg(name) 10 | return self.request.query[name] 11 | end 12 | 13 | function api:get_method() 14 | return self.request.method 15 | end 16 | 17 | function api:set_status(status) 18 | self.status = status 19 | end 20 | 21 | function api:set_header(name, value) 22 | self.response_headers[name:lower()] = {name = name, value = value} 23 | end 24 | 25 | function api:get_header(name) 26 | return self.request.headers[name:lower()] 27 | end 28 | 29 | function api:write_status_line_and_headers() 30 | local file = self.clientfd_write 31 | http.write_status_line(file, self.status or 200) 32 | self:set_header("Server", "modserver") 33 | if not self.response_headers["content-length"] then 34 | self:set_header("Transfer-Encoding", "chunked") 35 | end 36 | if not self.response_headers["content-type"] then 37 | self:set_header("Content-Type", "text/html; charset=UTF-8") 38 | end 39 | if not self.response_headers["connection"] then 40 | self:set_header("Connection", "close") 41 | end 42 | http.write_headers(file, self.response_headers) 43 | assert(file:write("\r\n")) 44 | self.response_headers_written = true 45 | end 46 | 47 | local function api_rwrite(self, buffer) 48 | local file = self.clientfd_write 49 | if not self.response_headers_written then 50 | self:write_status_line_and_headers() 51 | end 52 | if self:get_method() == "HEAD" then 53 | return #buffer 54 | end 55 | if not self.response_headers["content-length"] then 56 | return http.write_chunk(file, buffer) 57 | else 58 | if assert(file:write(buffer)) then 59 | return #buffer 60 | end 61 | end 62 | end 63 | 64 | function api:rwrite(buffer) 65 | local ok, ret, errstr, errnum = pcall(api_rwrite, self, buffer) 66 | if ok then 67 | return #buffer 68 | end 69 | return ret, errstr, errnum 70 | end 71 | 72 | function api:rflush() 73 | local file = self.clientfd_write 74 | file:flush() 75 | end 76 | 77 | return api 78 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/utsname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Get System Identification. 14 | 15 | @module posix.sys.utsname 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | 25 | /*** 26 | System identification record. 27 | @table utsname 28 | @string machine hardware platform name 29 | @string nodename network node name 30 | @string release operating system release level 31 | @string sysname operating system name 32 | @string version operating system version 33 | */ 34 | 35 | static int 36 | pushutsname(lua_State *L, struct utsname *u) 37 | { 38 | if (!u) 39 | return lua_pushnil(L), 1; 40 | 41 | lua_createtable(L, 0, 5); 42 | setstringfield(u, machine); 43 | setstringfield(u, nodename); 44 | setstringfield(u, release); 45 | setstringfield(u, sysname); 46 | setstringfield(u, version); 47 | 48 | settypemetatable("PosixUtsname"); 49 | return 1; 50 | } 51 | 52 | 53 | /*** 54 | Return information about this machine. 55 | @function uname 56 | @treturn[1] utsname system information 57 | @return[2] nil 58 | @treturn[2] string error message 59 | @treturn[2] int errnum 60 | @see uname(2) 61 | */ 62 | static int 63 | Puname(lua_State *L) 64 | { 65 | struct utsname u; 66 | checknargs(L, 0); 67 | if (uname(&u)==-1) 68 | return pusherror(L, "uname"); 69 | return pushutsname(L, &u); 70 | } 71 | 72 | 73 | static const luaL_Reg posix_sys_utsname_fns[] = 74 | { 75 | LPOSIX_FUNC( Puname ), 76 | {NULL, NULL} 77 | }; 78 | 79 | 80 | LUALIB_API int 81 | luaopen_posix_sys_utsname(lua_State *L) 82 | { 83 | luaL_register(L, "posix.sys.utsname", posix_sys_utsname_fns); 84 | lua_pushliteral(L, "posix.sys.utsname for " LUA_VERSION " / " PACKAGE_STRING); 85 | lua_setfield(L, -2, "version"); 86 | 87 | return 1; 88 | } 89 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.11.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /src/dep/luaposix/libgen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | General Library. 14 | 15 | Functions for separating a pathname into file and directory components. 16 | 17 | @module posix.libgen 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "_helpers.c" 25 | 26 | 27 | /*** 28 | File part of path. 29 | @function basename 30 | @string path file to act on 31 | @treturn string filename part of *path* 32 | @see basename(3) 33 | */ 34 | static int 35 | Pbasename(lua_State *L) 36 | { 37 | char *b; 38 | size_t len; 39 | void *ud; 40 | lua_Alloc lalloc; 41 | const char *path = luaL_checklstring(L, 1, &len); 42 | size_t path_len; 43 | checknargs(L, 1); 44 | path_len = strlen(path) + 1; 45 | lalloc = lua_getallocf(L, &ud); 46 | if ((b = lalloc(ud, NULL, 0, path_len)) == NULL) 47 | return pusherror(L, "lalloc"); 48 | lua_pushstring(L, basename(strcpy(b,path))); 49 | lalloc(ud, b, path_len, 0); 50 | return 1; 51 | } 52 | 53 | 54 | /*** 55 | Directory name of path. 56 | @function dirname 57 | @string path file to act on 58 | @treturn string directory part of *path* 59 | @see dirname(3) 60 | */ 61 | static int 62 | Pdirname(lua_State *L) 63 | { 64 | char *b; 65 | size_t len; 66 | void *ud; 67 | lua_Alloc lalloc; 68 | const char *path = luaL_checklstring(L, 1, &len); 69 | size_t path_len; 70 | checknargs(L, 1); 71 | path_len = strlen(path) + 1; 72 | lalloc = lua_getallocf(L, &ud); 73 | if ((b = lalloc(ud, NULL, 0, path_len)) == NULL) 74 | return pusherror(L, "lalloc"); 75 | lua_pushstring(L, dirname(strcpy(b,path))); 76 | lalloc(ud, b, path_len, 0); 77 | return 1; 78 | } 79 | 80 | 81 | static const luaL_Reg posix_libgen_fns[] = 82 | { 83 | LPOSIX_FUNC( Pbasename ), 84 | LPOSIX_FUNC( Pdirname ), 85 | {NULL, NULL} 86 | }; 87 | 88 | 89 | LUALIB_API int 90 | luaopen_posix_libgen(lua_State *L) 91 | { 92 | luaL_register(L, "posix.libgen", posix_libgen_fns); 93 | lua_pushliteral(L, "posix.libgen for " LUA_VERSION " / " PACKAGE_STRING); 94 | lua_setfield(L, -2, "version"); 95 | 96 | return 1; 97 | } 98 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/times.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Process Times. 14 | 15 | @module posix.sys.times 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | #define pushtimefield(k,x) pushintegerfield((k), ((lua_Integer)x)/clk_tck) 25 | 26 | /*** 27 | Process times record. 28 | All times are measured in cpu seconds. 29 | @table PosixTms 30 | @int tms_utime time spent executing user instructions 31 | @int tms_stime time spent in system execution 32 | @int tms_cutime sum of *tms_utime* for calling process and its children 33 | @int tms_cstime sum of *tms_stime* for calling process and its children 34 | */ 35 | static int 36 | pushtms(lua_State *L) 37 | { 38 | static long clk_tck = 0; 39 | 40 | struct tms t; 41 | clock_t elapsed = times(&t); 42 | 43 | if (elapsed == (clock_t) -1) 44 | return pusherror(L, "times"); 45 | 46 | if (clk_tck == 0) 47 | clk_tck = sysconf(_SC_CLK_TCK); 48 | 49 | lua_createtable(L, 0, 5); 50 | 51 | /* record elapsed time, and save accounting to struct */ 52 | pushtimefield("elapsed", elapsed); 53 | 54 | /* record struct entries */ 55 | pushtimefield("tms_utime", t.tms_utime); 56 | pushtimefield("tms_stime", t.tms_stime); 57 | pushtimefield("tms_cutime", t.tms_cutime); 58 | pushtimefield("tms_cstime", t.tms_cstime); 59 | 60 | settypemetatable("PosixTms"); 61 | return 1; 62 | } 63 | 64 | /*** 65 | Get the current process times. 66 | @function times 67 | @treturn[1] PosixTms time accounting for this process, if successful 68 | @return[2] nil 69 | @treturn[2] string error message 70 | @treturn[2] int errnum 71 | @see times(2) 72 | */ 73 | static int 74 | Ptimes(lua_State *L) 75 | { 76 | checknargs(L, 0); 77 | return pushtms(L); 78 | } 79 | 80 | 81 | static const luaL_Reg posix_sys_times_fns[] = 82 | { 83 | LPOSIX_FUNC( Ptimes ), 84 | {NULL, NULL} 85 | }; 86 | 87 | 88 | LUALIB_API int 89 | luaopen_posix_sys_times(lua_State *L) 90 | { 91 | luaL_register(L, "posix.sys.times", posix_sys_times_fns); 92 | lua_pushliteral(L, "posix.sys.times for " LUA_VERSION " / " PACKAGE_STRING); 93 | lua_setfield(L, -2, "version"); 94 | 95 | return 1; 96 | } 97 | -------------------------------------------------------------------------------- /src/dep/luaposix/fnmatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Filename matching. 14 | 15 | Functions and constants for matching known filenames against shell-style 16 | pattern strings. 17 | 18 | @see posix.glob 19 | @module posix.fnmatch 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "_helpers.c" 27 | 28 | 29 | /*** 30 | Match a filename against a shell pattern. 31 | @function fnmatch 32 | @string pat shell pattern 33 | @string name filename 34 | @int[opt=0] flags optional 35 | @treturn[1] int `0`, if successful 36 | @treturn[2] int `FNM_NOMATCH` 37 | @treturn[3] int some other non-zero integer if fnmatch itself failed 38 | @see fnmatch(3) 39 | */ 40 | static int 41 | Pfnmatch(lua_State *L) 42 | { 43 | const char *pattern = luaL_checkstring(L, 1); 44 | const char *string = luaL_checkstring(L, 2); 45 | int flags = optint(L, 3, 0); 46 | int res; 47 | checknargs(L, 3); 48 | return pushintresult(fnmatch(pattern, string, flags)); 49 | } 50 | 51 | 52 | static const luaL_Reg posix_fnmatch_fns[] = 53 | { 54 | LPOSIX_FUNC( Pfnmatch ), 55 | {NULL, NULL} 56 | }; 57 | 58 | 59 | /*** 60 | Constants. 61 | @section constants 62 | */ 63 | 64 | /*** 65 | Fnmatch constants. 66 | Any constants not available in the underlying system will be `nil` valued. 67 | @table posix.fnmatch 68 | @int FNM_PATHNAME slashes in pathname must be matched by slash in pattern 69 | @int FNM_NOESCAPE disable backslash escaping 70 | @int FNM_NOMATCH match failed 71 | @int FNM_PERIOD periods in pathname must be matched by period in pattern 72 | @usage 73 | -- Print fnmatch constants supported on this host. 74 | for name, value in pairs (require "posix.fnmatch") do 75 | if type (value) == "number" then 76 | print (name, value) 77 | end 78 | end 79 | */ 80 | 81 | LUALIB_API int 82 | luaopen_posix_fnmatch(lua_State *L) 83 | { 84 | luaL_register(L, "posix.fnmatch", posix_fnmatch_fns); 85 | lua_pushliteral(L, "posix.fnmatch for " LUA_VERSION " / " PACKAGE_STRING); 86 | lua_setfield(L, -2, "version"); 87 | 88 | /* from fnmatch.h */ 89 | LPOSIX_CONST( FNM_PATHNAME ); 90 | LPOSIX_CONST( FNM_NOESCAPE ); 91 | LPOSIX_CONST( FNM_NOMATCH ); 92 | LPOSIX_CONST( FNM_PERIOD ); 93 | 94 | return 1; 95 | } 96 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.13 2011/11/16 17:16:53 lhf Exp $ 2 | .TH LUA 1 "$Date: 2011/11/16 17:16:53 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the standalone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | The given 29 | .I options 30 | are handled in order and then 31 | the Lua program in file 32 | .I script 33 | is loaded and executed. 34 | The given 35 | .I args 36 | are available to 37 | .I script 38 | as strings in a global table named 39 | .BR arg . 40 | If no options or arguments are given, 41 | then 42 | .B "\-v \-i" 43 | is assumed when the standard input is a terminal; 44 | otherwise, 45 | .B "\-" 46 | is assumed. 47 | .LP 48 | In interactive mode, 49 | .B lua 50 | prompts the user, 51 | reads lines from the standard input, 52 | and executes them as they are read. 53 | If a line does not contain a complete statement, 54 | then a secondary prompt is displayed and 55 | lines are read until a complete statement is formed or 56 | a syntax error is found. 57 | If a line starts with 58 | .BR '=' , 59 | then 60 | .B lua 61 | evaluates and displays 62 | the values of the expressions in the remainder of the line. 63 | .LP 64 | At the very start, 65 | before even handling the command line, 66 | .B lua 67 | checks the contents of the environment variables 68 | .B LUA_INIT_5_2 69 | or 70 | .BR LUA_INIT , 71 | in that order. 72 | If the contents is of the form 73 | .RI '@ filename ', 74 | then 75 | .I filename 76 | is executed. 77 | Otherwise, the string is assumed to be a Lua statement and is executed. 78 | .SH OPTIONS 79 | .TP 80 | .BI \-e " stat" 81 | execute statement 82 | .IR stat . 83 | .TP 84 | .B \-i 85 | enter interactive mode after executing 86 | .IR script . 87 | .TP 88 | .BI \-l " name" 89 | execute the equivalent of 90 | .IB name =require(' name ') 91 | before executing 92 | .IR script . 93 | .TP 94 | .B \-v 95 | show version information. 96 | .TP 97 | .B \-E 98 | ignore environment variables. 99 | .TP 100 | .B \-\- 101 | stop handling options. 102 | .TP 103 | .B \- 104 | stop handling options and execute the standard input as a file. 105 | .SH "SEE ALSO" 106 | .BR luac (1) 107 | .br 108 | The documentation at lua.org, 109 | especially section 7 of the reference manual. 110 | .SH DIAGNOSTICS 111 | Error messages should be self explanatory. 112 | .SH AUTHORS 113 | R. Ierusalimschy, 114 | L. H. de Figueiredo, 115 | W. Celes 116 | .\" EOF 117 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/wait.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Wait for Process Termination. 14 | 15 | @module posix.sys.wait 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | 25 | /*** 26 | Wait for child process to terminate. 27 | @function wait 28 | @int[opt=-1] pid child process id to wait for, or -1 for any child process 29 | @int[opt] options bitwise OR of `WNOHANG` and `WUNTRACED` 30 | @treturn[1] int pid of terminated child, if successful 31 | @treturn[1] string "exited", "killed" or "stopped" 32 | @treturn[1] int exit status, or signal number responsible for "killed" or "stopped" 33 | @return[2] nil 34 | @treturn[2] string error message 35 | @treturn[2] int errnum 36 | @see waitpid(2) 37 | @see posix.unistd.fork 38 | */ 39 | static int 40 | Pwait(lua_State *L) 41 | { 42 | int status = 0; 43 | pid_t pid = optint(L, 1, -1); 44 | int options = optint(L, 2, 0); 45 | checknargs(L, 2); 46 | 47 | pid = waitpid(pid, &status, options); 48 | if (pid == -1) 49 | return pusherror(L, NULL); 50 | lua_pushinteger(L, pid); 51 | if (WIFEXITED(status)) 52 | { 53 | lua_pushliteral(L,"exited"); 54 | lua_pushinteger(L, WEXITSTATUS(status)); 55 | return 3; 56 | } 57 | else if (WIFSIGNALED(status)) 58 | { 59 | lua_pushliteral(L,"killed"); 60 | lua_pushinteger(L, WTERMSIG(status)); 61 | return 3; 62 | } 63 | else if (WIFSTOPPED(status)) 64 | { 65 | lua_pushliteral(L,"stopped"); 66 | lua_pushinteger(L, WSTOPSIG(status)); 67 | return 3; 68 | } 69 | return 1; 70 | } 71 | 72 | 73 | static const luaL_Reg posix_sys_wait_fns[] = 74 | { 75 | LPOSIX_FUNC( Pwait ), 76 | {NULL, NULL} 77 | }; 78 | 79 | 80 | /*** 81 | Constants. 82 | @section constants 83 | */ 84 | 85 | /*** 86 | Wait constants. 87 | Any constants not available in the underlying system will be `nil` valued. 88 | @table posix.sys.wait 89 | @int WNOHANG don't block waiting 90 | @int WUNTRACED report status of stopped children 91 | @usage 92 | -- Print wait constants supported on this host. 93 | for name, value in pairs (require "posix.sys.wait") do 94 | if type (value) == "number" then 95 | print (name, value) 96 | end 97 | end 98 | */ 99 | 100 | LUALIB_API int 101 | luaopen_posix_sys_wait(lua_State *L) 102 | { 103 | luaL_register(L, "posix.sys.wait", posix_sys_wait_fns); 104 | lua_pushliteral(L, "posix.sys.wait for " LUA_VERSION " / " PACKAGE_STRING); 105 | lua_setfield(L, -2, "version"); 106 | 107 | LPOSIX_CONST( WNOHANG ); 108 | LPOSIX_CONST( WUNTRACED ); 109 | 110 | return 1; 111 | } 112 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.84.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lgc.h" 18 | #include "lmem.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | 22 | 23 | 24 | /* 25 | ** About the realloc function: 26 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 27 | ** (`osize' is the old size, `nsize' is the new size) 28 | ** 29 | ** * frealloc(ud, NULL, x, s) creates a new block of size `s' (no 30 | ** matter 'x'). 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL); 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *what) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | l_noret luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | } 69 | 70 | 71 | 72 | /* 73 | ** generic allocation routine. 74 | */ 75 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 76 | void *newblock; 77 | global_State *g = G(L); 78 | size_t realosize = (block) ? osize : 0; 79 | lua_assert((realosize == 0) == (block == NULL)); 80 | #if defined(HARDMEMTESTS) 81 | if (nsize > realosize && g->gcrunning) 82 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 83 | #endif 84 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 85 | if (newblock == NULL && nsize > 0) { 86 | api_check(L, nsize > realosize, 87 | "realloc cannot fail when shrinking a block"); 88 | if (g->gcrunning) { 89 | luaC_fullgc(L, 1); /* try to free some memory... */ 90 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 91 | } 92 | if (newblock == NULL) 93 | luaD_throw(L, LUA_ERRMEM); 94 | } 95 | lua_assert((nsize == 0) == (newblock == NULL)); 96 | g->GCdebt = (g->GCdebt + nsize) - realosize; 97 | return newblock; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/dep/luaposix/strlcpy_.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef LUAPOSIX_STRLCPY_C 31 | #define LUAPOSIX_STRLCPY_C 1 32 | 33 | #include 34 | 35 | #ifndef HAVE_STRLCPY 36 | 37 | #if defined LIBC_SCCS && ! defined lint 38 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; 39 | #endif /* LIBC_SCCS and not lint */ 40 | 41 | #include 42 | #include 43 | 44 | static size_t strlcpy_(char *dst, const char *src, size_t siz); 45 | 46 | /* 47 | * Copy src to string dst of size siz. At most siz-1 characters 48 | * will be copied. Always NUL terminates (unless siz == 0). 49 | * Returns strlen(src); if retval >= siz, truncation occurred. 50 | */ 51 | static size_t strlcpy_(char *dst, const char *src, size_t siz) 52 | { 53 | register char *d = dst; 54 | register const char *s = src; 55 | register size_t n = siz; 56 | 57 | /* Copy as many bytes as will fit */ 58 | if (n != 0 && --n != 0) { 59 | do { 60 | if ((*d++ = *s++) == 0) 61 | break; 62 | } while (--n != 0); 63 | } 64 | 65 | /* Not enough room in dst, add NUL and traverse rest of src */ 66 | if (n == 0) { 67 | if (siz != 0) 68 | *d = '\0'; /* NUL-terminate dst */ 69 | while (*s++) 70 | ; 71 | } 72 | 73 | return(s - src - 1); /* count does not include NUL */ 74 | } 75 | 76 | #endif /* !HAVE_STRLCPY */ 77 | 78 | #endif /* !LUAPOSIX_STRLCPY_C */ 79 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.58.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_EQ, OPR_LT, OPR_LE, 30 | OPR_NE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 46 | 47 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 48 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 49 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 50 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 51 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 52 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 53 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 54 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 55 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 56 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 59 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 60 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 61 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 62 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 63 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 64 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 66 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 67 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 68 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 69 | LUAI_FUNC int luaK_jump (FuncState *fs); 70 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 71 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 72 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 73 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 74 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 75 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 76 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 77 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 78 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 79 | expdesc *v2, int line); 80 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 81 | 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/dep/lpeg/HISTORY: -------------------------------------------------------------------------------- 1 | HISTORY for LPeg 1.0 2 | 3 | * Changes from version 0.12 to 1.0 4 | --------------------------------- 5 | + group "names" can be any Lua value 6 | + some bugs fixed 7 | + other small improvements 8 | 9 | * Changes from version 0.11 to 0.12 10 | --------------------------------- 11 | + no "unsigned short" limit for pattern sizes 12 | + mathtime captures considered nullable 13 | + some bugs fixed 14 | 15 | * Changes from version 0.10 to 0.11 16 | ------------------------------- 17 | + complete reimplementation of the code generator 18 | + new syntax for table captures 19 | + new functions in module 're' 20 | + other small improvements 21 | 22 | * Changes from version 0.9 to 0.10 23 | ------------------------------- 24 | + backtrack stack has configurable size 25 | + better error messages 26 | + Notation for non-terminals in 're' back to A instead o 27 | + experimental look-behind pattern 28 | + support for external extensions 29 | + works with Lua 5.2 30 | + consumes less C stack 31 | 32 | - "and" predicates do not keep captures 33 | 34 | * Changes from version 0.8 to 0.9 35 | ------------------------------- 36 | + The accumulator capture was replaced by a fold capture; 37 | programs that used the old 'lpeg.Ca' will need small changes. 38 | + Some support for character classes from old C locales. 39 | + A new named-group capture. 40 | 41 | * Changes from version 0.7 to 0.8 42 | ------------------------------- 43 | + New "match-time" capture. 44 | + New "argument capture" that allows passing arguments into the pattern. 45 | + Better documentation for 're'. 46 | + Several small improvements for 're'. 47 | + The 're' module has an incompatibility with previous versions: 48 | now, any use of a non-terminal must be enclosed in angle brackets 49 | (like ). 50 | 51 | * Changes from version 0.6 to 0.7 52 | ------------------------------- 53 | + Several improvements in module 're': 54 | - better documentation; 55 | - support for most captures (all but accumulator); 56 | - limited repetitions p{n,m}. 57 | + Small improvements in efficiency. 58 | + Several small bugs corrected (special thanks to Hans Hagen 59 | and Taco Hoekwater). 60 | 61 | * Changes from version 0.5 to 0.6 62 | ------------------------------- 63 | + Support for non-numeric indices in grammars. 64 | + Some bug fixes (thanks to the luatex team). 65 | + Some new optimizations; (thanks to Mike Pall). 66 | + A new page layout (thanks to Andre Carregal). 67 | + Minimal documentation for module 're'. 68 | 69 | * Changes from version 0.4 to 0.5 70 | ------------------------------- 71 | + Several optimizations. 72 | + lpeg.P now accepts booleans. 73 | + Some new examples. 74 | + A proper license. 75 | + Several small improvements. 76 | 77 | * Changes from version 0.3 to 0.4 78 | ------------------------------- 79 | + Static check for loops in repetitions and grammars. 80 | + Removed label option in captures. 81 | + The implementation of captures uses less memory. 82 | 83 | * Changes from version 0.2 to 0.3 84 | ------------------------------- 85 | + User-defined patterns in Lua. 86 | + Several new captures. 87 | 88 | * Changes from version 0.1 to 0.2 89 | ------------------------------- 90 | + Several small corrections. 91 | + Handles embedded zeros like any other character. 92 | + Capture "name" can be any Lua value. 93 | + Unlimited number of captures. 94 | + Match gets an optional initial position. 95 | 96 | (end of HISTORY) 97 | -------------------------------------------------------------------------------- /src/dep/luaposix/dirent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Directory Iterators. 14 | 15 | @module posix.dirent 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | 25 | /*** 26 | Contents of directory. 27 | @function dir 28 | @string[opt="."] path directory to act on 29 | @treturn table contents of *path* 30 | @see dir.lua 31 | */ 32 | static int 33 | Pdir(lua_State *L) 34 | { 35 | const char *path = optstring(L, 1, "."); 36 | DIR *d; 37 | checknargs(L, 1); 38 | d = opendir(path); 39 | /* Throw an argument error for consistency with eg. io.lines */ 40 | if (d == NULL) 41 | { 42 | const char *msg = strerror (errno); 43 | msg = lua_pushfstring(L, "%s: %s", path, msg); 44 | return luaL_argerror(L, 1, msg); 45 | } 46 | else 47 | { 48 | int i; 49 | struct dirent *entry; 50 | lua_newtable(L); 51 | for (i=1; (entry = readdir(d)) != NULL; i++) 52 | { 53 | lua_pushstring(L, entry->d_name); 54 | lua_rawseti(L, -2, i); 55 | } 56 | closedir(d); 57 | lua_pushinteger(L, i-1); 58 | return 2; 59 | } 60 | } 61 | 62 | 63 | static int 64 | aux_files(lua_State *L) 65 | { 66 | DIR **p = (DIR **)lua_touserdata(L, lua_upvalueindex(1)); 67 | DIR *d = *p; 68 | struct dirent *entry; 69 | if (d == NULL) 70 | return 0; 71 | entry = readdir(d); 72 | if (entry == NULL) 73 | { 74 | closedir(d); 75 | *p=NULL; 76 | return 0; 77 | } 78 | return pushstringresult(entry->d_name); 79 | } 80 | 81 | 82 | static int 83 | dir_gc (lua_State *L) 84 | { 85 | DIR *d = *(DIR **)lua_touserdata(L, 1); 86 | if (d!=NULL) 87 | closedir(d); 88 | return 0; 89 | } 90 | 91 | 92 | /*** 93 | Iterator over all files in named directory. 94 | @function files 95 | @string[opt="."] path directory to act on 96 | @return an iterator 97 | */ 98 | static int 99 | Pfiles(lua_State *L) 100 | { 101 | const char *path = optstring(L, 1, "."); 102 | DIR **d; 103 | checknargs(L, 1); 104 | d = (DIR **)lua_newuserdata(L, sizeof(DIR *)); 105 | *d = opendir(path); 106 | /* Throw an argument error for consistency with eg. io.lines */ 107 | if (*d == NULL) 108 | { 109 | const char *msg = strerror (errno); 110 | msg = lua_pushfstring(L, "%s: %s", path, msg); 111 | return luaL_argerror(L, 1, msg); 112 | } 113 | if (luaL_newmetatable(L, PACKAGE_NAME " dir handle")) 114 | { 115 | lua_pushcfunction(L, dir_gc); 116 | lua_setfield(L, -2, "__gc"); 117 | } 118 | lua_setmetatable(L, -2); 119 | lua_pushcclosure(L, aux_files, 1); 120 | return 1; 121 | } 122 | 123 | 124 | static const luaL_Reg posix_dirent_fns[] = 125 | { 126 | LPOSIX_FUNC( Pdir ), 127 | LPOSIX_FUNC( Pfiles ), 128 | {NULL, NULL} 129 | }; 130 | 131 | 132 | LUALIB_API int 133 | luaopen_posix_dirent(lua_State *L) 134 | { 135 | luaL_register(L, "posix.dirent", posix_dirent_fns); 136 | lua_pushliteral(L, "posix.dirent for " LUA_VERSION " / " PACKAGE_STRING); 137 | lua_setfield(L, -2, "version"); 138 | 139 | return 1; 140 | } 141 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define lopcodes_c 9 | #define LUA_CORE 10 | 11 | 12 | #include "lopcodes.h" 13 | 14 | 15 | /* ORDER OP */ 16 | 17 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 18 | "MOVE", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADBOOL", 22 | "LOADNIL", 23 | "GETUPVAL", 24 | "GETTABUP", 25 | "GETTABLE", 26 | "SETTABUP", 27 | "SETUPVAL", 28 | "SETTABLE", 29 | "NEWTABLE", 30 | "SELF", 31 | "ADD", 32 | "SUB", 33 | "MUL", 34 | "DIV", 35 | "MOD", 36 | "POW", 37 | "UNM", 38 | "NOT", 39 | "LEN", 40 | "CONCAT", 41 | "JMP", 42 | "EQ", 43 | "LT", 44 | "LE", 45 | "TEST", 46 | "TESTSET", 47 | "CALL", 48 | "TAILCALL", 49 | "RETURN", 50 | "FORLOOP", 51 | "FORPREP", 52 | "TFORCALL", 53 | "TFORLOOP", 54 | "SETLIST", 55 | "CLOSURE", 56 | "VARARG", 57 | "EXTRAARG", 58 | NULL 59 | }; 60 | 61 | 62 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 63 | 64 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 65 | /* T A B C mode opcode */ 66 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 67 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 68 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 69 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 70 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 71 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 72 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 73 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 74 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 75 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 76 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 77 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 78 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 82 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 83 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 84 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 85 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 86 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 87 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 88 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 89 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 90 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 91 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 92 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 93 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 94 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 95 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 96 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 97 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 98 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 99 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 100 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 102 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 103 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 104 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 105 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 106 | }; 107 | 108 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | `modserver` is an HTTP/1.1 application server. Applications are loaded at runtime from a 2 | configuration file. The server exports an API for use by applications to interpret 3 | requests and generate responses. Modules provide support for loading applications written 4 | in a variety of programming languages. 5 | 6 | Here is an example application that writes a message to the user using the C API: 7 | ``` 8 | #include "modserver.h" 9 | 10 | int run(servlet *s) 11 | { 12 | rprintf(s, "hello from C"); 13 | return 0; 14 | } 15 | ``` 16 | 17 | ## Building 18 | `modserver` builds on at least the following platforms: DragonFly BSD, FreeBSD, 19 | GNU/Linux, illumos, Mac OS X, NetBSD, and OpenBSD. Run `make` or `gmake` depending on the 20 | platform. 21 | 22 | Individual modules may fail to build if their dependencies are not found. This is normal 23 | and does not affect the building of the server. Read the [Makefile](src/Makefile) to get 24 | a sense for what is required to build each module. 25 | 26 | ## Dependencies 27 | - A C compiler supporting C99. 28 | - An operating system supporting POSIX.1-2001. 29 | - [Lua](https://www.lua.org/) 30 | - [luaposix](https://github.com/luaposix/luaposix) 31 | - [luastatic](https://github.com/ers35/luastatic) 32 | - [LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/) 33 | 34 | A copy of all build dependencies are included in source form in the [dep](src/dep/) 35 | directory. Modules may require additional dependencies. 36 | 37 | ## Usage 38 | `modserver config.conf` 39 | 40 | ## Configuration 41 | See [config.conf](src/config.conf) for an example configuration file and 42 | [config.lua](src/config.lua) for the available configuration options. 43 | 44 | The server listens on port 8080 by default: http://127.0.0.1:8080/ 45 | 46 | ## API 47 | The C API is documented in [modserver.h](src/api/c/modserver.h). 48 | 49 | See the [api](src/api/) directory for bindings for other languages. 50 | 51 | ## Languages 52 | There are example hello world applications in a variety of programming languages: 53 | - [C](src/example/c/hello.c) 54 | - [C++](src/example/c++/hello.cpp) 55 | - [Crystal](src/example/crystal/hello.cr) 56 | - [CGI](src/example/cgi/hello.cgi) 57 | - [D](src/example/d/hello.d) 58 | - [Go](src/example/go/hello.go) 59 | - [Haskell](src/example/haskell/hello.hs) 60 | - [Lua](src/example/lua/hello.lua) 61 | - [Nim](src/example/nim/hello.nim) 62 | - [Python](src/example/python/hello.py) 63 | - [Ruby](src/example/ruby/hello.rb) 64 | - [Rust](src/example/rust/hello.rs) 65 | - [Scheme](src/example/scheme/hello.scm) 66 | 67 | See the [module](src/module/) directory to learn how to add support for another 68 | language. 69 | 70 | ## Design 71 | The design is a traditional forking server. Each concurrent request is handled by a 72 | separate process. A new process is created when all processes are busy handling a 73 | request. A process handles many requests to avoid the overhead of forking on each 74 | request. An idle process exits after five seconds to free its resources. 75 | 76 | Applications are free to use blocking I/O because the operating system schedules the 77 | processes. A crash while handling a request does not affect other requests. The server 78 | reports the crash and continues running. One tradeoff with this design is the memory 79 | usage increases with the number of concurrent requests as more processes are created. 80 | 81 | ## Feedback 82 | Email [eric@ers35.com](mailto:eric@ers35.com) or post a GitHub issue to give feedback. 83 | 84 | ## Known Issues 85 | - Go servlets panic on Mac OS X. 86 | - Go servlets sometimes deadlock on runtime.futexsleep. 87 | - Ruby servlets sometimes crash. 88 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files containing precompiled chunks 17 | that can be later loaded and executed. 18 | .LP 19 | The main advantages of precompiling chunks are: 20 | faster loading, 21 | protecting source code from accidental user changes, 22 | and 23 | off-line syntax checking. 24 | Precompiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | Precompiled chunks are not necessarily smaller than the corresponding source. 29 | The main goal in precompiling is faster loading. 30 | .LP 31 | In the command line, 32 | you can mix 33 | text files containing Lua source and 34 | binary files containing precompiled chunks. 35 | .B luac 36 | produces a single output file containing the combined bytecodes 37 | for all files given. 38 | Executing the combined file is equivalent to executing the given files. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | Precompiled chunks are 47 | .I not 48 | portable across different architectures. 49 | Moreover, 50 | the internal format of precompiled chunks 51 | is likely to change when a new version of Lua is released. 52 | Make sure you save the source files of all Lua programs that you precompile. 53 | .LP 54 | .SH OPTIONS 55 | .TP 56 | .B \-l 57 | produce a listing of the compiled bytecode for Lua's virtual machine. 58 | Listing bytecodes is useful to learn about Lua's virtual machine. 59 | If no files are given, then 60 | .B luac 61 | loads 62 | .B luac.out 63 | and lists its contents. 64 | Use 65 | .B \-l \-l 66 | for a full listing. 67 | .TP 68 | .BI \-o " file" 69 | output to 70 | .IR file , 71 | instead of the default 72 | .BR luac.out . 73 | (You can use 74 | .B "'\-'" 75 | for standard output, 76 | but not on platforms that open standard output in text mode.) 77 | The output file may be one of the given files because 78 | all files are loaded before the output file is written. 79 | Be careful not to overwrite precious files. 80 | .TP 81 | .B \-p 82 | load files but do not generate any output file. 83 | Used mainly for syntax checking and for testing precompiled chunks: 84 | corrupted files will probably generate errors when loaded. 85 | If no files are given, then 86 | .B luac 87 | loads 88 | .B luac.out 89 | and tests its contents. 90 | No messages are displayed if the file loads without errors. 91 | .TP 92 | .B \-s 93 | strip debug information before writing the output file. 94 | This saves some space in very large chunks, 95 | but if errors occur when running a stripped chunk, 96 | then the error messages may not contain the full information they usually do. 97 | In particular, 98 | line numbers and names of local variables are lost. 99 | .TP 100 | .B \-v 101 | show version information. 102 | .TP 103 | .B \-\- 104 | stop handling options. 105 | .TP 106 | .B \- 107 | stop handling options and process standard input. 108 | .SH "SEE ALSO" 109 | .BR lua (1) 110 | .br 111 | The documentation at lua.org. 112 | .SH DIAGNOSTICS 113 | Error messages should be self explanatory. 114 | .SH AUTHORS 115 | R. Ierusalimschy, 116 | L. H. de Figueiredo, 117 | W. Celes 118 | .\" EOF 119 | -------------------------------------------------------------------------------- /src/dep/lpeg/lptypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptypes.h,v 1.14 2015/09/28 17:17:41 roberto Exp $ 3 | ** LPeg - PEG pattern matching for Lua 4 | ** Copyright 2007-2015, Lua.org & PUC-Rio (see 'lpeg.html' for license) 5 | ** written by Roberto Ierusalimschy 6 | */ 7 | 8 | #if !defined(lptypes_h) 9 | #define lptypes_h 10 | 11 | 12 | #if !defined(LPEG_DEBUG) 13 | #define NDEBUG 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #include "lua.h" 20 | 21 | 22 | #define VERSION "1.0.0" 23 | 24 | 25 | #define PATTERN_T "lpeg-pattern" 26 | #define MAXSTACKIDX "lpeg-maxstack" 27 | 28 | 29 | /* 30 | ** compatibility with Lua 5.1 31 | */ 32 | #if (LUA_VERSION_NUM == 501) 33 | 34 | #define lp_equal lua_equal 35 | 36 | #define lua_getuservalue lua_getfenv 37 | #define lua_setuservalue lua_setfenv 38 | 39 | #define lua_rawlen lua_objlen 40 | 41 | #define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f) 42 | #define luaL_newlib(L,f) luaL_register(L,"lpeg",f) 43 | 44 | #endif 45 | 46 | 47 | #if !defined(lp_equal) 48 | #define lp_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) 49 | #endif 50 | 51 | 52 | /* default maximum size for call/backtrack stack */ 53 | #if !defined(MAXBACK) 54 | #define MAXBACK 400 55 | #endif 56 | 57 | 58 | /* maximum number of rules in a grammar */ 59 | #if !defined(MAXRULES) 60 | #define MAXRULES 1000 61 | #endif 62 | 63 | 64 | 65 | /* initial size for capture's list */ 66 | #define INITCAPSIZE 32 67 | 68 | 69 | /* index, on Lua stack, for subject */ 70 | #define SUBJIDX 2 71 | 72 | /* number of fixed arguments to 'match' (before capture arguments) */ 73 | #define FIXEDARGS 3 74 | 75 | /* index, on Lua stack, for capture list */ 76 | #define caplistidx(ptop) ((ptop) + 2) 77 | 78 | /* index, on Lua stack, for pattern's ktable */ 79 | #define ktableidx(ptop) ((ptop) + 3) 80 | 81 | /* index, on Lua stack, for backtracking stack */ 82 | #define stackidx(ptop) ((ptop) + 4) 83 | 84 | 85 | 86 | typedef unsigned char byte; 87 | 88 | 89 | #define BITSPERCHAR 8 90 | 91 | #define CHARSETSIZE ((UCHAR_MAX/BITSPERCHAR) + 1) 92 | 93 | 94 | 95 | typedef struct Charset { 96 | byte cs[CHARSETSIZE]; 97 | } Charset; 98 | 99 | 100 | 101 | #define loopset(v,b) { int v; for (v = 0; v < CHARSETSIZE; v++) {b;} } 102 | 103 | /* access to charset */ 104 | #define treebuffer(t) ((byte *)((t) + 1)) 105 | 106 | /* number of slots needed for 'n' bytes */ 107 | #define bytes2slots(n) (((n) - 1) / sizeof(TTree) + 1) 108 | 109 | /* set 'b' bit in charset 'cs' */ 110 | #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) 111 | 112 | 113 | /* 114 | ** in capture instructions, 'kind' of capture and its offset are 115 | ** packed in field 'aux', 4 bits for each 116 | */ 117 | #define getkind(op) ((op)->i.aux & 0xF) 118 | #define getoff(op) (((op)->i.aux >> 4) & 0xF) 119 | #define joinkindoff(k,o) ((k) | ((o) << 4)) 120 | 121 | #define MAXOFF 0xF 122 | #define MAXAUX 0xFF 123 | 124 | 125 | /* maximum number of bytes to look behind */ 126 | #define MAXBEHIND MAXAUX 127 | 128 | 129 | /* maximum size (in elements) for a pattern */ 130 | #define MAXPATTSIZE (SHRT_MAX - 10) 131 | 132 | 133 | /* size (in elements) for an instruction plus extra l bytes */ 134 | #define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1) 135 | 136 | 137 | /* size (in elements) for a ISet instruction */ 138 | #define CHARSETINSTSIZE instsize(CHARSETSIZE) 139 | 140 | /* size (in elements) for a IFunc instruction */ 141 | #define funcinstsize(p) ((p)->i.aux + 2) 142 | 143 | 144 | 145 | #define testchar(st,c) (((int)(st)[((c) >> 3)] & (1 << ((c) & 7)))) 146 | 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for installing Lua 2 | # See doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= none 8 | 9 | # Where to install. The installation starts in the src and doc directories, 10 | # so take care if INSTALL_TOP is not an absolute path. See the local target. 11 | # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with 12 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h. 13 | INSTALL_TOP= /usr/local 14 | INSTALL_BIN= $(INSTALL_TOP)/bin 15 | INSTALL_INC= $(INSTALL_TOP)/include 16 | INSTALL_LIB= $(INSTALL_TOP)/lib 17 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 18 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 19 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 20 | 21 | # How to install. If your install program does not support "-p", then 22 | # you may have to run ranlib on the installed liblua.a. 23 | INSTALL= install -p 24 | INSTALL_EXEC= $(INSTALL) -m 0755 25 | INSTALL_DATA= $(INSTALL) -m 0644 26 | # 27 | # If you don't have "install" you can use "cp" instead. 28 | # INSTALL= cp -p 29 | # INSTALL_EXEC= $(INSTALL) 30 | # INSTALL_DATA= $(INSTALL) 31 | 32 | # Other utilities. 33 | MKDIR= mkdir -p 34 | RM= rm -f 35 | 36 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 37 | 38 | # Convenience platforms targets. 39 | PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris 40 | 41 | # What to install. 42 | TO_BIN= lua luac 43 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp 44 | TO_LIB= liblua.a 45 | TO_MAN= lua.1 luac.1 46 | 47 | # Lua version and release. 48 | V= 5.2 49 | R= $V.4 50 | 51 | # Targets start here. 52 | all: $(PLAT) 53 | 54 | $(PLATS) clean: 55 | cd src && $(MAKE) $@ 56 | 57 | test: dummy 58 | src/lua -v 59 | 60 | install: dummy 61 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 62 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 63 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 64 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 65 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 66 | 67 | uninstall: 68 | cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) 69 | cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) 70 | cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) 71 | cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) 72 | 73 | local: 74 | $(MAKE) install INSTALL_TOP=../install 75 | 76 | none: 77 | @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" 78 | @echo " $(PLATS)" 79 | @echo "See doc/readme.html for complete instructions." 80 | 81 | # make may get confused with test/ and install/ 82 | dummy: 83 | 84 | # echo config parameters 85 | echo: 86 | @cd src && $(MAKE) -s echo 87 | @echo "PLAT= $(PLAT)" 88 | @echo "V= $V" 89 | @echo "R= $R" 90 | @echo "TO_BIN= $(TO_BIN)" 91 | @echo "TO_INC= $(TO_INC)" 92 | @echo "TO_LIB= $(TO_LIB)" 93 | @echo "TO_MAN= $(TO_MAN)" 94 | @echo "INSTALL_TOP= $(INSTALL_TOP)" 95 | @echo "INSTALL_BIN= $(INSTALL_BIN)" 96 | @echo "INSTALL_INC= $(INSTALL_INC)" 97 | @echo "INSTALL_LIB= $(INSTALL_LIB)" 98 | @echo "INSTALL_MAN= $(INSTALL_MAN)" 99 | @echo "INSTALL_LMOD= $(INSTALL_LMOD)" 100 | @echo "INSTALL_CMOD= $(INSTALL_CMOD)" 101 | @echo "INSTALL_EXEC= $(INSTALL_EXEC)" 102 | @echo "INSTALL_DATA= $(INSTALL_DATA)" 103 | 104 | # echo pkg-config data 105 | pc: 106 | @echo "version=$R" 107 | @echo "prefix=$(INSTALL_TOP)" 108 | @echo "libdir=$(INSTALL_LIB)" 109 | @echo "includedir=$(INSTALL_INC)" 110 | 111 | # list targets that do not create files (but not all makes understand .PHONY) 112 | .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho 113 | 114 | # (end of Makefile) 115 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VNONRELOC, /* info = result register */ 27 | VLOCAL, /* info = local register */ 28 | VUPVAL, /* info = index of upvalue in 'upvalues' */ 29 | VINDEXED, /* t = table register/upvalue; idx = index R/K */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VCALL, /* info = instruction pc */ 33 | VVARARG /* info = instruction pc */ 34 | } expkind; 35 | 36 | 37 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 38 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 39 | 40 | typedef struct expdesc { 41 | expkind k; 42 | union { 43 | struct { /* for indexed variables (VINDEXED) */ 44 | short idx; /* index (R/K) */ 45 | lu_byte t; /* table (register or upvalue) */ 46 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 47 | } ind; 48 | int info; /* for generic use */ 49 | lua_Number nval; /* for VKNUM */ 50 | } u; 51 | int t; /* patch list of `exit when true' */ 52 | int f; /* patch list of `exit when false' */ 53 | } expdesc; 54 | 55 | 56 | /* description of active local variable */ 57 | typedef struct Vardesc { 58 | short idx; /* variable index in stack */ 59 | } Vardesc; 60 | 61 | 62 | /* description of pending goto statements and label statements */ 63 | typedef struct Labeldesc { 64 | TString *name; /* label identifier */ 65 | int pc; /* position in code */ 66 | int line; /* line where it appeared */ 67 | lu_byte nactvar; /* local level where it appears in current block */ 68 | } Labeldesc; 69 | 70 | 71 | /* list of labels or gotos */ 72 | typedef struct Labellist { 73 | Labeldesc *arr; /* array */ 74 | int n; /* number of entries in use */ 75 | int size; /* array size */ 76 | } Labellist; 77 | 78 | 79 | /* dynamic structures used by the parser */ 80 | typedef struct Dyndata { 81 | struct { /* list of active local variables */ 82 | Vardesc *arr; 83 | int n; 84 | int size; 85 | } actvar; 86 | Labellist gt; /* list of pending gotos */ 87 | Labellist label; /* list of active labels */ 88 | } Dyndata; 89 | 90 | 91 | /* control of blocks */ 92 | struct BlockCnt; /* defined in lparser.c */ 93 | 94 | 95 | /* state needed to generate code for a given function */ 96 | typedef struct FuncState { 97 | Proto *f; /* current function header */ 98 | Table *h; /* table to find (and reuse) elements in `k' */ 99 | struct FuncState *prev; /* enclosing function */ 100 | struct LexState *ls; /* lexical state */ 101 | struct BlockCnt *bl; /* chain of current blocks */ 102 | int pc; /* next position to code (equivalent to `ncode') */ 103 | int lasttarget; /* 'label' of last 'jump label' */ 104 | int jpc; /* list of pending jumps to `pc' */ 105 | int nk; /* number of elements in `k' */ 106 | int np; /* number of elements in `p' */ 107 | int firstlocal; /* index of first local var (in Dyndata array) */ 108 | short nlocvars; /* number of elements in 'f->locvars' */ 109 | lu_byte nactvar; /* number of active local variables */ 110 | lu_byte nups; /* number of upvalues */ 111 | lu_byte freereg; /* first free register */ 112 | } FuncState; 113 | 114 | 115 | LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 116 | Dyndata *dyd, const char *name, int firstchar); 117 | 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/statvfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Retrieve File System Information. 14 | 15 | Where supported by the underlying system, query the file system. If the 16 | module loads, but there is no kernel support, then `posix.sys.statvfs.version` 17 | will be set, but the unsupported APIs will be `nil`. 18 | 19 | @module posix.sys.statvfs 20 | */ 21 | 22 | #include 23 | 24 | #if defined HAVE_STATVFS 25 | 26 | #include 27 | 28 | #include "_helpers.c" 29 | 30 | 31 | /*** 32 | Files system information record. 33 | @table PosixStatvfs 34 | @int f_bsize file system block size 35 | @int f_frsize fundamental file system block size 36 | @int f_blocks number of *f_frsize* sized blocks in file system 37 | @int f_bfree number of free blocks 38 | @int f_bavail number of free blocks available to non-privileged process 39 | @int f_files number of file serial numbers 40 | @int f_ffree number of free file serial numbers 41 | @int f_favail number of free file serial numbers available 42 | @int f_fsid file system id 43 | @int f_flag flag bits 44 | @int f_namemax maximum filename length 45 | */ 46 | static int 47 | pushstatvfs(lua_State *L, struct statvfs *sv) 48 | { 49 | if (!sv) 50 | return lua_pushnil(L), 1; 51 | 52 | lua_createtable(L, 0, 11); 53 | 54 | setintegerfield(sv, f_bsize); 55 | setintegerfield(sv, f_frsize); 56 | setintegerfield(sv, f_blocks); 57 | setintegerfield(sv, f_bfree); 58 | setintegerfield(sv, f_bavail); 59 | setintegerfield(sv, f_files); 60 | setintegerfield(sv, f_ffree); 61 | setintegerfield(sv, f_favail); 62 | setintegerfield(sv, f_fsid); 63 | setintegerfield(sv, f_flag); 64 | setintegerfield(sv, f_namemax); 65 | 66 | settypemetatable("PosixStatvfs"); 67 | return 1; 68 | } 69 | 70 | 71 | /*** 72 | Get file system statistics. 73 | @function statvfs 74 | @string path any path within the mounted file system 75 | @treturn PosixStatvfs information about file system containing *path* 76 | @see statvfs(3) 77 | @usage 78 | local statvfs = require "posix.sys.statvfs".statvfs 79 | for a, b in pairs (statvfs "/") do print (a, b) end 80 | */ 81 | static int 82 | Pstatvfs(lua_State *L) 83 | { 84 | struct statvfs s; 85 | const char *path = luaL_checkstring(L, 1); 86 | checknargs(L, 1); 87 | if (statvfs(path, &s) == -1) 88 | return pusherror(L, path); 89 | return pushstatvfs(L, &s); 90 | } 91 | 92 | 93 | static const luaL_Reg posix_sys_statvfs_fns[] = 94 | { 95 | LPOSIX_FUNC( Pstatvfs ), 96 | {NULL, NULL} 97 | }; 98 | 99 | 100 | /*** 101 | Constants. 102 | @section constants 103 | */ 104 | 105 | /*** 106 | Statvfs constants. 107 | Any constants not available in the underlying system will be `nil` valued. 108 | @table posix.sys.statvfs 109 | @int ST_RDONLY read-only file system 110 | @int ST_NOSUID does not support `S_ISUID` nor `S_ISGID` file mode bits 111 | @usage 112 | -- Print statvfs constants supported on this host. 113 | for name, value in pairs (require "posix.sys.statvfs") do 114 | if type (value) == "number" then 115 | print (name, value) 116 | end 117 | end 118 | */ 119 | 120 | 121 | LUALIB_API int 122 | luaopen_posix_sys_statvfs(lua_State *L) 123 | { 124 | luaL_register(L, "posix.sys.statvfs", posix_sys_statvfs_fns); 125 | lua_pushliteral(L, "posix.sys.statvfs for " LUA_VERSION " / " PACKAGE_STRING); 126 | lua_setfield(L, -2, "version"); 127 | 128 | LPOSIX_CONST( ST_RDONLY ); 129 | LPOSIX_CONST( ST_NOSUID ); 130 | 131 | return 1; 132 | } 133 | #endif 134 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.17.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | 9 | #define ldump_c 10 | #define LUA_CORE 11 | 12 | #include "lua.h" 13 | 14 | #include "lobject.h" 15 | #include "lstate.h" 16 | #include "lundump.h" 17 | 18 | typedef struct { 19 | lua_State* L; 20 | lua_Writer writer; 21 | void* data; 22 | int strip; 23 | int status; 24 | } DumpState; 25 | 26 | #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) 27 | #define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) 28 | 29 | static void DumpBlock(const void* b, size_t size, DumpState* D) 30 | { 31 | if (D->status==0) 32 | { 33 | lua_unlock(D->L); 34 | D->status=(*D->writer)(D->L,b,size,D->data); 35 | lua_lock(D->L); 36 | } 37 | } 38 | 39 | static void DumpChar(int y, DumpState* D) 40 | { 41 | char x=(char)y; 42 | DumpVar(x,D); 43 | } 44 | 45 | static void DumpInt(int x, DumpState* D) 46 | { 47 | DumpVar(x,D); 48 | } 49 | 50 | static void DumpNumber(lua_Number x, DumpState* D) 51 | { 52 | DumpVar(x,D); 53 | } 54 | 55 | static void DumpVector(const void* b, int n, size_t size, DumpState* D) 56 | { 57 | DumpInt(n,D); 58 | DumpMem(b,n,size,D); 59 | } 60 | 61 | static void DumpString(const TString* s, DumpState* D) 62 | { 63 | if (s==NULL) 64 | { 65 | size_t size=0; 66 | DumpVar(size,D); 67 | } 68 | else 69 | { 70 | size_t size=s->tsv.len+1; /* include trailing '\0' */ 71 | DumpVar(size,D); 72 | DumpBlock(getstr(s),size*sizeof(char),D); 73 | } 74 | } 75 | 76 | #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) 77 | 78 | static void DumpFunction(const Proto* f, DumpState* D); 79 | 80 | static void DumpConstants(const Proto* f, DumpState* D) 81 | { 82 | int i,n=f->sizek; 83 | DumpInt(n,D); 84 | for (i=0; ik[i]; 87 | DumpChar(ttypenv(o),D); 88 | switch (ttypenv(o)) 89 | { 90 | case LUA_TNIL: 91 | break; 92 | case LUA_TBOOLEAN: 93 | DumpChar(bvalue(o),D); 94 | break; 95 | case LUA_TNUMBER: 96 | DumpNumber(nvalue(o),D); 97 | break; 98 | case LUA_TSTRING: 99 | DumpString(rawtsvalue(o),D); 100 | break; 101 | default: lua_assert(0); 102 | } 103 | } 104 | n=f->sizep; 105 | DumpInt(n,D); 106 | for (i=0; ip[i],D); 107 | } 108 | 109 | static void DumpUpvalues(const Proto* f, DumpState* D) 110 | { 111 | int i,n=f->sizeupvalues; 112 | DumpInt(n,D); 113 | for (i=0; iupvalues[i].instack,D); 116 | DumpChar(f->upvalues[i].idx,D); 117 | } 118 | } 119 | 120 | static void DumpDebug(const Proto* f, DumpState* D) 121 | { 122 | int i,n; 123 | DumpString((D->strip) ? NULL : f->source,D); 124 | n= (D->strip) ? 0 : f->sizelineinfo; 125 | DumpVector(f->lineinfo,n,sizeof(int),D); 126 | n= (D->strip) ? 0 : f->sizelocvars; 127 | DumpInt(n,D); 128 | for (i=0; ilocvars[i].varname,D); 131 | DumpInt(f->locvars[i].startpc,D); 132 | DumpInt(f->locvars[i].endpc,D); 133 | } 134 | n= (D->strip) ? 0 : f->sizeupvalues; 135 | DumpInt(n,D); 136 | for (i=0; iupvalues[i].name,D); 137 | } 138 | 139 | static void DumpFunction(const Proto* f, DumpState* D) 140 | { 141 | DumpInt(f->linedefined,D); 142 | DumpInt(f->lastlinedefined,D); 143 | DumpChar(f->numparams,D); 144 | DumpChar(f->is_vararg,D); 145 | DumpChar(f->maxstacksize,D); 146 | DumpCode(f,D); 147 | DumpConstants(f,D); 148 | DumpUpvalues(f,D); 149 | DumpDebug(f,D); 150 | } 151 | 152 | static void DumpHeader(DumpState* D) 153 | { 154 | lu_byte h[LUAC_HEADERSIZE]; 155 | luaU_header(h); 156 | DumpBlock(h,LUAC_HEADERSIZE,D); 157 | } 158 | 159 | /* 160 | ** dump Lua function as precompiled chunk 161 | */ 162 | int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) 163 | { 164 | DumpState D; 165 | D.L=L; 166 | D.writer=w; 167 | D.data=data; 168 | D.strip=strip; 169 | D.status=0; 170 | DumpHeader(&D); 171 | DumpFunction(f,&D); 172 | return D.status; 173 | } 174 | -------------------------------------------------------------------------------- /src/dep/luaposix/sched.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Kernel Thread Scheduling Priority. 14 | 15 | Where supported by the underlying system, functions to discover and 16 | change the kernel thread scheduling priority. If the module loads 17 | successfully, but there is no kernel support, then `posix.sched.version` 18 | will be set, but the unsupported APIs will be `nil`. 19 | @module posix.sched 20 | */ 21 | 22 | #include 23 | 24 | /* cannot use unistd.h for _POSIX_PRIORITY_SCHEDULING, because on Linux 25 | glibc it is defined even though the APIs are not implemented :-( */ 26 | 27 | #ifdef HAVE_SCHED_H 28 | #include 29 | #endif 30 | 31 | #include "_helpers.c" 32 | 33 | 34 | /*** 35 | get scheduling policy 36 | @function sched_getscheduler 37 | @int[opt=0] pid process to act on, or `0` for caller process 38 | @treturn[1] int scheduling policy `SCHED_FIFO`, `SCHED_RR`, `SCHED_OTHER`, 39 | if successful 40 | @return[2] nil 41 | @treturn[2] string error message 42 | @treturn[2] int errnum 43 | @see sched_getscheduler(2) 44 | */ 45 | #if HAVE_SCHED_GETSCHEDULER 46 | static int 47 | Psched_getscheduler(lua_State *L) 48 | { 49 | struct sched_param sched_param = {0}; 50 | pid_t pid = optint(L, 1, 0); 51 | checknargs(L, 1); 52 | return pushresult(L, sched_getscheduler(pid), NULL); 53 | } 54 | #endif 55 | 56 | 57 | /*** 58 | set scheduling policy/priority 59 | @function sched_setscheduler 60 | @see sched_setscheduler(2) 61 | @int[opt=0] pid process to act on, or `0` for caller process 62 | @int[opt=`SCHED_OTHER`] policy one of `SCHED_FIFO`, `SCHED_RR` or 63 | `SCHED_OTHER` 64 | @int[opt=0] priority must be `0` for `SCHED_OTHER`, or else a positive 65 | number below 100 for real-time policies 66 | @treturn[1] int `0`, if successful 67 | @return[2] nil 68 | @treturn[2] string error message 69 | @treturn[2] int errnum 70 | */ 71 | #if HAVE_SCHED_SETSCHEDULER 72 | static int 73 | Psched_setscheduler(lua_State *L) 74 | { 75 | struct sched_param sched_param = {0}; 76 | pid_t pid = optint(L, 1, 0); 77 | int policy = optint(L, 2, SCHED_OTHER); 78 | sched_param.sched_priority = optint (L, 3, 0); 79 | checknargs(L, 3); 80 | return pushresult(L, sched_setscheduler(pid, policy, &sched_param), NULL); 81 | } 82 | #endif 83 | 84 | 85 | static const luaL_Reg posix_sched_fns[] = 86 | { 87 | #if HAVE_SCHED_GETSCHEDULER 88 | LPOSIX_FUNC( Psched_getscheduler ), 89 | #endif 90 | #if HAVE_SCHED_SETSCHEDULER 91 | LPOSIX_FUNC( Psched_setscheduler ), 92 | #endif 93 | {NULL, NULL} 94 | }; 95 | 96 | 97 | /*** 98 | Constants. 99 | @section constants 100 | */ 101 | 102 | /*** 103 | Scheduler constants. 104 | Any constants not available in the underlying system will be `nil` valued. 105 | @table posix.sched 106 | @int SCHED_FIFO first-in, first-out scheduling policy 107 | @int SCHED_RR round-robin scheduling policy 108 | @int SCHED_OTHER another scheduling policy 109 | @usage 110 | -- Print scheduler constants supported on this host. 111 | for name, value in pairs (require "posix.sched") do 112 | if type (value) == "number" then 113 | print (name, value) 114 | end 115 | end 116 | */ 117 | 118 | LUALIB_API int 119 | luaopen_posix_sched(lua_State *L) 120 | { 121 | luaL_register(L, "posix.sched", posix_sched_fns); 122 | lua_pushliteral(L, "posix.sched for " LUA_VERSION " / " PACKAGE_STRING); 123 | lua_setfield(L, -2, "version"); 124 | 125 | /* Psched_setscheduler flags */ 126 | #ifdef SCHED_FIFO 127 | LPOSIX_CONST( SCHED_FIFO ); 128 | #endif 129 | #ifdef SCHED_RR 130 | LPOSIX_CONST( SCHED_RR ); 131 | #endif 132 | #ifdef SCHED_OTHER 133 | LPOSIX_CONST( SCHED_OTHER ); 134 | #endif 135 | 136 | return 1; 137 | } 138 | -------------------------------------------------------------------------------- /src/api/c/modserver.h: -------------------------------------------------------------------------------- 1 | #ifndef MODSERVER_H 2 | #define MODSERVER_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | Each API function takes an opaque pointer. Do not free this. 12 | */ 13 | typedef struct servlet servlet; 14 | 15 | /* 16 | Return the value associated with the given key of the query part of the URI, or NULL if 17 | no such key is found. 18 | 19 | The returned string is NULL terminated. The application must not free the value. 20 | 21 | // Example: 22 | // For a given URI of /?key1=value1&key2=value2 23 | const char *val = get_arg(s, "key1"); 24 | assert(strcmp(val, "value1") == 0); 25 | */ 26 | const char* get_arg(servlet *s, const char *name); 27 | 28 | /* 29 | Return the HTTP request method. 30 | 31 | The returned string is NULL terminated. The application must not free the value. 32 | 33 | // Example: 34 | const char *method = get_method(s); 35 | assert(strcmp(method, "GET") == 0); 36 | */ 37 | const char* get_method(servlet *s); 38 | 39 | /* 40 | Return the value associated with the given HTTP request header name. 41 | 42 | HTTP header names are case-insensitive and so is the name argument. 43 | 44 | The returned string is NULL terminated. The application must not free the value. 45 | 46 | // Example: 47 | const char *val0 = get_header(s, "User-Agent"); 48 | const char *val1 = get_header(s, "user-agent"); 49 | assert(strcmp(val0, val1) == 0); 50 | */ 51 | const char* get_header(servlet *s, const char *name); 52 | 53 | /* 54 | Set the HTTP response status code. 55 | 56 | The reason phrase is automatically set based on the integer status code. 57 | 58 | The default status code of 200 is automatically set by the server and does not have to be 59 | set by the application. 60 | 61 | // Example: 62 | // 404 Not Found 63 | set_status(s, 404); 64 | */ 65 | void set_status(servlet *s, int status); 66 | 67 | /* 68 | Set an HTTP response header. 69 | 70 | HTTP header names are case-insensitive. Setting the same header again replaces the previous 71 | header. 72 | 73 | Internal copies are made of the name and value. 74 | 75 | // Example: 76 | set_header(s, "Set-Cookie", "key=value"); 77 | 78 | set_header(s, "Content-Type", "text/plain; charset=UTF-8"); 79 | 80 | unsigned length = 42; 81 | char str_length[128]; 82 | snprintf(str_length, sizeof(str_length), "%u", length); 83 | set_header(s, "Content-Length", str_length); 84 | */ 85 | void set_header(servlet *s, const char *name, const char *value); 86 | 87 | /* 88 | Write the given buffer to the output stream. 89 | 90 | The first write to the output stream generates the HTTP status line and headers. Further 91 | changes to the status or headers is not possible once the headers are sent. Chunked 92 | transfer encoding is used by default when the Content-Length header is not set. 93 | 94 | The output stream is fully buffered and is automatically flushed when it grows too large. 95 | One may use rflush() to manually flush the output stream to the user. 96 | 97 | // Example: 98 | const char reply[] = "hello world"; 99 | rwrite(s, reply, sizeof(reply) - 1); 100 | */ 101 | size_t rwrite(servlet *s, const char *buffer, size_t length); 102 | 103 | /* 104 | Write to the output stream according to the given printf format string and arguments. 105 | 106 | See the documentation of rwrite() for the behavior of rprintf() with regard to the output 107 | stream. 108 | 109 | // Example: 110 | rprintf(s, "The number is %i\n", 42); 111 | 112 | const char reply[] = "hello world"; 113 | rprintf(s, "%.*s", (int)sizeof(reply) - 1, reply); 114 | // Equivalent to 115 | // rwrite(s, buf, sizeof(buf) - 1); 116 | */ 117 | int rprintf(servlet *s, const char *format, ...); 118 | 119 | /* 120 | Write all the buffered data in the output stream to the user. 121 | 122 | rflush() is automatically called when the application returns. 123 | 124 | // Example: 125 | for (int count = 0; count < 5; ++count) 126 | { 127 | rprintf(s, "count: %i\n", count); 128 | // Without the rflush() the user would have to wait 5 seconds to see any output. 129 | rflush(s); 130 | sleep(1); 131 | } 132 | rprintf(s, "done\n"); 133 | */ 134 | void rflush(servlet *s); 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /src/dep/luaposix/grp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Group Database Operations. 14 | 15 | Query the system group database. 16 | 17 | @see posix.pwd 18 | @module posix.grp 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "_helpers.c" 26 | 27 | 28 | /*** 29 | Group record. 30 | @table PosixGroup 31 | @string gr_name name of group 32 | @int gr_gid unique group id 33 | @tfield list gr_mem a list of group members 34 | */ 35 | 36 | static int 37 | pushgroup(lua_State *L, struct group *g) 38 | { 39 | if (!g) 40 | return lua_pushnil(L), 1; 41 | 42 | lua_createtable(L, 0, 3); 43 | setintegerfield(g, gr_gid); 44 | setstringfield(g, gr_name); 45 | if (g->gr_mem) 46 | { 47 | int i; 48 | lua_newtable(L); 49 | for (i = 0; g->gr_mem[i] != NULL; i++) 50 | { 51 | lua_pushstring(L, g->gr_mem[i]); 52 | lua_rawseti(L, -2, i + 1); 53 | } 54 | lua_setfield(L, -2, "gr_mem"); 55 | } 56 | 57 | settypemetatable("PosixGroup"); 58 | return 1; 59 | } 60 | 61 | 62 | /*** 63 | Release group database resources. 64 | @function endgrent 65 | @see getgrent 66 | */ 67 | static int 68 | Pendgrent(lua_State *L) 69 | { 70 | checknargs(L, 0); 71 | endgrent(); 72 | return 0; 73 | } 74 | 75 | 76 | /*** 77 | Fetch next group. 78 | @function getgrent 79 | @treturn PosixGroup next group record 80 | @see endgrent 81 | @usage 82 | local grp = require "posix.grp" 83 | t = grp.getgrent () 84 | while t ~= nil do 85 | process (t) 86 | t = grp.getgrent () 87 | end 88 | grp.endgrent () 89 | */ 90 | static int 91 | Pgetgrent(lua_State *L) 92 | { 93 | struct group *g; 94 | checknargs(L, 0); 95 | g = getgrent(); 96 | if (!g && errno == 0) 97 | endgrent(); 98 | return pushgroup(L, g); 99 | } 100 | 101 | 102 | /*** 103 | Fetch group with given group id. 104 | @function getgrgid 105 | @int gid group id 106 | @treturn PosixGroup group record for *gid* 107 | @usage 108 | local grp = require "posix.grp" 109 | t = grp.getgrgid (0) 110 | */ 111 | static int 112 | Pgetgrgid(lua_State *L) 113 | { 114 | gid_t gid = (gid_t) checkint(L, 1); 115 | struct group *g; 116 | checknargs(L, 1); 117 | 118 | errno = 0; /* so we can recognise a successful empty result */ 119 | g = getgrgid(gid); 120 | if (!g && errno != 0) 121 | return pusherror(L, "getgrgid"); 122 | return pushgroup(L, g); 123 | } 124 | 125 | 126 | /*** 127 | Fetch named group. 128 | @function getgrnam 129 | @string name group name 130 | @treturn PosixGroup group record for *name* 131 | @usage 132 | local grp = require "posix.grp" 133 | t = grp.getgrnam "wheel" 134 | */ 135 | static int 136 | Pgetgrnam(lua_State *L) 137 | { 138 | const char *name = luaL_checkstring(L, 1); 139 | struct group *g; 140 | checknargs(L, 1); 141 | 142 | errno = 0; /* so we can recognise a successful empty result */ 143 | g = getgrnam (name); 144 | if (!g && errno != 0) 145 | return pusherror(L, "getgrnam"); 146 | return pushgroup(L, g); 147 | } 148 | 149 | 150 | /*** 151 | Rewind next @{getgrent} back to start of database. 152 | @function setgrent 153 | @see getgrent 154 | */ 155 | static int 156 | Psetgrent(lua_State *L) 157 | { 158 | checknargs(L, 0); 159 | setgrent(); 160 | return 0; 161 | } 162 | 163 | 164 | static const luaL_Reg posix_grp_fns[] = 165 | { 166 | LPOSIX_FUNC( Pendgrent ), 167 | LPOSIX_FUNC( Pgetgrent ), 168 | LPOSIX_FUNC( Pgetgrgid ), 169 | LPOSIX_FUNC( Pgetgrnam ), 170 | LPOSIX_FUNC( Psetgrent ), 171 | {NULL, NULL} 172 | }; 173 | 174 | 175 | LUALIB_API int 176 | luaopen_posix_grp(lua_State *L) 177 | { 178 | luaL_register(L, "posix.grp", posix_grp_fns); 179 | lua_pushliteral(L, "posix.grp for " LUA_VERSION " / " PACKAGE_STRING); 180 | lua_setfield(L, -2, "version"); 181 | 182 | return 1; 183 | } 184 | -------------------------------------------------------------------------------- /src/dep/luaposix/pwd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Password Database Operations. 14 | 15 | Query the system password database. 16 | 17 | @module posix.pwd 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include /* for geteuid(2) */ 25 | 26 | #include "_helpers.c" 27 | 28 | 29 | /*** 30 | Password record. 31 | @table PosixPasswd 32 | @string pw_name user's login name 33 | @int pw_uid unique user id 34 | @int pw_gid user's default group id 35 | @string pw_dir initial working directory 36 | @string pw_shell user's login shell path 37 | */ 38 | 39 | static int 40 | pushpasswd(lua_State *L, struct passwd *p) 41 | { 42 | if (!p) 43 | return lua_pushnil(L), 1; 44 | 45 | lua_createtable(L, 0, 6); 46 | setintegerfield(p, pw_uid); 47 | setintegerfield(p, pw_gid); 48 | setstringfield(p, pw_name); 49 | setstringfield(p, pw_dir); 50 | setstringfield(p, pw_shell); 51 | setstringfield(p, pw_passwd); 52 | 53 | settypemetatable("PosixPasswd"); 54 | return 1; 55 | } 56 | 57 | 58 | /*** 59 | Release password database resources. 60 | @function endpwent 61 | @see getpwent 62 | */ 63 | static int 64 | Pendpwent(lua_State *L) 65 | { 66 | checknargs(L, 0); 67 | endpwent(); 68 | return 0; 69 | } 70 | 71 | 72 | /*** 73 | Fetch next password entry. 74 | @function getpwent 75 | @treturn PosixPasswd next password record 76 | @see endpwent 77 | @usage 78 | local pwd = require "posix.pwd" 79 | t = pwd.getpwent () 80 | while t ~= nil do 81 | process (t) 82 | t = pwd.getpwent () 83 | end 84 | pwd.endpwent () 85 | */ 86 | static int 87 | Pgetpwent(lua_State *L) 88 | { 89 | struct passwd *p; 90 | checknargs(L, 0); 91 | p = getpwent(); 92 | if (!p && errno == 0) 93 | endpwent(); 94 | return pushpasswd(L, p); 95 | } 96 | 97 | 98 | /*** 99 | Fetch named user. 100 | @function getpwnam 101 | @string name user name 102 | @treturn PosixPasswd passwd record for *name* 103 | @usage 104 | local pwd = require "posix.pwd" 105 | t = pwd.getpwnam "root" 106 | */ 107 | static int 108 | Pgetpwnam(lua_State *L) 109 | { 110 | const char *name = luaL_checkstring(L, 1); 111 | struct passwd *p; 112 | checknargs(L, 1); 113 | 114 | errno = 0; /* so we can recognise a successful empty result */ 115 | p = getpwnam (name); 116 | if (!p && errno != 0) 117 | return pusherror(L, "getpwnam"); 118 | return pushpasswd(L, p); 119 | } 120 | 121 | 122 | /*** 123 | Fetch password entry with given user id. 124 | @function getpwuid 125 | @int uid user id 126 | @treturn PosixPasswd passwd record for *uid* 127 | @usage 128 | local pwd = require "posix.pwd" 129 | t = pwd.getpwuid (0) 130 | */ 131 | static int 132 | Pgetpwuid(lua_State *L) 133 | { 134 | uid_t uid = (uid_t) checkint(L, 1); 135 | struct passwd *p; 136 | checknargs(L, 1); 137 | 138 | errno = 0; /* so we can recognise a successful empty result */ 139 | p = getpwuid(uid); 140 | if (!p && errno != 0) 141 | return pusherror(L, "getpwuid"); 142 | return pushpasswd(L, p); 143 | } 144 | 145 | 146 | /*** 147 | Rewind next @{getpwent} back to start of database. 148 | @function setpwent 149 | @see getpwent 150 | */ 151 | static int 152 | Psetpwent(lua_State *L) 153 | { 154 | checknargs(L, 0); 155 | setpwent(); 156 | return 0; 157 | } 158 | 159 | 160 | static const luaL_Reg posix_pwd_fns[] = 161 | { 162 | LPOSIX_FUNC( Pendpwent ), 163 | LPOSIX_FUNC( Pgetpwent ), 164 | LPOSIX_FUNC( Pgetpwnam ), 165 | LPOSIX_FUNC( Pgetpwuid ), 166 | LPOSIX_FUNC( Psetpwent ), 167 | {NULL, NULL} 168 | }; 169 | 170 | 171 | LUALIB_API int 172 | luaopen_posix_pwd(lua_State *L) 173 | { 174 | luaL_register(L, "posix.pwd", posix_pwd_fns); 175 | lua_pushliteral(L, "posix.pwd for " LUA_VERSION " / " PACKAGE_STRING); 176 | lua_setfield(L, -2, "version"); 177 | 178 | return 1; 179 | } 180 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.5.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | 11 | #define lcorolib_c 12 | #define LUA_LIB 13 | 14 | #include "lua.h" 15 | 16 | #include "lauxlib.h" 17 | #include "lualib.h" 18 | 19 | 20 | static int auxresume (lua_State *L, lua_State *co, int narg) { 21 | int status; 22 | if (!lua_checkstack(co, narg)) { 23 | lua_pushliteral(L, "too many arguments to resume"); 24 | return -1; /* error flag */ 25 | } 26 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 27 | lua_pushliteral(L, "cannot resume dead coroutine"); 28 | return -1; /* error flag */ 29 | } 30 | lua_xmove(L, co, narg); 31 | status = lua_resume(co, L, narg); 32 | if (status == LUA_OK || status == LUA_YIELD) { 33 | int nres = lua_gettop(co); 34 | if (!lua_checkstack(L, nres + 1)) { 35 | lua_pop(co, nres); /* remove results anyway */ 36 | lua_pushliteral(L, "too many results to resume"); 37 | return -1; /* error flag */ 38 | } 39 | lua_xmove(co, L, nres); /* move yielded values */ 40 | return nres; 41 | } 42 | else { 43 | lua_xmove(co, L, 1); /* move error message */ 44 | return -1; /* error flag */ 45 | } 46 | } 47 | 48 | 49 | static int luaB_coresume (lua_State *L) { 50 | lua_State *co = lua_tothread(L, 1); 51 | int r; 52 | luaL_argcheck(L, co, 1, "coroutine expected"); 53 | r = auxresume(L, co, lua_gettop(L) - 1); 54 | if (r < 0) { 55 | lua_pushboolean(L, 0); 56 | lua_insert(L, -2); 57 | return 2; /* return false + error message */ 58 | } 59 | else { 60 | lua_pushboolean(L, 1); 61 | lua_insert(L, -(r + 1)); 62 | return r + 1; /* return true + `resume' returns */ 63 | } 64 | } 65 | 66 | 67 | static int luaB_auxwrap (lua_State *L) { 68 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 69 | int r = auxresume(L, co, lua_gettop(L)); 70 | if (r < 0) { 71 | if (lua_isstring(L, -1)) { /* error object is a string? */ 72 | luaL_where(L, 1); /* add extra info */ 73 | lua_insert(L, -2); 74 | lua_concat(L, 2); 75 | } 76 | return lua_error(L); /* propagate error */ 77 | } 78 | return r; 79 | } 80 | 81 | 82 | static int luaB_cocreate (lua_State *L) { 83 | lua_State *NL; 84 | luaL_checktype(L, 1, LUA_TFUNCTION); 85 | NL = lua_newthread(L); 86 | lua_pushvalue(L, 1); /* move function to top */ 87 | lua_xmove(L, NL, 1); /* move function from L to NL */ 88 | return 1; 89 | } 90 | 91 | 92 | static int luaB_cowrap (lua_State *L) { 93 | luaB_cocreate(L); 94 | lua_pushcclosure(L, luaB_auxwrap, 1); 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_yield (lua_State *L) { 100 | return lua_yield(L, lua_gettop(L)); 101 | } 102 | 103 | 104 | static int luaB_costatus (lua_State *L) { 105 | lua_State *co = lua_tothread(L, 1); 106 | luaL_argcheck(L, co, 1, "coroutine expected"); 107 | if (L == co) lua_pushliteral(L, "running"); 108 | else { 109 | switch (lua_status(co)) { 110 | case LUA_YIELD: 111 | lua_pushliteral(L, "suspended"); 112 | break; 113 | case LUA_OK: { 114 | lua_Debug ar; 115 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 116 | lua_pushliteral(L, "normal"); /* it is running */ 117 | else if (lua_gettop(co) == 0) 118 | lua_pushliteral(L, "dead"); 119 | else 120 | lua_pushliteral(L, "suspended"); /* initial state */ 121 | break; 122 | } 123 | default: /* some error occurred */ 124 | lua_pushliteral(L, "dead"); 125 | break; 126 | } 127 | } 128 | return 1; 129 | } 130 | 131 | 132 | static int luaB_corunning (lua_State *L) { 133 | int ismain = lua_pushthread(L); 134 | lua_pushboolean(L, ismain); 135 | return 2; 136 | } 137 | 138 | 139 | static const luaL_Reg co_funcs[] = { 140 | {"create", luaB_cocreate}, 141 | {"resume", luaB_coresume}, 142 | {"running", luaB_corunning}, 143 | {"status", luaB_costatus}, 144 | {"wrap", luaB_cowrap}, 145 | {"yield", luaB_yield}, 146 | {NULL, NULL} 147 | }; 148 | 149 | 150 | 151 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 152 | luaL_newlib(L, co_funcs); 153 | return 1; 154 | } 155 | 156 | -------------------------------------------------------------------------------- /src/module/guile.c: -------------------------------------------------------------------------------- 1 | // C99 2 | #include 3 | #include 4 | #include 5 | #include 6 | // Lua 7 | #include 8 | #include 9 | #include 10 | // Guile Scheme 11 | #include 12 | // Local 13 | #include "modserver.h" 14 | 15 | static SCM api_get_arg(SCM s_, SCM name_) 16 | { 17 | servlet *s = scm_to_pointer(s_); 18 | char *name = scm_to_utf8_string(name_); 19 | const char *arg = get_arg(s, name); 20 | free(name); 21 | if (arg) 22 | { 23 | return scm_from_utf8_string(arg); 24 | } 25 | return SCM_UNSPECIFIED; 26 | } 27 | 28 | static SCM api_get_method(SCM s_) 29 | { 30 | servlet *s = scm_to_pointer(s_); 31 | const char *method = get_method(s); 32 | if (method) 33 | { 34 | return scm_from_utf8_string(method); 35 | } 36 | return SCM_UNSPECIFIED; 37 | } 38 | 39 | static SCM api_get_header(SCM s_, SCM key_) 40 | { 41 | servlet *s = scm_to_pointer(s_); 42 | char *key = scm_to_utf8_string(key_); 43 | const char *value = get_header(s, key); 44 | free(key); 45 | if (value) 46 | { 47 | return scm_from_utf8_string(value); 48 | } 49 | return SCM_UNSPECIFIED; 50 | } 51 | 52 | static SCM api_set_status(SCM s_, SCM status_) 53 | { 54 | servlet *s = scm_to_pointer(s_); 55 | int status = scm_to_int(status_); 56 | set_status(s, status); 57 | return SCM_UNSPECIFIED; 58 | } 59 | 60 | static SCM api_set_header(SCM s_, SCM key_, SCM value_) 61 | { 62 | servlet *s = scm_to_pointer(s_); 63 | char *key = scm_to_utf8_string(key_); 64 | char *value = scm_to_utf8_string(value_); 65 | set_header(s, key, value); 66 | free(key); 67 | free(value); 68 | return SCM_UNSPECIFIED; 69 | } 70 | 71 | static SCM api_rwrite(SCM s_, SCM buffer_) 72 | { 73 | servlet *s = scm_to_pointer(s_); 74 | size_t length; 75 | char *str = scm_to_utf8_stringn(buffer_, &length); 76 | size_t ret = rwrite(s, str, length); 77 | free(str); 78 | return scm_from_size_t(ret); 79 | } 80 | 81 | static SCM api_rflush(SCM s_) 82 | { 83 | servlet *s = scm_to_pointer(s_); 84 | rflush(s); 85 | return SCM_UNSPECIFIED; 86 | } 87 | 88 | static void* guile_mod_init(void *data) 89 | { 90 | return NULL; 91 | } 92 | 93 | static int mod_init(lua_State *l) 94 | { 95 | scm_init_guile(); 96 | return 0; 97 | } 98 | 99 | static int servlet_run(lua_State *l) 100 | { 101 | SCM run_ref = (SCM)lua_touserdata(l, lua_upvalueindex(1)); 102 | SCM s = scm_from_pointer(l, NULL); 103 | scm_call_1(run_ref, s); 104 | return 0; 105 | } 106 | 107 | static int mod_load_servlet(lua_State *l) 108 | { 109 | const char *path = luaL_checkstring(l, -1); 110 | SCM module = scm_c_define_module(path, NULL, NULL); 111 | SCM prev_module = scm_set_current_module(module); 112 | 113 | // TODO: don't define these functions every time for each servlet 114 | scm_c_define_gsubr("get_arg", 2, 0, 0, &api_get_arg); 115 | scm_c_define_gsubr("get_method", 1, 0, 0, &api_get_method); 116 | scm_c_define_gsubr("get_header", 2, 0, 0, &api_get_header); 117 | scm_c_define_gsubr("set_status", 2, 0, 0, &api_set_status); 118 | scm_c_define_gsubr("set_header", 3, 0, 0, &api_set_header); 119 | scm_c_define_gsubr("rwrite", 2, 0, 0, &api_rwrite); 120 | scm_c_define_gsubr("rflush", 1, 0, 0, &api_rflush); 121 | 122 | SCM foo = scm_c_primitive_load(path); 123 | SCM run_symbol = scm_c_lookup("run"); 124 | SCM run_ref = scm_variable_ref(run_symbol); 125 | scm_set_current_module(prev_module); 126 | 127 | lua_newtable(l); 128 | lua_pushlightuserdata(l, (void*)run_ref); 129 | lua_pushcclosure(l, servlet_run, 1); 130 | lua_setfield(l, -2, "run"); 131 | 132 | return 1; 133 | } 134 | 135 | static int mod_cleanup(lua_State *l) 136 | { 137 | return 0; 138 | } 139 | 140 | static const luaL_Reg module_guile[] = 141 | { 142 | {"init", mod_init}, 143 | {"load_servlet", mod_load_servlet}, 144 | {"cleanup", mod_cleanup}, 145 | {NULL, NULL}, 146 | }; 147 | 148 | LUALIB_API int luaopen_module_guile(lua_State *l) 149 | { 150 | luaL_newlib(l, module_guile); 151 | return 1; 152 | } 153 | 154 | // https://www.gnu.org/software/guile/manual/guile.html 155 | // https://www.gnu.org/software/guile/manual/html_node/index.html#SEC_Contents 156 | // https://www.gnu.org/software/guile/manual/html_node/Programming-in-C.html#Programming-in-C 157 | // https://www.gnu.org/software/guile/manual/html_node/Accessing-Modules-from-C.html 158 | // http://www.lonelycactus.com/guilebook/seccreatingguiletoplevelvar.html 159 | // http://www.lonelycactus.com/guilebook/secreadtoplevel.html 160 | // http://agentzh.org/misc/code/gdb/guile/guile.c.html 161 | // /usr/include/guile/2.0/libguile/modules.h 162 | -------------------------------------------------------------------------------- /src/api/c/modserver.c: -------------------------------------------------------------------------------- 1 | // C99 2 | #include 3 | #include 4 | #include 5 | #include 6 | // Lua 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | Users of the API must not have to manage or be aware of the Lua stack. This API 13 | implementation is responsible for managing the Lua stack. 14 | */ 15 | 16 | const char *get_arg(lua_State *l, const char *name) 17 | { 18 | lua_getfield(l, -1, "get_arg"); 19 | lua_pushvalue(l, 1); 20 | lua_pushstring(l, name); 21 | lua_call(l, 2, 1); 22 | const char *arg = lua_tostring(l, -1); 23 | /* 24 | Push another copy of the servlet ref over the string arg. This keeps the arg ref alive 25 | until after servlet:run() returns. 26 | */ 27 | lua_pushvalue(l, 1); 28 | return arg; 29 | } 30 | 31 | const char *get_method(lua_State *l) 32 | { 33 | lua_getfield(l, -1, "get_method"); 34 | lua_pushvalue(l, 1); 35 | lua_call(l, 1, 1); 36 | const char *method = luaL_checkstring(l, -1); 37 | lua_pushvalue(l, 1); 38 | return method; 39 | } 40 | 41 | const char *get_header(lua_State *l, const char *name) 42 | { 43 | lua_getfield(l, -1, "get_header"); 44 | lua_pushvalue(l, 1); 45 | lua_pushstring(l, name); 46 | lua_call(l, 2, 1); 47 | const char *arg = lua_tostring(l, -1); 48 | lua_pushvalue(l, 1); 49 | return arg; 50 | } 51 | 52 | void set_header(lua_State *l, const char *name, const char *value) 53 | { 54 | lua_getfield(l, -1, "set_header"); 55 | lua_pushvalue(l, 1); 56 | lua_pushstring(l, name); 57 | lua_pushstring(l, value); 58 | lua_call(l, 3, 0); 59 | } 60 | 61 | void set_status(lua_State *l, int status) 62 | { 63 | lua_getfield(l, -1, "set_status"); 64 | lua_pushvalue(l, 1); 65 | lua_pushnumber(l, status); 66 | // servlet.set_status(self, status) 67 | lua_call(l, 2, 0); 68 | } 69 | 70 | size_t rwrite(lua_State *l, const char *buffer, size_t length) 71 | { 72 | lua_getfield(l, -1, "rwrite"); 73 | lua_pushvalue(l, 1); 74 | lua_pushlstring(l, buffer, length); 75 | /* 76 | Use pcall because writing to a socket could fail with EPIPE if the connection is closed 77 | prematurely. 78 | */ 79 | if (lua_pcall(l, 2, LUA_MULTRET, 0) != LUA_OK) 80 | { 81 | lua_pop(l, 3); 82 | return 0; 83 | } 84 | int isnum; 85 | size_t length_written = lua_tonumberx(l, -1, &isnum); 86 | lua_pop(l, 1); 87 | if (isnum) 88 | { 89 | return length_written; 90 | } 91 | return 0; 92 | } 93 | 94 | static int write_status_line_and_headers(lua_State *l) 95 | { 96 | lua_getfield(l, -1, "write_status_line_and_headers"); 97 | lua_pushvalue(l, 1); 98 | if (lua_pcall(l, 1, LUA_MULTRET, 0) != LUA_OK) 99 | { 100 | lua_pop(l, 3); 101 | return -1; 102 | } 103 | return 0; 104 | } 105 | 106 | static FILE* get_clientfd_write(lua_State *l) 107 | { 108 | lua_getfield(l, -1, "clientfd_write"); 109 | luaL_Stream *stream = luaL_checkudata(l, -1, LUA_FILEHANDLE); 110 | FILE *file = stream->f; 111 | lua_pop(l, 1); 112 | return file; 113 | } 114 | 115 | int rprintf(lua_State *l, const char *format, ...) 116 | { 117 | lua_getfield(l, -1, "response_headers_written"); 118 | int response_headers_written = lua_toboolean(l, -1); 119 | lua_pop(l, 1); 120 | if (!response_headers_written) 121 | { 122 | if (write_status_line_and_headers(l) != 0) 123 | { 124 | return -1; 125 | } 126 | } 127 | FILE *file = get_clientfd_write(l); 128 | int ret; 129 | va_list ap0, ap1; 130 | va_start(ap0, format); 131 | va_copy(ap1, ap0); 132 | // Get the length of the output without writing anything. 133 | // Per C99: "If n is zero, nothing is written, and s may be a null pointer." 134 | int len = vsnprintf(NULL, 0, format, ap0); 135 | va_end(ap0); 136 | if (!len) 137 | { 138 | return -1; 139 | } 140 | if (strcmp(get_method(l), "HEAD") == 0) 141 | { 142 | return len; 143 | } 144 | lua_getfield(l, -1, "response_headers"); 145 | lua_getfield(l, -1, "content-length"); 146 | int chunked = !lua_toboolean(l, -1); 147 | lua_pop(l, 2); 148 | if (chunked) 149 | { 150 | ret = fprintf(file, "%X\r\n", len); 151 | if (!ret) 152 | { 153 | va_end(ap1); 154 | return -1; 155 | } 156 | } 157 | ret = vfprintf(file, format, ap1); 158 | if (!ret) 159 | { 160 | va_end(ap1); 161 | return -1; 162 | } 163 | va_end(ap1); 164 | if (chunked) 165 | { 166 | ret = fprintf(file, "\r\n"); 167 | if (!ret) 168 | { 169 | return -1; 170 | } 171 | } 172 | return ret; 173 | } 174 | 175 | void rflush(lua_State *l) 176 | { 177 | lua_getfield(l, -1, "rflush"); 178 | lua_pushvalue(l, 1); 179 | lua_call(l, 1, 0); 180 | } 181 | -------------------------------------------------------------------------------- /src/dep/luaposix/getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Command Line Argument Processing. 14 | 15 | @module posix.getopt 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | 25 | /* getopt_long */ 26 | 27 | /* N.B. We don't need the symbolic constants no_argument, 28 | required_argument and optional_argument, since their values are 29 | defined as 0, 1 and 2 respectively. */ 30 | static const char *const arg_types[] = 31 | { 32 | "none", "required", "optional", NULL 33 | }; 34 | 35 | 36 | static int 37 | iter_getopt_long(lua_State *L) 38 | { 39 | int longindex = 0, ret, argc = lua_tointeger(L, lua_upvalueindex(1)); 40 | char **argv = (char **)lua_touserdata(L, lua_upvalueindex(3)); 41 | struct option *longopts = (struct option *)lua_touserdata(L, lua_upvalueindex(3 + argc + 1)); 42 | 43 | if (argv == NULL) /* If we have already completed, return now. */ 44 | return 0; 45 | 46 | /* Fetch upvalues to pass to getopt_long. */ 47 | ret = getopt_long(argc, argv, 48 | lua_tostring(L, lua_upvalueindex(2)), 49 | longopts, 50 | &longindex); 51 | if (ret == -1) 52 | return 0; 53 | else 54 | { 55 | char c = ret; 56 | lua_pushlstring(L, &c, 1); 57 | lua_pushstring(L, optarg); 58 | lua_pushinteger(L, optind); 59 | lua_pushinteger(L, longindex); 60 | return 4; 61 | } 62 | } 63 | 64 | 65 | /*** 66 | Parse command-line options. 67 | @function getopt 68 | @param arg command line arguments 69 | @string shortopts short option specifier 70 | @tparam[opt] table longopts long options table 71 | @int[opt=0] opterr index of the option with an error 72 | @int[opt=1] optind index of the next unprocessed option 73 | @return option iterator, returning 4 values 74 | @see getopt(3) 75 | @see getopt_long(3) 76 | @usage 77 | local getopt = require "posix.getopt".getopt 78 | local longopts = { 79 | {"help", "none", 1}, 80 | {"version", "none", 3}, 81 | } 82 | for r, longindex, err, i in getopt (arg, "ho:v", longopts, err, i) do 83 | process (arg, err, i) 84 | end 85 | @see getopt.lua 86 | */ 87 | static int 88 | Pgetopt(lua_State *L) 89 | { 90 | int argc, i, n = 0; 91 | const char *shortopts; 92 | char **argv; 93 | struct option *longopts; 94 | 95 | checknargs(L, 5); 96 | checktype(L, 1, LUA_TTABLE, "list"); 97 | shortopts = luaL_checkstring(L, 2); 98 | if (!lua_isnoneornil(L, 3)) 99 | checktype(L, 3, LUA_TTABLE, "table or nil"); 100 | opterr = optint(L, 4, 0); 101 | optind = optint(L, 5, 1); 102 | 103 | argc = (int)lua_objlen(L, 1) + 1; 104 | 105 | lua_pushinteger(L, argc); 106 | 107 | lua_pushstring(L, shortopts); 108 | 109 | argv = lua_newuserdata(L, (argc + 1) * sizeof(char *)); 110 | argv[argc] = NULL; 111 | for (i = 0; i < argc; i++) 112 | { 113 | lua_pushinteger(L, i); 114 | lua_gettable(L, 1); 115 | argv[i] = (char *)luaL_checkstring(L, -1); 116 | } 117 | 118 | if (lua_type(L, 3) == LUA_TTABLE) 119 | { 120 | n = (int)lua_objlen(L, 3); 121 | } 122 | longopts = lua_newuserdata(L, (n + 1) * sizeof(struct option)); 123 | longopts[n].name = NULL; 124 | longopts[n].has_arg = 0; 125 | longopts[n].flag = NULL; 126 | longopts[n].val = 0; 127 | for (i = 1; i <= n; i++) 128 | { 129 | const char *name, *val; 130 | int has_arg; 131 | 132 | lua_pushinteger(L, i); 133 | lua_gettable(L, 3); 134 | luaL_checktype(L, -1, LUA_TTABLE); 135 | 136 | lua_pushinteger(L, 1); 137 | lua_gettable(L, -2); 138 | name = luaL_checkstring(L, -1); 139 | 140 | lua_pushinteger(L, 2); 141 | lua_gettable(L, -3); 142 | has_arg = luaL_checkoption(L, -1, NULL, arg_types); 143 | lua_pop(L, 1); 144 | 145 | lua_pushinteger(L, 3); 146 | lua_gettable(L, -3); 147 | val = luaL_checkstring(L, -1); 148 | lua_pop(L, 1); 149 | 150 | longopts[i - 1].name = name; 151 | longopts[i - 1].has_arg = has_arg; 152 | longopts[i - 1].flag = NULL; 153 | longopts[i - 1].val = val[0]; 154 | lua_pop(L, 1); 155 | } 156 | 157 | /* Push remaining upvalues, and make and push closure. */ 158 | lua_pushcclosure(L, iter_getopt_long, 4 + argc + n); 159 | 160 | return 1; 161 | } 162 | 163 | static const luaL_Reg posix_getopt_fns[] = 164 | { 165 | LPOSIX_FUNC( Pgetopt ), 166 | {NULL, NULL} 167 | }; 168 | 169 | 170 | LUALIB_API int 171 | luaopen_posix_getopt(lua_State *L) 172 | { 173 | luaL_register(L, "posix.getopt", posix_getopt_fns); 174 | lua_pushliteral(L, "posix.getopt for " LUA_VERSION " / " PACKAGE_STRING); 175 | lua_setfield(L, -2, "version"); 176 | 177 | return 1; 178 | } 179 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.30.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lfunc_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lfunc.h" 16 | #include "lgc.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | Closure *luaF_newCclosure (lua_State *L, int n) { 24 | Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl; 25 | c->c.nupvalues = cast_byte(n); 26 | return c; 27 | } 28 | 29 | 30 | Closure *luaF_newLclosure (lua_State *L, int n) { 31 | Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl; 32 | c->l.p = NULL; 33 | c->l.nupvalues = cast_byte(n); 34 | while (n--) c->l.upvals[n] = NULL; 35 | return c; 36 | } 37 | 38 | 39 | UpVal *luaF_newupval (lua_State *L) { 40 | UpVal *uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), NULL, 0)->uv; 41 | uv->v = &uv->u.value; 42 | setnilvalue(uv->v); 43 | return uv; 44 | } 45 | 46 | 47 | UpVal *luaF_findupval (lua_State *L, StkId level) { 48 | global_State *g = G(L); 49 | GCObject **pp = &L->openupval; 50 | UpVal *p; 51 | UpVal *uv; 52 | while (*pp != NULL && (p = gco2uv(*pp))->v >= level) { 53 | GCObject *o = obj2gco(p); 54 | lua_assert(p->v != &p->u.value); 55 | lua_assert(!isold(o) || isold(obj2gco(L))); 56 | if (p->v == level) { /* found a corresponding upvalue? */ 57 | if (isdead(g, o)) /* is it dead? */ 58 | changewhite(o); /* resurrect it */ 59 | return p; 60 | } 61 | pp = &p->next; 62 | } 63 | /* not found: create a new one */ 64 | uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), pp, 0)->uv; 65 | uv->v = level; /* current value lives in the stack */ 66 | uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ 67 | uv->u.l.next = g->uvhead.u.l.next; 68 | uv->u.l.next->u.l.prev = uv; 69 | g->uvhead.u.l.next = uv; 70 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); 71 | return uv; 72 | } 73 | 74 | 75 | static void unlinkupval (UpVal *uv) { 76 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); 77 | uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ 78 | uv->u.l.prev->u.l.next = uv->u.l.next; 79 | } 80 | 81 | 82 | void luaF_freeupval (lua_State *L, UpVal *uv) { 83 | if (uv->v != &uv->u.value) /* is it open? */ 84 | unlinkupval(uv); /* remove from open list */ 85 | luaM_free(L, uv); /* free upvalue */ 86 | } 87 | 88 | 89 | void luaF_close (lua_State *L, StkId level) { 90 | UpVal *uv; 91 | global_State *g = G(L); 92 | while (L->openupval != NULL && (uv = gco2uv(L->openupval))->v >= level) { 93 | GCObject *o = obj2gco(uv); 94 | lua_assert(!isblack(o) && uv->v != &uv->u.value); 95 | L->openupval = uv->next; /* remove from `open' list */ 96 | if (isdead(g, o)) 97 | luaF_freeupval(L, uv); /* free upvalue */ 98 | else { 99 | unlinkupval(uv); /* remove upvalue from 'uvhead' list */ 100 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 101 | uv->v = &uv->u.value; /* now current value lives here */ 102 | gch(o)->next = g->allgc; /* link upvalue into 'allgc' list */ 103 | g->allgc = o; 104 | luaC_checkupvalcolor(g, uv); 105 | } 106 | } 107 | } 108 | 109 | 110 | Proto *luaF_newproto (lua_State *L) { 111 | Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), NULL, 0)->p; 112 | f->k = NULL; 113 | f->sizek = 0; 114 | f->p = NULL; 115 | f->sizep = 0; 116 | f->code = NULL; 117 | f->cache = NULL; 118 | f->sizecode = 0; 119 | f->lineinfo = NULL; 120 | f->sizelineinfo = 0; 121 | f->upvalues = NULL; 122 | f->sizeupvalues = 0; 123 | f->numparams = 0; 124 | f->is_vararg = 0; 125 | f->maxstacksize = 0; 126 | f->locvars = NULL; 127 | f->sizelocvars = 0; 128 | f->linedefined = 0; 129 | f->lastlinedefined = 0; 130 | f->source = NULL; 131 | return f; 132 | } 133 | 134 | 135 | void luaF_freeproto (lua_State *L, Proto *f) { 136 | luaM_freearray(L, f->code, f->sizecode); 137 | luaM_freearray(L, f->p, f->sizep); 138 | luaM_freearray(L, f->k, f->sizek); 139 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 140 | luaM_freearray(L, f->locvars, f->sizelocvars); 141 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 142 | luaM_free(L, f); 143 | } 144 | 145 | 146 | /* 147 | ** Look for n-th local variable at line `line' in function `func'. 148 | ** Returns NULL if not found. 149 | */ 150 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 151 | int i; 152 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 153 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 154 | local_number--; 155 | if (local_number == 0) 156 | return getstr(f->locvars[i].varname); 157 | } 158 | } 159 | return NULL; /* not found */ 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/dep/luaposix/sys/resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | Control Maximum System Resource Consumption. 14 | 15 | @module posix.sys.resource 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | /* OpenBSD 5.6 recommends using RLIMIT_DATA in place of missing RLIMIT_AS */ 25 | #ifndef RLIMIT_AS 26 | # define RLIMIT_AS RLIMIT_DATA 27 | #endif 28 | 29 | 30 | /*** 31 | Resource limit record. 32 | @table PosixRlimit 33 | @int rlim_cur current soft limit 34 | @int rlim_max hard limit 35 | */ 36 | static int 37 | pushrlimit(lua_State *L, struct rlimit *lim) 38 | { 39 | if (!lim) 40 | return lua_pushnil(L), 1; 41 | 42 | lua_createtable(L, 0, 2); 43 | 44 | setnumberfield(lim, rlim_cur); 45 | setnumberfield(lim, rlim_max); 46 | 47 | settypemetatable("PosixRlimit"); 48 | return 1; 49 | } 50 | 51 | 52 | /*** 53 | Get resource limits for this process. 54 | @function getrlimit 55 | @int resource one of `RLIMIT_CORE`, `RLIMIT_CPU`, `RLIMIT_DATA`, `RLIMIT_FSIZE`, 56 | `RLIMIT_NOFILE`, `RLIMIT_STACK` or `RLIMIT_AS` 57 | @treturn[1] int softlimit 58 | @treturn[1] int hardlimit, if successful 59 | @return[2] nil 60 | @treturn[2] string error message 61 | @treturn[2] int errnum 62 | @see getrlimit(2) 63 | @see setrlimit 64 | */ 65 | static int 66 | Pgetrlimit(lua_State *L) 67 | { 68 | struct rlimit lim; 69 | int r; 70 | checknargs(L, 1); 71 | r = getrlimit(checkint(L, 1), &lim); 72 | if (r < 0) 73 | return pusherror(L, "getrlimit"); 74 | return pushrlimit(L, &lim); 75 | } 76 | 77 | 78 | /*** 79 | Set a resource limit for subsequent child processes. 80 | @function setrlimit 81 | @string resource one of "core", "cpu", "data", "fsize", 82 | "nofile", "stack" or "as" 83 | @param[opt] softlimit process may receive a signal when reached 84 | @param[opt] hardlimit process may be terminated when reached 85 | @treturn[1] int `0`, if successful 86 | @return[2] nil 87 | @treturn[2] string error message 88 | @treturn[2] int errnum 89 | @see getrlimit(2) 90 | @see limit.lua 91 | @usage 92 | local sysres = require "posix.sys.resource" 93 | sysres.setrlimit ("nofile", 1000, 2000) 94 | */ 95 | 96 | static const char *Srlimit_fields[] = { "rlim_cur", "rlim_max" }; 97 | 98 | static int 99 | Psetrlimit(lua_State *L) 100 | { 101 | struct rlimit lim; 102 | int rid = checkint(L, 1); 103 | 104 | luaL_checktype(L, 2, LUA_TTABLE); 105 | checknargs(L, 2); 106 | 107 | lim.rlim_cur = checknumberfield(L, 2, "rlim_cur"); 108 | lim.rlim_max = checknumberfield(L, 2, "rlim_max"); 109 | checkfieldnames(L, 2, Srlimit_fields); 110 | 111 | return pushresult(L, setrlimit(rid, &lim), "setrlimit"); 112 | } 113 | 114 | 115 | static const luaL_Reg posix_sys_resource_fns[] = 116 | { 117 | LPOSIX_FUNC( Pgetrlimit ), 118 | LPOSIX_FUNC( Psetrlimit ), 119 | {NULL, NULL} 120 | }; 121 | 122 | 123 | /*** 124 | Constants. 125 | @section constants 126 | */ 127 | 128 | /*** 129 | Rlimit constants. 130 | @table posix.sys.resource 131 | @int RLIM_INFINITY unlimited resource usage 132 | @int RLIM_SAVED_CUR saved current resource soft limit 133 | @int RLIM_SAVED_MAX saved resource hard limit 134 | @int RLIMIT_CORE maximum bytes allowed for a core file 135 | @int RLIMIT_CPU maximum cputime secconds allowed per process 136 | @int RLIMIT_DATA maximum data segment bytes per process 137 | @int RLIMIT_FSIZE maximum bytes in any file 138 | @int RLIMIT_NOFILE maximum number of open files per process 139 | @int RLIMIT_STACK maximum stack segment bytes per process 140 | @int RLIMIT_AS maximum bytes total address space per process 141 | @usage 142 | -- Print resource constants supported on this host. 143 | for name, value in pairs (require "posix.sys.resource") do 144 | if type (value) == "number" then 145 | print (name, value) 146 | end 147 | end 148 | */ 149 | 150 | LUALIB_API int 151 | luaopen_posix_sys_resource(lua_State *L) 152 | { 153 | luaL_register(L, "posix.sys.resource", posix_sys_resource_fns); 154 | lua_pushliteral(L, "posix.sys.resource for " LUA_VERSION " / " PACKAGE_STRING); 155 | lua_setfield(L, -2, "version"); 156 | 157 | LPOSIX_CONST( RLIM_INFINITY ); 158 | #if defined RLIM_SAVED_CUR 159 | LPOSIX_CONST( RLIM_SAVED_CUR ); 160 | #endif 161 | #if defined RLIM_SAVED_MAX 162 | LPOSIX_CONST( RLIM_SAVED_MAX ); 163 | #endif 164 | LPOSIX_CONST( RLIMIT_CORE ); 165 | LPOSIX_CONST( RLIMIT_CPU ); 166 | LPOSIX_CONST( RLIMIT_DATA ); 167 | LPOSIX_CONST( RLIMIT_FSIZE ); 168 | LPOSIX_CONST( RLIMIT_NOFILE ); 169 | LPOSIX_CONST( RLIMIT_STACK ); 170 | LPOSIX_CONST( RLIMIT_AS ); 171 | 172 | return 1; 173 | } 174 | -------------------------------------------------------------------------------- /src/dep/luaposix/stdio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX library for Lua 5.1, 5.2 & 5.3. 3 | * Copyright (C) 2013-2016 Gary V. Vaughan 4 | * Copyright (C) 2010-2013 Reuben Thomas 5 | * Copyright (C) 2008-2010 Natanael Copa 6 | * Clean up and bug fixes by Leo Razoumov 2006-10-11 7 | * Luiz Henrique de Figueiredo 07 Apr 2006 23:17:49 8 | * Based on original by Claudio Terra for Lua 3.x. 9 | * With contributions by Roberto Ierusalimschy. 10 | * With documentation from Steve Donovan 2012 11 | */ 12 | /*** 13 | A few Standard I/O functions not already in Lua core. 14 | 15 | @module posix.stdio 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "_helpers.c" 23 | 24 | /*** 25 | Name of controlling terminal. 26 | @function ctermid 27 | @treturn string controlling terminal for current process 28 | @see ctermid(3) 29 | */ 30 | static int 31 | Pctermid(lua_State *L) 32 | { 33 | char b[L_ctermid]; 34 | checknargs(L, 0); 35 | return pushstringresult(ctermid(b)); 36 | } 37 | 38 | 39 | /*** 40 | File descriptor corresponding to a Lua file object. 41 | @function fileno 42 | @tparam file file Lua file object 43 | @treturn[1] int file descriptor for *file*, if successful 44 | @return[2] nil 45 | @treturn[2] string error message 46 | @treturn[2] int errnum 47 | @usage 48 | local stdio = require "posix.stdio" 49 | local unistd = require "posix.unistd" 50 | assert (stdio.fileno (io.stdout) == unistd.STDOUT_FILENO) 51 | */ 52 | static int 53 | Pfileno(lua_State *L) 54 | { 55 | FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); 56 | checknargs(L, 1); 57 | return pushresult(L, fileno(f), NULL); 58 | } 59 | 60 | 61 | /* This helper function is adapted from Lua 5.3's liolib.c */ 62 | static int 63 | stdio_fclose (lua_State *L) { 64 | luaL_Stream *p = ((luaL_Stream *)luaL_checkudata(L, 1, LUA_FILEHANDLE)); 65 | int res = fclose(p->f); 66 | return luaL_fileresult(L, (res == 0), NULL); 67 | } 68 | 69 | /* This function could be used more generally; see */ 70 | static int 71 | pushfile (lua_State *L, int fd, const char *mode) { 72 | luaL_Stream *p = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream)); 73 | luaL_getmetatable(L, LUA_FILEHANDLE); 74 | lua_setmetatable(L, -2); 75 | p->closef = stdio_fclose; 76 | p->f = fdopen(fd, mode); 77 | return p->f != NULL; 78 | } 79 | 80 | /*** 81 | Create a Lua file object from a file descriptor. 82 | @function fdopen 83 | @tparam int fd file descriptor 84 | @tparam string mode the mode in which to open the file descriptor 85 | @treturn[1] file file Lua file object *fd*, if successful 86 | @return[2] nil 87 | @treturn[2] string error message 88 | @treturn[2] int errnum 89 | @usage 90 | local fdopen = require "posix.stdio".fdopen 91 | local STDOUT_FILENO = require "posix.unistd".STDOUT_FILENO 92 | stdout = fdopen (STDOUT_FILENO, "w") 93 | */ 94 | static int 95 | Pfdopen(lua_State *L) /** fdopen(fd, mode) */ 96 | { 97 | int fd = checkint(L, 1); 98 | const char *mode = luaL_checkstring(L, 2); 99 | checknargs(L, 2); 100 | if (!pushfile(L, fd, mode)) 101 | return pusherror(L, "fdopen"); 102 | return 1; 103 | } 104 | 105 | /*** 106 | Change the name or location of a file 107 | @function rename 108 | @tparam string oldpath 109 | @tparam string newpath 110 | @treturn[1] int `0` if successful 111 | @return[2] nil 112 | @treturn[2] string error message 113 | @treturn[2] int errnum 114 | @see rename(2) 115 | @usage 116 | local ok, errmsg = P.rename (oldpath, newpath) 117 | if not ok then error (errmsg) end 118 | */ 119 | static int 120 | Prename(lua_State *L) /** rename(oldpath, newpath) */ 121 | { 122 | const char *oldpath = luaL_checkstring(L, 1); 123 | const char *newpath = luaL_checkstring(L, 2); 124 | checknargs(L, 2); 125 | return pushresult(L, rename(oldpath, newpath), NULL); 126 | } 127 | 128 | 129 | static const luaL_Reg posix_stdio_fns[] = 130 | { 131 | LPOSIX_FUNC( Pctermid ), 132 | LPOSIX_FUNC( Pfileno ), 133 | LPOSIX_FUNC( Pfdopen ), 134 | LPOSIX_FUNC( Prename ), 135 | {NULL, NULL} 136 | }; 137 | 138 | 139 | /*** 140 | Constants. 141 | @section constants 142 | */ 143 | 144 | /*** 145 | Stdio constants. 146 | Any constants not available in the underlying system will be `nil` valued. 147 | @table posix.stdio 148 | @int _IOFBF fully buffered 149 | @int _IOLBF line buffered 150 | @int _IONBF unbuffered 151 | @int BUFSIZ size of buffer 152 | @int EOF end of file 153 | @int FOPEN_MAX maximum number of open files 154 | @int FILENAME_MAX maximum length of filename 155 | @usage 156 | -- Print stdio constants supported on this host. 157 | for name, value in pairs (require "posix.stdio") do 158 | if type (value) == "number" then 159 | print (name, value) 160 | end 161 | end 162 | */ 163 | 164 | LUALIB_API int 165 | luaopen_posix_stdio(lua_State *L) 166 | { 167 | luaL_register(L, "posix.stdio", posix_stdio_fns); 168 | lua_pushliteral(L, "posix.stdio for " LUA_VERSION " / " PACKAGE_STRING); 169 | lua_setfield(L, -2, "version"); 170 | 171 | /* stdio.h constants */ 172 | /* Those that are omitted already have a Lua interface, or alternative. */ 173 | LPOSIX_CONST( _IOFBF ); 174 | LPOSIX_CONST( _IOLBF ); 175 | LPOSIX_CONST( _IONBF ); 176 | LPOSIX_CONST( BUFSIZ ); 177 | LPOSIX_CONST( EOF ); 178 | LPOSIX_CONST( FOPEN_MAX ); 179 | LPOSIX_CONST( FILENAME_MAX ); 180 | 181 | return 1; 182 | } 183 | -------------------------------------------------------------------------------- /src/dep/luaposix/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define this if your system has a crypt() function */ 5 | //#define HAVE_CRYPT 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | //#define HAVE_CRYPT_H 1 9 | 10 | /* Define to 1 if you have the declaration of `fdatasync', and to 0 if you 11 | don't. */ 12 | //#define HAVE_DECL_FDATASYNC 1 13 | 14 | /* Define to 1 if you have the header file. */ 15 | #define HAVE_DLFCN_H 1 16 | 17 | /* Define to 1 if you have the `fdatasync' function. */ 18 | //#define HAVE_FDATASYNC 1 19 | 20 | /* Define to 1 if you have the `gethostid' function. */ 21 | #define HAVE_GETHOSTID 1 22 | 23 | /* Define to 1 if you have the header file. */ 24 | #define HAVE_INTTYPES_H 1 25 | 26 | /* Define to 1 if you have the header file. */ 27 | #define HAVE_LAUXLIB_H 1 28 | 29 | /* Define to 1 if you have the `rt' library (-lrt). */ 30 | #define HAVE_LIBRT 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | //#define HAVE_LINUX_NETLINK_H 1 34 | 35 | /* Define to 1 if you have the header file. */ 36 | #define HAVE_LUACONF_H 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #define HAVE_LUALIB_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #define HAVE_LUA_H 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_MEMORY_H 1 46 | 47 | /* Define to 1 if you have the `msgrcv' function. */ 48 | #define HAVE_MSGRCV 1 49 | 50 | /* Define to 1 if you have the `msgsnd' function. */ 51 | #define HAVE_MSGSND 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_NET_IF_H 1 55 | 56 | /* Define to 1 if you have the `posix_fadvise' function. */ 57 | //#define HAVE_POSIX_FADVISE 1 58 | 59 | /* Define to 1 if you have the `sched_getsheduler' function. */ 60 | /* #undef HAVE_SCHED_GETSHEDULER */ 61 | 62 | /* Define to 1 if you have the header file. */ 63 | //#define HAVE_SCHED_H 1 64 | 65 | /* Define to 1 if you have the `sched_setscheduler' function. */ 66 | //#define HAVE_SCHED_SETSCHEDULER 1 67 | 68 | /* Define to 1 if you have the `statvfs' function. */ 69 | #define HAVE_STATVFS 1 70 | 71 | /* Define to 1 if you have the header file. */ 72 | #define HAVE_STDINT_H 1 73 | 74 | /* Define to 1 if you have the header file. */ 75 | #define HAVE_STDLIB_H 1 76 | 77 | /* Define to 1 if you have the header file. */ 78 | #define HAVE_STRINGS_H 1 79 | 80 | /* Define to 1 if you have the header file. */ 81 | #define HAVE_STRING_H 1 82 | 83 | /* Define to 1 if you have the `strlcpy' function. */ 84 | /* #undef HAVE_STRLCPY */ 85 | 86 | /* Define if your system has SysV message APIs */ 87 | #define HAVE_SYSV_MESSAGING 1 88 | 89 | /* Define to 1 if you have the header file. */ 90 | #define HAVE_SYS_MSG_H 1 91 | 92 | /* Define to 1 if you have the header file. */ 93 | #define HAVE_SYS_STATVFS_H 1 94 | 95 | /* Define to 1 if you have the header file. */ 96 | #define HAVE_SYS_STAT_H 1 97 | 98 | /* Define to 1 if you have the header file. */ 99 | #define HAVE_SYS_TYPES_H 1 100 | 101 | /* Define to 1 if you have the header file. */ 102 | #define HAVE_UNISTD_H 1 103 | 104 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 105 | #define LT_OBJDIR ".libs/" 106 | 107 | /* Name of package */ 108 | #define PACKAGE "luaposix" 109 | 110 | /* Define to the address where bug reports for this package should be sent. */ 111 | #define PACKAGE_BUGREPORT "http://github.com/luaposix/luaposix/issues" 112 | 113 | /* Define to the full name of this package. */ 114 | #define PACKAGE_NAME "luaposix" 115 | 116 | /* Define to the full name and version of this package. */ 117 | #define PACKAGE_STRING "luaposix 33.4.0" 118 | 119 | /* Define to the one symbol short name of this package. */ 120 | #define PACKAGE_TARNAME "luaposix" 121 | 122 | /* Define to the home page for this package. */ 123 | #define PACKAGE_URL "" 124 | 125 | /* Define to the version of this package. */ 126 | #define PACKAGE_VERSION "33.4.0" 127 | 128 | /* Define to 1 if you have the ANSI C header files. */ 129 | #define STDC_HEADERS 1 130 | 131 | /* Enable extensions on AIX 3, Interix. */ 132 | #ifndef _ALL_SOURCE 133 | # define _ALL_SOURCE 1 134 | #endif 135 | /* Enable GNU extensions on systems that have them. */ 136 | #ifndef _GNU_SOURCE 137 | # define _GNU_SOURCE 1 138 | #endif 139 | /* Enable threading extensions on Solaris. */ 140 | #ifndef _POSIX_PTHREAD_SEMANTICS 141 | # define _POSIX_PTHREAD_SEMANTICS 1 142 | #endif 143 | /* Enable extensions on HP NonStop. */ 144 | #ifndef _TANDEM_SOURCE 145 | # define _TANDEM_SOURCE 1 146 | #endif 147 | /* Enable general extensions on Solaris. */ 148 | #ifndef __EXTENSIONS__ 149 | # define __EXTENSIONS__ 1 150 | #endif 151 | 152 | 153 | /* Version number of package */ 154 | #define VERSION "33.4.0" 155 | 156 | /* Define to 1 if on MINIX. */ 157 | /* #undef _MINIX */ 158 | 159 | /* Define to 2 if the system does not provide POSIX.1 features except with 160 | this defined. */ 161 | /* #undef _POSIX_1_SOURCE */ 162 | 163 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 164 | /* #undef _POSIX_SOURCE */ 165 | -------------------------------------------------------------------------------- /src/dep/lua-5.2.4/src/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.18.1.2 2013/07/09 18:01:41 roberto Exp $ 3 | ** Standard library for bitwise operations 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lbitlib_c 8 | #define LUA_LIB 9 | 10 | #include "lua.h" 11 | 12 | #include "lauxlib.h" 13 | #include "lualib.h" 14 | 15 | 16 | /* number of bits to consider in a number */ 17 | #if !defined(LUA_NBITS) 18 | #define LUA_NBITS 32 19 | #endif 20 | 21 | 22 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 23 | 24 | /* macro to trim extra bits */ 25 | #define trim(x) ((x) & ALLONES) 26 | 27 | 28 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 29 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 30 | 31 | 32 | typedef lua_Unsigned b_uint; 33 | 34 | 35 | 36 | static b_uint andaux (lua_State *L) { 37 | int i, n = lua_gettop(L); 38 | b_uint r = ~(b_uint)0; 39 | for (i = 1; i <= n; i++) 40 | r &= luaL_checkunsigned(L, i); 41 | return trim(r); 42 | } 43 | 44 | 45 | static int b_and (lua_State *L) { 46 | b_uint r = andaux(L); 47 | lua_pushunsigned(L, r); 48 | return 1; 49 | } 50 | 51 | 52 | static int b_test (lua_State *L) { 53 | b_uint r = andaux(L); 54 | lua_pushboolean(L, r != 0); 55 | return 1; 56 | } 57 | 58 | 59 | static int b_or (lua_State *L) { 60 | int i, n = lua_gettop(L); 61 | b_uint r = 0; 62 | for (i = 1; i <= n; i++) 63 | r |= luaL_checkunsigned(L, i); 64 | lua_pushunsigned(L, trim(r)); 65 | return 1; 66 | } 67 | 68 | 69 | static int b_xor (lua_State *L) { 70 | int i, n = lua_gettop(L); 71 | b_uint r = 0; 72 | for (i = 1; i <= n; i++) 73 | r ^= luaL_checkunsigned(L, i); 74 | lua_pushunsigned(L, trim(r)); 75 | return 1; 76 | } 77 | 78 | 79 | static int b_not (lua_State *L) { 80 | b_uint r = ~luaL_checkunsigned(L, 1); 81 | lua_pushunsigned(L, trim(r)); 82 | return 1; 83 | } 84 | 85 | 86 | static int b_shift (lua_State *L, b_uint r, int i) { 87 | if (i < 0) { /* shift right? */ 88 | i = -i; 89 | r = trim(r); 90 | if (i >= LUA_NBITS) r = 0; 91 | else r >>= i; 92 | } 93 | else { /* shift left */ 94 | if (i >= LUA_NBITS) r = 0; 95 | else r <<= i; 96 | r = trim(r); 97 | } 98 | lua_pushunsigned(L, r); 99 | return 1; 100 | } 101 | 102 | 103 | static int b_lshift (lua_State *L) { 104 | return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2)); 105 | } 106 | 107 | 108 | static int b_rshift (lua_State *L) { 109 | return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2)); 110 | } 111 | 112 | 113 | static int b_arshift (lua_State *L) { 114 | b_uint r = luaL_checkunsigned(L, 1); 115 | int i = luaL_checkint(L, 2); 116 | if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1)))) 117 | return b_shift(L, r, -i); 118 | else { /* arithmetic shift for 'negative' number */ 119 | if (i >= LUA_NBITS) r = ALLONES; 120 | else 121 | r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */ 122 | lua_pushunsigned(L, r); 123 | return 1; 124 | } 125 | } 126 | 127 | 128 | static int b_rot (lua_State *L, int i) { 129 | b_uint r = luaL_checkunsigned(L, 1); 130 | i &= (LUA_NBITS - 1); /* i = i % NBITS */ 131 | r = trim(r); 132 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 133 | r = (r << i) | (r >> (LUA_NBITS - i)); 134 | lua_pushunsigned(L, trim(r)); 135 | return 1; 136 | } 137 | 138 | 139 | static int b_lrot (lua_State *L) { 140 | return b_rot(L, luaL_checkint(L, 2)); 141 | } 142 | 143 | 144 | static int b_rrot (lua_State *L) { 145 | return b_rot(L, -luaL_checkint(L, 2)); 146 | } 147 | 148 | 149 | /* 150 | ** get field and width arguments for field-manipulation functions, 151 | ** checking whether they are valid. 152 | ** ('luaL_error' called without 'return' to avoid later warnings about 153 | ** 'width' being used uninitialized.) 154 | */ 155 | static int fieldargs (lua_State *L, int farg, int *width) { 156 | int f = luaL_checkint(L, farg); 157 | int w = luaL_optint(L, farg + 1, 1); 158 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 159 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 160 | if (f + w > LUA_NBITS) 161 | luaL_error(L, "trying to access non-existent bits"); 162 | *width = w; 163 | return f; 164 | } 165 | 166 | 167 | static int b_extract (lua_State *L) { 168 | int w; 169 | b_uint r = luaL_checkunsigned(L, 1); 170 | int f = fieldargs(L, 2, &w); 171 | r = (r >> f) & mask(w); 172 | lua_pushunsigned(L, r); 173 | return 1; 174 | } 175 | 176 | 177 | static int b_replace (lua_State *L) { 178 | int w; 179 | b_uint r = luaL_checkunsigned(L, 1); 180 | b_uint v = luaL_checkunsigned(L, 2); 181 | int f = fieldargs(L, 3, &w); 182 | int m = mask(w); 183 | v &= m; /* erase bits outside given width */ 184 | r = (r & ~(m << f)) | (v << f); 185 | lua_pushunsigned(L, r); 186 | return 1; 187 | } 188 | 189 | 190 | static const luaL_Reg bitlib[] = { 191 | {"arshift", b_arshift}, 192 | {"band", b_and}, 193 | {"bnot", b_not}, 194 | {"bor", b_or}, 195 | {"bxor", b_xor}, 196 | {"btest", b_test}, 197 | {"extract", b_extract}, 198 | {"lrotate", b_lrot}, 199 | {"lshift", b_lshift}, 200 | {"replace", b_replace}, 201 | {"rrotate", b_rrot}, 202 | {"rshift", b_rshift}, 203 | {NULL, NULL} 204 | }; 205 | 206 | 207 | 208 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 209 | luaL_newlib(L, bitlib); 210 | return 1; 211 | } 212 | 213 | -------------------------------------------------------------------------------- /src/dep/luaposix/compat-5.2.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lua.h" 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | 8 | #if !defined(LUA_VERSION_NUM) 9 | /* Lua 5.0 */ 10 | 11 | #define LUA_QL(x) "'" x "'" 12 | #define LUA_QS LUA_QL("%s") 13 | 14 | #define luaL_Reg luaL_reg 15 | 16 | #define luaL_opt(L, f, n, d) \ 17 | (lua_isnoneornil(L, n) ? (d) : f(L, n)) 18 | 19 | #define luaL_addchar(B,c) \ 20 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 21 | (*(B)->p++ = (char)(c))) 22 | 23 | #endif /* Lua 5.0 */ 24 | 25 | 26 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 27 | /* Lua 5.1 */ 28 | 29 | /* PUC-Rio Lua uses lconfig_h as include guard for luaconf.h, 30 | * LuaJIT uses luaconf_h. If you use PUC-Rio's include files 31 | * but LuaJIT's library, you will need to define the macro 32 | * COMPAT52_IS_LUAJIT yourself! */ 33 | #if !defined(COMPAT52_IS_LUAJIT) && defined(luaconf_h) 34 | #define COMPAT52_IS_LUAJIT 35 | #endif 36 | 37 | /* LuaJIT doesn't define these unofficial macros ... */ 38 | #if !defined(LUAI_INT32) 39 | #include 40 | #if INT_MAX-20 < 32760 41 | #define LUAI_INT32 long 42 | #define LUAI_UINT32 unsigned long 43 | #elif INT_MAX > 2147483640L 44 | #define LUAI_INT32 int 45 | #define LUAI_UINT32 unsigned int 46 | #else 47 | #error "could not detect suitable lua_Unsigned datatype" 48 | #endif 49 | #endif 50 | 51 | #define LUA_OPADD 0 52 | #define LUA_OPSUB 1 53 | #define LUA_OPMUL 2 54 | #define LUA_OPDIV 3 55 | #define LUA_OPMOD 4 56 | #define LUA_OPPOW 5 57 | #define LUA_OPUNM 6 58 | #define LUA_OPEQ 0 59 | #define LUA_OPLT 1 60 | #define LUA_OPLE 2 61 | 62 | typedef LUAI_UINT32 lua_Unsigned; 63 | 64 | typedef struct luaL_Buffer_52 { 65 | luaL_Buffer b; /* make incorrect code crash! */ 66 | char *ptr; 67 | size_t nelems; 68 | size_t capacity; 69 | lua_State *L2; 70 | } luaL_Buffer_52; 71 | #define luaL_Buffer luaL_Buffer_52 72 | 73 | typedef struct luaL_Stream { 74 | FILE *f; 75 | /* The following field is for LuaJIT which adds a uint32_t field 76 | * to file handles. */ 77 | lua_Unsigned type; 78 | lua_CFunction closef; 79 | } luaL_Stream; 80 | 81 | 82 | #define lua_tounsigned(L, i) lua_tounsignedx(L, i, NULL) 83 | 84 | #define lua_rawlen(L, i) lua_objlen(L, i) 85 | 86 | void lua_arith (lua_State *L, int op); 87 | int lua_compare (lua_State *L, int idx1, int idx2, int op); 88 | void lua_pushunsigned (lua_State *L, lua_Unsigned n); 89 | lua_Unsigned luaL_checkunsigned (lua_State *L, int i); 90 | lua_Unsigned lua_tounsignedx (lua_State *L, int i, int *isnum); 91 | lua_Unsigned luaL_optunsigned (lua_State *L, int i, lua_Unsigned def); 92 | lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); 93 | void lua_len (lua_State *L, int i); 94 | int luaL_len (lua_State *L, int i); 95 | const char *luaL_tolstring (lua_State *L, int idx, size_t *len); 96 | void luaL_requiref (lua_State *L, char const* modname, lua_CFunction openf, int glb); 97 | 98 | #define luaL_buffinit luaL_buffinit_52 99 | void luaL_buffinit (lua_State *L, luaL_Buffer_52 *B); 100 | 101 | #define luaL_prepbuffsize luaL_prepbuffsize_52 102 | char *luaL_prepbuffsize (luaL_Buffer_52 *B, size_t s); 103 | 104 | #define luaL_addlstring luaL_addlstring_52 105 | void luaL_addlstring (luaL_Buffer_52 *B, const char *s, size_t l); 106 | 107 | #define luaL_addvalue luaL_addvalue_52 108 | void luaL_addvalue (luaL_Buffer_52 *B); 109 | 110 | #define luaL_pushresult luaL_pushresult_52 111 | void luaL_pushresult (luaL_Buffer_52 *B); 112 | 113 | #undef luaL_buffinitsize 114 | #define luaL_buffinitsize(L, B, s) \ 115 | (luaL_buffinit(L, B), luaL_prepbuffsize(B, s)) 116 | 117 | #undef luaL_prepbuffer 118 | #define luaL_prepbuffer(B) \ 119 | luaL_prepbuffsize(B, LUAL_BUFFERSIZE) 120 | 121 | #undef luaL_addchar 122 | #define luaL_addchar(B, c) \ 123 | ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize(B, 1)), \ 124 | ((B)->ptr[(B)->nelems++] = (c))) 125 | 126 | #undef luaL_addsize 127 | #define luaL_addsize(B, s) \ 128 | ((B)->nelems += (s)) 129 | 130 | #undef luaL_addstring 131 | #define luaL_addstring(B, s) \ 132 | luaL_addlstring(B, s, strlen(s)) 133 | 134 | #undef luaL_pushresultsize 135 | #define luaL_pushresultsize(B, s) \ 136 | (luaL_addsize(B, s), luaL_pushresult(B)) 137 | 138 | #endif /* Lua 5.1 */ 139 | 140 | 141 | #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501 142 | /* Lua 5.0 *or* 5.1 */ 143 | 144 | #define LUA_OK 0 145 | 146 | #define lua_pushglobaltable(L) \ 147 | lua_pushvalue(L, LUA_GLOBALSINDEX) 148 | 149 | #define luaL_newlib(L, l) \ 150 | (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) 151 | 152 | void luaL_checkversion (lua_State *L); 153 | 154 | #endif /* Lua 5.0 *or* 5.1 */ 155 | 156 | int lua_absindex (lua_State *L, int i); 157 | void lua_copy (lua_State *L, int from, int to); 158 | void lua_rawgetp (lua_State *L, int i, const void *p); 159 | void lua_rawsetp (lua_State *L, int i, const void *p); 160 | void *luaL_testudata (lua_State *L, int i, const char *tname); 161 | lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); 162 | void lua_getuservalue (lua_State *L, int i); 163 | void lua_setuservalue (lua_State *L, int i); 164 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 165 | void luaL_setmetatable (lua_State *L, const char *tname); 166 | int luaL_getsubtable (lua_State *L, int i, const char *name); 167 | void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); 168 | int luaL_fileresult (lua_State *L, int stat, const char *fname); 169 | --------------------------------------------------------------------------------