Added lua-zlib, lfs and luv support for LUA, exposed all using luaengine (nw)

This commit is contained in:
Miodrag Milanovic 2016-02-14 08:16:35 +01:00
parent 80e8fe80e6
commit 2db4908814
146 changed files with 16054 additions and 34 deletions

1
3rdparty/lua-zlib/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
lua_zlib.c export-subst ident

62
3rdparty/lua-zlib/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,62 @@
# Copyright (C) 2007-2009 LuaDist.
# Submitted by David Manura
# Redistribution and use of this file is allowed according to the
# terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Please note that the package source code is licensed under its own
# license.
PROJECT(lua-zlib C)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
option(USE_LUA "Use Lua (also called 'C' Lua) includes (default)" ON)
option(USE_LUAJIT "Use LuaJIT includes instead of 'C' Lua ones (recommended, if you're using LuaJIT, but disabled by default)")
set(USE_LUA_VERSION 5.1 CACHE STRING "Set the Lua version to use (default: 5.1)")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
if(USE_LUAJIT)
# Find luajit
find_package(LuaJIT REQUIRED)
set(USE_LUA OFF)
# / Find lua
endif()
if(USE_LUA)
# Find lua
find_package(Lua ${USE_LUA_VERSION} EXACT REQUIRED)
# / Find lua
endif()
# Basic configurations
SET(INSTALL_CMOD share/lua/cmod CACHE PATH "Directory to install Lua binary modules (configure lua via LUA_CPATH)")
# / configs
# Find zlib
FIND_PACKAGE(ZLIB REQUIRED)
# / Find zlib
# Define how to build zlib.so:
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
ADD_LIBRARY(cmod_zlib MODULE
lua_zlib.c zlib.def)
SET_TARGET_PROPERTIES(cmod_zlib PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(cmod_zlib PROPERTIES OUTPUT_NAME zlib)
TARGET_LINK_LIBRARIES(cmod_zlib ${ZLIB_LIBRARIES})
# / build zlib.so
# Define how to test zlib.so:
INCLUDE(CTest)
SET(LUA_BIN "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
FIND_PROGRAM(LUA NAMES ${LUA_BIN} lua luajit lua.bat)
ADD_TEST(basic ${LUA} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua ${CMAKE_CURRENT_SOURCE_DIR}/ ${CMAKE_CURRENT_BINARY_DIR}/)
SET_TESTS_PROPERTIES(basic
PROPERTIES
FAIL_REGULAR_EXPRESSION
"not ok")
# / test zlib.so
# Where to install stuff
INSTALL (TARGETS cmod_zlib DESTINATION ${INSTALL_CMOD})
# / Where to install.

62
3rdparty/lua-zlib/Makefile vendored Normal file
View File

@ -0,0 +1,62 @@
# This Makefile is based on LuaSec's Makefile. Thanks to the LuaSec developers.
# Inform the location to intall the modules
LUAPATH ?= /usr/share/lua/5.1
LUACPATH ?= /usr/lib/lua/5.1
INCDIR ?= -I/usr/include/lua5.1
LIBDIR ?= -L/usr/lib
# For Mac OS X: set the system version
MACOSX_VERSION = 10.4
CMOD = zlib.so
OBJS = lua_zlib.o
LIBS = -lz -llua -lm
WARN = -Wall -pedantic
BSD_CFLAGS = -O2 -fPIC $(WARN) $(INCDIR) $(DEFS)
BSD_LDFLAGS = -O -shared -fPIC $(LIBDIR)
LNX_CFLAGS = -O2 -fPIC $(WARN) $(INCDIR) $(DEFS)
LNX_LDFLAGS = -O -shared -fPIC $(LIBDIR)
MAC_ENV = env MACOSX_DEPLOYMENT_TARGET='$(MACVER)'
MAC_CFLAGS = -O2 -fPIC -fno-common $(WARN) $(INCDIR) $(DEFS)
MAC_LDFLAGS = -bundle -undefined dynamic_lookup -fPIC $(LIBDIR)
CC = gcc
LD = $(MYENV) gcc
CFLAGS = $(MYCFLAGS)
LDFLAGS = $(MYLDFLAGS)
.PHONY: all clean install none linux bsd macosx
all:
@echo "Usage: $(MAKE) <platform>"
@echo " * linux"
@echo " * bsd"
@echo " * macosx"
install: $(CMOD)
cp $(CMOD) $(LUACPATH)
uninstall:
rm $(LUACPATH)/zlib.so
linux:
@$(MAKE) $(CMOD) MYCFLAGS="$(LNX_CFLAGS)" MYLDFLAGS="$(LNX_LDFLAGS)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)"
bsd:
@$(MAKE) $(CMOD) MYCFLAGS="$(BSD_CFLAGS)" MYLDFLAGS="$(BSD_LDFLAGS)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)"
macosx:
@$(MAKE) $(CMOD) MYCFLAGS="$(MAC_CFLAGS)" MYLDFLAGS="$(MAC_LDFLAGS)" MYENV="$(MAC_ENV)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)"
clean:
rm -f $(OBJS) $(CMOD)
.c.o:
$(CC) -c $(CFLAGS) $(DEFS) $(INCDIR) -o $@ $<
$(CMOD): $(OBJS)
$(LD) $(LDFLAGS) $(LIBDIR) $(OBJS) $(LIBS) -o $@

151
3rdparty/lua-zlib/README vendored Normal file
View File

@ -0,0 +1,151 @@
**********************************************************************
* Author : Brian Maher <maherb at brimworks dot com>
* Library : lua_zlib - Lua 5.1 interface to zlib
*
* The MIT License
*
* Copyright (c) 2009 Brian Maher
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**********************************************************************
To use this library, you need zlib, get it here:
http://www.gzip.org/zlib/
To build this library, you can use CMake and get it here:
http://www.cmake.org/cmake/resources/software.html
...or you can use GNU Make.
make <platform>
Loading the library:
If you built the library as a loadable package
[local] zlib = require 'zlib'
If you compiled the package statically into your application, call
the function "luaopen_zlib(L)". It will create a table with the zlib
functions and leave it on the stack.
-- zlib functions --
int major, int minor, int patch = zlib.version()
returns numeric zlib version for the major, minor, and patch
levels of the version dynamically linked in.
function stream = zlib.deflate([ int compression_level ], [ int window_size ])
If no compression_level is provided uses Z_DEFAULT_COMPRESSION (6),
compression level is a number from 1-9 where zlib.BEST_SPEED is 1
and zlib.BEST_COMPRESSION is 9.
Returns a "stream" function that compresses (or deflates) all
strings passed in. Specifically, use it as such:
string deflated, bool eof, int bytes_in, int bytes_out =
stream(string input [, 'sync' | 'full' | 'finish'])
Takes input and deflates and returns a portion of it,
optionally forcing a flush.
A 'sync' flush will force all pending output to be flushed to
the return value and the output is aligned on a byte boundary,
so that the decompressor can get all input data available so
far. Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
A 'full' flush will flush all output as with 'sync', and the
compression state is reset so that decompression can restart
from this point if previous compressed data has been damaged
or if random access is desired. Using Z_FULL_FLUSH too often
can seriously degrade the compression.
A 'finish' flush will force all pending output to be processed
and results in the stream become unusable. Any future
attempts to print anything other than the empty string will
result in an error that begins with IllegalState.
The eof result is true if 'finish' was specified, otherwise
it is false.
The bytes_in is how many bytes of input have been passed to
stream, and bytes_out is the number of bytes returned in
deflated string chunks.
function stream = zlib.inflate([int windowBits])
Returns a "stream" function that decompresses (or inflates) all
strings passed in. Optionally specify a windowBits argument
that is passed to inflateInit2(), see zlib.h for details about
this argument. By default, gzip header detection is done, and
the max window size is used.
The "stream" function should be used as such:
string inflated, bool eof, int bytes_in, int bytes_out =
stream(string input)
Takes input and inflates and returns a portion of it. If it
detects the end of a deflation stream, then total will be the
total number of bytes read from input and all future calls to
stream() with a non empty string will result in an error that
begins with IllegalState.
No flush options are provided since the maximal amount of
input is always processed.
eof will be true when the input string is determined to be at
the "end of the file".
The bytes_in is how many bytes of input have been passed to
stream, and bytes_out is the number of bytes returned in
inflated string chunks.
function compute_checksum = zlib.adler32()
function compute_checksum = zlib.crc32()
Create a new checksum computation function using either the
adler32 or crc32 algorithms. This resulting function should be
used as such:
int checksum = compute_checksum(string input |
function compute_checksum)
The compute_checksum function takes as input either a string
that is logically getting appended to or another
compute_checksum function that is logically getting appended.
The result is the updated checksum.
For example, these uses will all result in the same checksum:
-- All in one call:
local csum = zlib.crc32()("one two")
-- Multiple calls:
local compute = zlib.crc32()
compute("one")
assert(csum == compute(" two"))
-- Multiple compute_checksums joined:
local compute1, compute2 = zlib.crc32(), zlib.crc32()
compute1("one")
compute2(" two")
assert(csum == compute1(compute2))

BIN
3rdparty/lua-zlib/amnon_david.gz vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,63 @@
# Locate LuaJIT library
# This module defines
# LUAJIT_FOUND, if false, do not try to link to Lua
# LUA_LIBRARIES
# LUA_INCLUDE_DIR, where to find lua.h
# LUAJIT_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
## Copied from default CMake FindLua51.cmake
find_path(LUA_INCLUDE_DIR luajit.h
HINTS
ENV LUA_DIR
PATH_SUFFIXES include/luajit-2.0 include
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(LUA_LIBRARY
NAMES luajit-5.1
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
)
if(LUA_LIBRARY)
# include the math library for Unix
if(UNIX AND NOT APPLE)
find_library(LUA_MATH_LIBRARY m)
set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
# For Windows and Mac, don't need to explicitly include the math library
else()
set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
endif()
endif()
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/luajit.h")
file(STRINGS "${LUA_INCLUDE_DIR}/luajit.h" luajit_version_str REGEX "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT .+\"")
string(REGEX REPLACE "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT ([^\"]+)\".*" "\\1" LUAJIT_VERSION_STRING "${luajit_version_str}")
unset(luajit_version_str)
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJIT
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUAJIT_VERSION_STRING)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)

401
3rdparty/lua-zlib/lua_zlib.c vendored Normal file
View File

@ -0,0 +1,401 @@
#include <ctype.h>
#include <lauxlib.h>
#include <lua.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
/*
* ** compatibility with Lua 5.2
* */
#if (LUA_VERSION_NUM >= 502)
#undef luaL_register
#define luaL_register(L,n,f) \
{ if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); }
#endif
#if (LUA_VERSION_NUM >= 503)
#undef luaL_optint
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L,(n),(d)))
#endif
#define DEF_MEM_LEVEL 8
typedef uLong (*checksum_t) (uLong crc, const Bytef *buf, uInt len);
typedef uLong (*checksum_combine_t)(uLong crc1, uLong crc2, z_off_t len2);
static int lz_deflate(lua_State *L);
static int lz_deflate_delete(lua_State *L);
static int lz_inflate_delete(lua_State *L);
static int lz_inflate(lua_State *L);
static int lz_checksum(lua_State *L);
static int lz_checksum_new(lua_State *L, checksum_t checksum, checksum_combine_t combine);
static int lz_adler32(lua_State *L);
static int lz_crc32(lua_State *L);
static int lz_version(lua_State *L) {
const char* version = zlibVersion();
int count = strlen(version) + 1;
char* cur = (char*)memcpy(lua_newuserdata(L, count),
version, count);
count = 0;
while ( *cur ) {
char* begin = cur;
/* Find all digits: */
while ( isdigit(*cur) ) cur++;
if ( begin != cur ) {
int is_end = *cur == '\0';
*cur = '\0';
lua_pushnumber(L, atoi(begin));
count++;
if ( is_end ) break;
cur++;
}
while ( *cur && ! isdigit(*cur) ) cur++;
}
return count;
}
static int lz_assert(lua_State *L, int result, const z_stream* stream, const char* file, int line) {
/* Both of these are "normal" return codes: */
if ( result == Z_OK || result == Z_STREAM_END ) return result;
switch ( result ) {
case Z_NEED_DICT:
lua_pushfstring(L, "RequiresDictionary: input stream requires a dictionary to be deflated (%s) at %s line %d",
stream->msg, file, line);
break;
case Z_STREAM_ERROR:
lua_pushfstring(L, "InternalError: inconsistent internal zlib stream (%s) at %s line %d",
stream->msg, file, line);
break;
case Z_DATA_ERROR:
lua_pushfstring(L, "InvalidInput: input string does not conform to zlib format or checksum failed at %s line %d",
file, line);
break;
case Z_MEM_ERROR:
lua_pushfstring(L, "OutOfMemory: not enough memory (%s) at %s line %d",
stream->msg, file, line);
break;
case Z_BUF_ERROR:
lua_pushfstring(L, "InternalError: no progress possible (%s) at %s line %d",
stream->msg, file, line);
break;
case Z_VERSION_ERROR:
lua_pushfstring(L, "IncompatibleLibrary: built with version %s, but dynamically linked with version %s (%s) at %s line %d",
ZLIB_VERSION, zlibVersion(), stream->msg, file, line);
break;
default:
lua_pushfstring(L, "ZLibError: unknown code %d (%s) at %s line %d",
result, stream->msg, file, line);
}
lua_error(L);
return result;
}
/**
* @upvalue z_stream - Memory for the z_stream.
* @upvalue remainder - Any remainder from the last deflate call.
*
* @param string - "print" to deflate stream.
* @param int - flush output buffer? Z_SYNC_FLUSH, Z_FULL_FLUSH, or Z_FINISH.
*
* if no params, terminates the stream (as if we got empty string and Z_FINISH).
*/
static int lz_filter_impl(lua_State *L, int (*filter)(z_streamp, int), int (*end)(z_streamp), const char* name) {
int flush = Z_NO_FLUSH, result;
z_stream* stream;
luaL_Buffer buff;
size_t avail_in;
if ( filter == deflate ) {
const char *const opts[] = { "none", "sync", "full", "finish", NULL };
flush = luaL_checkoption(L, 2, opts[0], opts);
if ( flush ) flush++;
/* Z_NO_FLUSH(0) Z_SYNC_FLUSH(2), Z_FULL_FLUSH(3), Z_FINISH (4) */
/* No arguments or nil, we are terminating the stream: */
if ( lua_gettop(L) == 0 || lua_isnil(L, 1) ) {
flush = Z_FINISH;
}
}
stream = (z_stream*)lua_touserdata(L, lua_upvalueindex(1));
if ( stream == NULL ) {
if ( lua_gettop(L) >= 1 && lua_isstring(L, 1) ) {
lua_pushfstring(L, "IllegalState: calling %s function when stream was previously closed", name);
lua_error(L);
}
lua_pushstring(L, "");
lua_pushboolean(L, 1);
return 2; /* Ignore duplicate calls to "close". */
}
luaL_buffinit(L, &buff);
if ( lua_gettop(L) > 1 ) lua_pushvalue(L, 1);
if ( lua_isstring(L, lua_upvalueindex(2)) ) {
lua_pushvalue(L, lua_upvalueindex(2));
if ( lua_gettop(L) > 1 && lua_isstring(L, -2) ) {
lua_concat(L, 2);
}
}
/* Do the actual deflate'ing: */
if (lua_gettop(L) > 0) {
stream->next_in = (unsigned char*)lua_tolstring(L, -1, &avail_in);
} else {
stream->next_in = NULL;
avail_in = 0;
}
stream->avail_in = avail_in;
if ( ! stream->avail_in && ! flush ) {
/* Passed empty string, make it a noop instead of erroring out. */
lua_pushstring(L, "");
lua_pushboolean(L, 0);
lua_pushinteger(L, stream->total_in);
lua_pushinteger(L, stream->total_out);
return 4;
}
do {
stream->next_out = (unsigned char*)luaL_prepbuffer(&buff);
stream->avail_out = LUAL_BUFFERSIZE;
result = filter(stream, flush);
if ( Z_BUF_ERROR != result ) {
/* Ignore Z_BUF_ERROR since that just indicates that we
* need a larger buffer in order to proceed. Thanks to
* Tobias Markmann for finding this bug!
*/
lz_assert(L, result, stream, __FILE__, __LINE__);
}
luaL_addsize(&buff, LUAL_BUFFERSIZE - stream->avail_out);
} while ( stream->avail_out == 0 );
/* Need to do this before we alter the stack: */
luaL_pushresult(&buff);
/* Save remainder in lua_upvalueindex(2): */
if ( NULL != stream->next_in ) {
lua_pushlstring(L, (char*)stream->next_in, stream->avail_in);
lua_replace(L, lua_upvalueindex(2));
}
/* "close" the stream/remove finalizer: */
if ( result == Z_STREAM_END ) {
/* Clear-out the metatable so end is not called twice: */
lua_pushnil(L);
lua_setmetatable(L, lua_upvalueindex(1));
/* nil the upvalue: */
lua_pushnil(L);
lua_replace(L, lua_upvalueindex(1));
/* Close the stream: */
lz_assert(L, end(stream), stream, __FILE__, __LINE__);
lua_pushboolean(L, 1);
} else {
lua_pushboolean(L, 0);
}
lua_pushinteger(L, stream->total_in);
lua_pushinteger(L, stream->total_out);
return 4;
}
static void lz_create_deflate_mt(lua_State *L) {
luaL_newmetatable(L, "lz.deflate.meta"); /* {} */
lua_pushcfunction(L, lz_deflate_delete);
lua_setfield(L, -2, "__gc");
lua_pop(L, 1); /* <empty> */
}
static int lz_deflate_new(lua_State *L) {
int level = luaL_optint(L, 1, Z_DEFAULT_COMPRESSION);
int window_size = luaL_optint(L, 2, MAX_WBITS);
/* Allocate the stream: */
z_stream* stream = (z_stream*)lua_newuserdata(L, sizeof(z_stream));
stream->zalloc = Z_NULL;
stream->zfree = Z_NULL;
int result = deflateInit2(stream, level, Z_DEFLATED, window_size,
DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
lz_assert(L, result, stream, __FILE__, __LINE__);
/* Don't allow destructor to execute unless deflateInit2 was successful: */
luaL_getmetatable(L, "lz.deflate.meta");
lua_setmetatable(L, -2);
lua_pushnil(L);
lua_pushcclosure(L, lz_deflate, 2);
return 1;
}
static int lz_deflate(lua_State *L) {
return lz_filter_impl(L, deflate, deflateEnd, "deflate");
}
static int lz_deflate_delete(lua_State *L) {
z_stream* stream = (z_stream*)lua_touserdata(L, 1);
/* Ignore errors. */
deflateEnd(stream);
return 0;
}
static void lz_create_inflate_mt(lua_State *L) {
luaL_newmetatable(L, "lz.inflate.meta"); /* {} */
lua_pushcfunction(L, lz_inflate_delete);
lua_setfield(L, -2, "__gc");
lua_pop(L, 1); /* <empty> */
}
static int lz_inflate_new(lua_State *L) {
/* Allocate the stream */
z_stream* stream = (z_stream*)lua_newuserdata(L, sizeof(z_stream));
/* By default, we will do gzip header detection w/ max window size */
int window_size = lua_isnumber(L, 1) ? lua_tointeger(L, 1) : MAX_WBITS + 32;
stream->zalloc = Z_NULL;
stream->zfree = Z_NULL;
stream->next_in = Z_NULL;
stream->avail_in = 0;
lz_assert(L, inflateInit2(stream, window_size), stream, __FILE__, __LINE__);
/* Don't allow destructor to execute unless deflateInit was successful: */
luaL_getmetatable(L, "lz.inflate.meta");
lua_setmetatable(L, -2);
lua_pushnil(L);
lua_pushcclosure(L, lz_inflate, 2);
return 1;
}
static int lz_inflate(lua_State *L) {
return lz_filter_impl(L, inflate, inflateEnd, "inflate");
}
static int lz_inflate_delete(lua_State *L) {
z_stream* stream = (z_stream*)lua_touserdata(L, 1);
/* Ignore errors: */
inflateEnd(stream);
return 0;
}
static int lz_checksum(lua_State *L) {
if ( lua_gettop(L) <= 0 ) {
lua_pushvalue(L, lua_upvalueindex(3));
lua_pushvalue(L, lua_upvalueindex(4));
} else if ( lua_isfunction(L, 1) ) {
checksum_combine_t combine = (checksum_combine_t)
lua_touserdata(L, lua_upvalueindex(2));
lua_pushvalue(L, 1);
lua_call(L, 0, 2);
if ( ! lua_isnumber(L, -2) || ! lua_isnumber(L, -1) ) {
luaL_argerror(L, 1, "expected function to return two numbers");
}
/* Calculate and replace the checksum */
lua_pushnumber(L,
combine(lua_tonumber(L, lua_upvalueindex(3)),
lua_tonumber(L, -2),
lua_tonumber(L, -1)));
lua_pushvalue(L, -1);
lua_replace(L, lua_upvalueindex(3));
/* Calculate and replace the length */
lua_pushnumber(L,
lua_tonumber(L, lua_upvalueindex(4)) + lua_tonumber(L, -2));
lua_pushvalue(L, -1);
lua_replace(L, lua_upvalueindex(4));
} else {
const Bytef* str;
size_t len;
checksum_t checksum = (checksum_t)
lua_touserdata(L, lua_upvalueindex(1));
str = (const Bytef*)luaL_checklstring(L, 1, &len);
/* Calculate and replace the checksum */
lua_pushnumber(L,
checksum(lua_tonumber(L, lua_upvalueindex(3)),
str,
len));
lua_pushvalue(L, -1);
lua_replace(L, lua_upvalueindex(3));
/* Calculate and replace the length */
lua_pushnumber(L,
lua_tonumber(L, lua_upvalueindex(4)) + len);
lua_pushvalue(L, -1);
lua_replace(L, lua_upvalueindex(4));
}
return 2;
}
static int lz_checksum_new(lua_State *L, checksum_t checksum, checksum_combine_t combine) {
lua_pushlightuserdata(L, checksum);
lua_pushlightuserdata(L, combine);
lua_pushnumber(L, checksum(0L, Z_NULL, 0));
lua_pushnumber(L, 0);
lua_pushcclosure(L, lz_checksum, 4);
return 1;
}
static int lz_adler32(lua_State *L) {
return lz_checksum_new(L, adler32, adler32_combine);
}
static int lz_crc32(lua_State *L) {
return lz_checksum_new(L, crc32, crc32_combine);
}
static const luaL_Reg zlib_functions[] = {
{ "deflate", lz_deflate_new },
{ "inflate", lz_inflate_new },
{ "adler32", lz_adler32 },
{ "crc32", lz_crc32 },
{ "version", lz_version },
{ NULL, NULL }
};
#define SETLITERAL(n,v) (lua_pushliteral(L, n), lua_pushliteral(L, v), lua_settable(L, -3))
#define SETINT(n,v) (lua_pushliteral(L, n), lua_pushinteger(L, v), lua_settable(L, -3))
LUALIB_API int luaopen_zlib(lua_State * const L) {
lz_create_deflate_mt(L);
lz_create_inflate_mt(L);
luaL_register(L, "zlib", zlib_functions);
SETINT("BEST_SPEED", Z_BEST_SPEED);
SETINT("BEST_COMPRESSION", Z_BEST_COMPRESSION);
SETLITERAL("_COPYRIGHT", "Copyright (c) 2009-2010 Brian Maher");
SETLITERAL("_DESCRIPTION", "Yet another binding to the zlib library");
SETLITERAL("_VERSION", "lua-zlib $Id$ $Format:%d$");
/* Expose this to lua so we can do a test: */
SETINT("_TEST_BUFSIZ", LUAL_BUFFERSIZE);
return 1;
}

35
3rdparty/lua-zlib/rockspec vendored Normal file
View File

@ -0,0 +1,35 @@
package = "lua-zlib"
version = "0.3-1"
source = {
url = "git://github.com/brimworks/lua-zlib.git",
tag = "v0.4",
}
description = {
summary = "Simple streaming interface to zlib for Lua.",
detailed = [[
Simple streaming interface to zlib for Lua.
Consists of two functions: inflate and deflate.
Both functions return "stream functions" (takes a buffer of input and returns a buffer of output).
This project is hosted on github.
]],
homepage = "https://github.com/brimworks/lua-zlib",
license = "MIT"
}
dependencies = {
"lua >= 5.1, < 5.3"
}
external_dependencies = {
ZLIB = {
header = "zlib.h"
}
}
build = {
type = "builtin",
modules = {
zlib = {
sources = { "lua_zlib.c" };
libraries = { "z" },
};
}
}

24
3rdparty/lua-zlib/tap.lua vendored Normal file
View File

@ -0,0 +1,24 @@
local tap_module = {}
local os = require("os")
local counter = 1
local failed = false
function tap_module.ok(assert_true, desc)
local msg = ( assert_true and "ok " or "not ok " ) .. counter
if ( not assert_true ) then
failed = true
end
if ( desc ) then
msg = msg .. " - " .. desc
end
print(msg)
counter = counter + 1
end
function tap_module.exit()
os.exit(failed and 1 or 0)
end
return tap_module

198
3rdparty/lua-zlib/test.lua vendored Normal file
View File

@ -0,0 +1,198 @@
print "1..9"
local src_dir, build_dir = ...
package.path = (src_dir or "./") .. "?.lua;" .. package.path
package.cpath = (build_dir or "./") .. "?.so;" .. package.cpath
local tap = require("tap")
local lz = require("zlib")
local ok = tap.ok
local table = require("table")
local io = require("io")
function main()
test_stats()
test_buff_err()
test_small_inputs()
test_basic()
test_large()
test_no_input()
test_invalid_input()
test_streaming()
test_illegal_state()
test_checksum()
test_version()
test_tom_macwright()
test_amnon_david()
end
function test_tom_macwright()
local deflated =
assert(io.open(src_dir.. "/tom_macwright.gz")):read("*a")
local inflated = lz.inflate()(deflated)
local expected_inflated =
assert(io.open(src_dir.. "/tom_macwright.out")):read("*a")
ok(expected_inflated == inflated, "Tom MacWright Test")
end
function test_amnon_david()
local body = assert(io.open(src_dir.."/amnon_david.gz")):read("*a")
local inflate = lz.inflate()
local inflated, eof, bytes_in, bytes_out = inflate(body)
local deflate = lz.deflate()
local deflated, eof, bytes_in, bytes_out = deflate(inflated, "full")
end
function test_stats()
local string = ("one"):rep(20)
local deflated, eof, bin, bout = lz.deflate()(string, 'finish')
ok(eof == true, "eof is true (" .. tostring(eof) .. ")");
ok(bin > bout, "bytes in is greater than bytes out?")
ok(#deflated == bout, "bytes out is the same size as deflated string length")
ok(#string == bin, "bytes in is the same size as the input string length")
end
-- Thanks to Tobias Markmann for the bug report! We are trying to
-- force inflate() to return a Z_BUF_ERROR (which should be recovered
-- from). For some reason this only happens when the input is exactly
-- LUAL_BUFFERSIZE (at least on my machine).
function test_buff_err()
local text = ("X"):rep(lz._TEST_BUFSIZ);
local deflated = lz.deflate()(text, 'finish')
for i=1,#deflated do
lz.inflate()(deflated:sub(1,i))
end
end
function test_small_inputs()
local text = ("X"):rep(lz._TEST_BUFSIZ);
local deflated = lz.deflate()(text, 'finish')
local inflated = {}
local inflator = lz.inflate()
for i=1,#deflated do
local part = inflator(deflated:sub(i,i))
table.insert(inflated, part)
end
inflated = table.concat(inflated)
ok(inflated == text, "Expected " .. #text .. " Xs got " .. #inflated)
end
function test_basic()
local test_string = "abcdefghijklmnopqrstuv"
ok(lz.inflate()(lz.deflate()(), "finish") == "")
-- Input to deflate is same as output to inflate:
local deflated = lz.deflate()(test_string, "finish")
local inflated = lz.inflate()(deflated, "finish")
ok(test_string == inflated, "'" .. tostring(test_string) .. "' == '" .. tostring(inflated) .. "'")
end
function test_large()
-- Try a larger string:
local numbers = ""
for i=1, 100 do numbers = numbers .. string.format("%3d", i) end
local numbers_table = {}
for i=1, 10000 do numbers_table[i] = numbers end
local test_string = table.concat(numbers_table, "\n")
local deflated = lz.deflate()(test_string, "finish")
local inflated = lz.inflate()(deflated, "finish")
ok(test_string == inflated, "large string")
end
function test_no_input()
local stream = lz.deflate()
local deflated = stream("")
deflated = deflated .. stream("")
deflated = deflated .. stream(nil, "finish")
ok("" == lz.inflate()(deflated, "finish"), "empty string")
end
function test_invalid_input()
local stream = lz.inflate()
local isok, err = pcall(
function()
stream("bad input")
end)
ok(not isok)
ok(string.find(err, "^InvalidInput"),
string.format("InvalidInput error (%s)", err))
end
function test_streaming()
local shrink = lz.deflate(lz.BEST_COMPRESSION)
local enlarge = lz.inflate()
local expected = {}
local got = {}
local chant = "Isn't He great, isn't He wonderful?\n"
for i=1,100 do
if ( i == 100 ) then
chant = nil
print "EOF round"
end
local shrink_part, shrink_eof = shrink(chant)
local enlarge_part, enlarge_eof = enlarge(shrink_part)
if ( i == 100 ) then
if not shrink_eof then error("expected eof after shrinking flush") end
if not enlarge_eof then error("expected eof after enlarging") end
else
if shrink_eof then error("unexpected eof after shrinking") end
if enlarge_eof then error("unexpected eof after enlarging") end
end
if enlarge_part then table.insert(got, enlarge_part) end
if chant then table.insert(expected, chant) end
end
ok(table.concat(got) == table.concat(expected), "streaming works")
end
function test_illegal_state()
local stream = lz.deflate()
stream("abc")
stream() -- eof/close
local _, emsg = pcall(
function()
stream("printing on 'closed' handle")
end)
ok(string.find(emsg, "^IllegalState"),
string.format("IllegalState error (%s)", emsg))
local enlarge = lz.inflate()
end
function test_checksum()
for _, factory in pairs{lz.crc32, lz.adler32} do
local csum = factory()("one two")
-- Multiple calls:
local compute = factory()
compute("one")
assert(csum == compute(" two"))
-- Multiple compute_checksums joined:
local compute1, compute2 = factory(), factory()
compute1("one")
compute2(" two")
assert(csum == compute1(compute2))
end
end
function test_version()
local major, minor, patch = lz.version()
ok(1 == major, "major version 1 == " .. major);
ok(type(minor) == "number", "minor version is number (" .. minor .. ")")
ok(type(patch) == "number", "patch version is number (" .. patch .. ")")
end
main()

4
3rdparty/lua-zlib/tom_macwright.gz vendored Normal file
View File

@ -0,0 +1,4 @@
xťŽ[
Â0EýÎ*fIgň(<28>čüüN“éL#mÄí[\‚—‡scÉy®Đę*=&ňNŚď<C59A>:'…I<E280A6>1Yi[ŘpŚŁz…U
ŽŤóäĽíR?0J§ťîzăQę<>­ńÖ%I…wťĘ
÷’áâcťÇ©Â)‡řůÍË<C38D>ĂülbÉgФÉ!·¤á<C2A4>ڍvşź¬ň§®®K˝ľ ”E¶F}šĘHŮ

BIN
3rdparty/lua-zlib/tom_macwright.out vendored Normal file

Binary file not shown.

2
3rdparty/lua-zlib/zlib.def vendored Normal file
View File

@ -0,0 +1,2 @@
EXPORTS
luaopen_zlib

33
3rdparty/luafilesystem/.travis.yml vendored Normal file
View File

@ -0,0 +1,33 @@
language: c
env:
global:
- LUAROCKS=2.2.0-rc1
matrix:
- LUA=lua5.1
- LUA=lua5.2
- LUA=lua5.3
- LUA=luajit
branches:
only:
- master
before_install:
- bash .travis/setup_lua.sh
- sudo pip install cpp-coveralls
install:
- sudo luarocks make rockspecs/luafilesystem-cvs-3.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
script:
- cd tests
- sudo lua test.lua
after_success:
- coveralls -b .. -r .. -E usr
notifications:
email:
on_success: change
on_failure: always

View File

@ -0,0 +1,15 @@
if [ -z "$PLATFORM" ]; then
PLATFORM=$TRAVIS_OS_NAME;
fi
if [ "$PLATFORM" == "osx" ]; then
PLATFORM="macosx";
fi
if [ -z "$PLATFORM" ]; then
if [ "$(uname)" == "Linux" ]; then
PLATFORM="linux";
else
PLATFORM="macosx";
fi;
fi

View File

@ -0,0 +1,101 @@
#! /bin/bash
# A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit".
# luajit2.0 - master v2.0
# luajit2.1 - master v2.1
LUAJIT_BASE="LuaJIT-2.0.3"
source .travis/platform.sh
LUAJIT="no"
if [ "$PLATFORM" == "macosx" ]; then
if [ "$LUA" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.0" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.1" ]; then
LUAJIT="yes";
fi;
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUAJIT" == "yes" ]; then
if [ "$LUA" == "luajit" ]; then
curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz;
else
git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE;
fi
cd $LUAJIT_BASE
if [ "$LUA" == "luajit2.1" ]; then
git checkout v2.1;
fi
make && sudo make install
if [ "$LUA" == "luajit2.1" ]; then
sudo ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
else
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
fi;
else
if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz
cd lua-5.2.3;
elif [ "$LUA" == "lua5.3" ]; then
curl http://www.lua.org/work/lua-5.3.0-beta.tar.gz | tar xz
cd lua-5.3.0-beta;
fi
sudo make $PLATFORM install;
fi
cd $TRAVIS_BUILD_DIR;
LUAROCKS_BASE=luarocks-$LUAROCKS
# curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
git clone https://github.com/keplerproject/luarocks.git $LUAROCKS_BASE
cd $LUAROCKS_BASE
git checkout v$LUAROCKS
if [ "$LUA" == "luajit" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.0" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.1" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.1;
else
./configure;
fi
make build && sudo make install
cd $TRAVIS_BUILD_DIR
rm -rf $LUAROCKS_BASE
if [ "$LUAJIT" == "yes" ]; then
rm -rf $LUAJIT_BASE;
elif [ "$LUA" == "lua5.1" ]; then
rm -rf lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
rm -rf lua-5.2.3;
elif [ "$LUA" == "lua5.3" ]; then
rm -rf lua-5.3.0-beta;
fi

21
3rdparty/luafilesystem/LICENSE vendored Normal file
View File

@ -0,0 +1,21 @@
Copyright © 2003-2014 Kepler Project.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
3rdparty/luafilesystem/Makefile vendored Normal file
View File

@ -0,0 +1,25 @@
# $Id: Makefile,v 1.36 2009/09/21 17:02:44 mascarenhas Exp $
T= lfs
CONFIG= ./config
include $(CONFIG)
SRCS= src/$T.c
OBJS= src/$T.o
lib: src/lfs.so
src/lfs.so: $(OBJS)
MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
test: lib
LUA_CPATH=./src/?.so lua tests/test.lua
install:
mkdir -p $(LUA_LIBDIR)
cp src/lfs.so $(LUA_LIBDIR)
clean:
rm -f src/lfs.so $(OBJS)

25
3rdparty/luafilesystem/Makefile.win vendored Normal file
View File

@ -0,0 +1,25 @@
# $Id: Makefile.win,v 1.11 2008/05/07 19:06:37 carregal Exp $
T= lfs
include config.win
SRCS= src\$T.c
OBJS= src\$T.obj
lib: src\lfs.dll
.c.obj:
$(CC) /c /Fo$@ $(CFLAGS) $<
src\lfs.dll: $(OBJS)
link /dll /def:src\$T.def /out:src\lfs.dll $(OBJS) "$(LUA_LIB)"
IF EXIST src\lfs.dll.manifest mt -manifest src\lfs.dll.manifest -outputresource:src\lfs.dll;2
install: src\lfs.dll
IF NOT EXIST "$(LUA_LIBDIR)" mkdir "$(LUA_LIBDIR)"
copy src\lfs.dll "$(LUA_LIBDIR)"
clean:
del src\lfs.dll $(OBJS) src\$T.lib src\$T.exp
IF EXIST src\lfs.dll.manifest del src\lfs.dll.manifest

23
3rdparty/luafilesystem/README vendored Normal file
View File

@ -0,0 +1,23 @@
LuaFileSystem - File System Library for Lua
Copyright 2003-2015 Kepler Project
http://keplerproject.github.io/luafilesystem
Description
-----------
LuaFileSystem is a Lua library developed to complement the set of functions
related to file systems offered by the standard Lua distribution.
LuaFileSystem offers a portable way to access the underlying directory structure and file attributes.
LuaFileSystem is free software and uses the same license as Lua 5.1
LuaRocks Installation
---------------------
```
luarocks install luafilesystem
```
Documentation
-------------
Please check the documentation at doc/us/ for more information.

24
3rdparty/luafilesystem/config vendored Normal file
View File

@ -0,0 +1,24 @@
# Installation directories
# Default installation prefix
PREFIX=/usr/local
# System's libraries directory (where binary libraries are installed)
LUA_LIBDIR= $(PREFIX)/lib/lua/5.1
# Lua includes directory
LUA_INC= $(PREFIX)/include
# OS dependent
LIB_OPTION= -shared #for Linux
#LIB_OPTION= -bundle -undefined dynamic_lookup #for MacOS X
LIBNAME= $T.so.$V
# Compilation directives
WARN= -O2 -Wall -fPIC -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -pedantic
INCS= -I$(LUA_INC)
CFLAGS= $(WARN) $(INCS)
CC= gcc
# $Id: config,v 1.21 2007/10/27 22:42:32 carregal Exp $

19
3rdparty/luafilesystem/config.win vendored Normal file
View File

@ -0,0 +1,19 @@
# Installation directories
# System's libraries directory (where binary libraries are installed)
LUA_LIBDIR= "c:\lua5.1"
# Lua includes directory
LUA_INC= "c:\lua5.1\include"
# Lua library
LUA_LIB= "c:\lua5.1\lua5.1.lib"
LIBNAME= $T.dll
# Compilation directives
WARN= /O2
INCS= /I$(LUA_INC)
CFLAGS= /MD $(WARN) $(INCS)
CC= cl
# $Id: config.win,v 1.7 2008/03/25 17:39:29 mascarenhas Exp $

212
3rdparty/luafilesystem/doc/us/doc.css vendored Normal file
View File

@ -0,0 +1,212 @@
body {
margin-left: 1em;
margin-right: 1em;
font-family: arial, helvetica, geneva, sans-serif;
background-color:#ffffff; margin:0px;
}
code {
font-family: "Andale Mono", monospace;
}
tt {
font-family: "Andale Mono", monospace;
}
body, td, th { font-size: 11pt; }
h1, h2, h3, h4 { margin-left: 0em; }
textarea, pre, tt { font-size:10pt; }
body, td, th { color:#000000; }
small { font-size:0.85em; }
h1 { font-size:1.5em; }
h2 { font-size:1.25em; }
h3 { font-size:1.15em; }
h4 { font-size:1.06em; }
a:link { font-weight:bold; color: #004080; text-decoration: none; }
a:visited { font-weight:bold; color: #006699; text-decoration: none; }
a:link:hover { text-decoration:underline; }
hr { color:#cccccc }
img { border-width: 0px; }
h3 { padding-top: 1em; }
p { margin-left: 1em; }
p.name {
font-family: "Andale Mono", monospace;
padding-top: 1em;
margin-left: 0em;
}
blockquote { margin-left: 3em; }
.example {
background-color: rgb(245, 245, 245);
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: silver;
border-right-color: silver;
border-bottom-color: silver;
border-left-color: silver;
padding: 1em;
margin-left: 1em;
margin-right: 1em;
font-family: "Andale Mono", monospace;
font-size: smaller;
}
hr {
margin-left: 0em;
background: #00007f;
border: 0px;
height: 1px;
}
ul { list-style-type: disc; }
table.index { border: 1px #00007f; }
table.index td { text-align: left; vertical-align: top; }
table.index ul { padding-top: 0em; margin-top: 0em; }
table {
border: 1px solid black;
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
}
th {
border: 1px solid black;
padding: 0.5em;
}
td {
border: 1px solid black;
padding: 0.5em;
}
div.header, div.footer { margin-left: 0em; }
#container {
margin-left: 1em;
margin-right: 1em;
background-color: #f0f0f0;
}
#product {
text-align: center;
border-bottom: 1px solid #cccccc;
background-color: #ffffff;
}
#product big {
font-size: 2em;
}
#product_logo {
}
#product_name {
}
#product_description {
}
#main {
background-color: #f0f0f0;
border-left: 2px solid #cccccc;
}
#navigation {
float: left;
width: 12em;
margin: 0;
vertical-align: top;
background-color: #f0f0f0;
overflow:visible;
}
#navigation h1 {
background-color:#e7e7e7;
font-size:1.1em;
color:#000000;
text-align:left;
margin:0px;
padding:0.2em;
border-top:1px solid #dddddd;
border-bottom:1px solid #dddddd;
}
#navigation ul {
font-size:1em;
list-style-type: none;
padding: 0;
margin: 1px;
}
#navigation li {
text-indent: -1em;
margin: 0em 0em 0em 0.5em;
display: block;
padding: 3px 0px 0px 12px;
}
#navigation li li a {
padding: 0px 3px 0px -1em;
}
#content {
margin-left: 12em;
padding: 1em;
border-left: 2px solid #cccccc;
border-right: 2px solid #cccccc;
background-color: #ffffff;
}
#about {
clear: both;
margin: 0;
padding: 5px;
border-top: 2px solid #cccccc;
background-color: #ffffff;
}
@media print {
body {
font: 10pt "Times New Roman", "TimeNR", Times, serif;
}
a {
font-weight:bold; color: #004080; text-decoration: underline;
}
#main {
background-color: #ffffff; border-left: 0px;
}
#container {
margin-left: 2%; margin-right: 2%; background-color: #ffffff;
}
#content {
margin-left: 0px; padding: 1em; border-left: 0px; border-right: 0px; background-color: #ffffff;
}
#navigation {
display: none;
}
#product_logo {
display: none;
}
#about img {
display: none;
}
.example {
font-family: "Andale Mono", monospace;
font-size: 8pt;
page-break-inside: avoid;
}
}

View File

@ -0,0 +1,103 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>LuaFileSystem</title>
<link rel="stylesheet" href="doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<a href="http://www.keplerproject.org">
<img alt="LuaFileSystem" src="luafilesystem.png"/>
</a>
</div>
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
<div id="product_description">File System Library for the Lua Programming Language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaFileSystem</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#building">Building</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#reference">Reference</a></li>
</ul>
</li>
<li><strong>Examples</strong></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
<ul>
<li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="example"></a>Examples</h2>
<h3>Directory iterator</h3>
<p>The following example iterates over a directory and recursively lists the
attributes for each file inside it.</p>
<pre class="example">
local lfs = require"lfs"
function attrdir (path)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
print ("\t "..f)
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
attrdir (f)
else
for name, value in pairs(attr) do
print (name, value)
end
end
end
end
end
attrdir (".")
</pre>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
<p><small>$Id: examples.html,v 1.8 2007/12/14 15:28:04 carregal Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

218
3rdparty/luafilesystem/doc/us/index.html vendored Normal file
View File

@ -0,0 +1,218 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>LuaFileSystem</title>
<link rel="stylesheet" href="doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<a href="http://www.keplerproject.org">
<img alt="LuaFileSystem" src="luafilesystem.png"/>
</a>
</div>
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
<div id="product_description">File System Library for the Lua Programming Language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaFileSystem</h1>
<ul>
<li><strong>Home</strong>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#building">Building</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#reference">Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
<ul>
<li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="overview"></a>Overview</h2>
<p>LuaFileSystem is a <a href="http://www.lua.org">Lua</a> library
developed to complement the set of functions related to file
systems offered by the standard Lua distribution.</p>
<p>LuaFileSystem offers a portable way to access
the underlying directory structure and file attributes.</p>
<p>LuaFileSystem is free software and uses the same
<a href="license.html">license</a> as Lua 5.1.</p>
<h2><a name="status"></a>Status</h2>
<p>Current version is 1.6.3. It works with Lua 5.1, 5.2 and 5.3.</p>
<h2><a name="download"></a>Download</h2>
<p>LuaFileSystem source can be downloaded from its
<a href="http://github.com/keplerproject/luafilesystem">Github</a>
page.</p>
<h2><a name="history"></a>History</h2>
<dl class="history">
<dt><strong>Version 1.6.3</strong> [15/Jan/2015]</dt>
<dd><ul>
<li>Lua 5.3 support.</li>
<li>Assorted bugfixes.</li>
</ul></dd>
<dt><strong>Version 1.6.2</strong> [??/Oct/2012]</dt>
<dd><ul>
<li>Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)</li>
</ul></dd>
<dt><strong>Version 1.6.1</strong> [01/Oct/2012]</dt>
<dd><ul>
<li>fix build for Lua 5.2</li>
</ul></dd>
<dt><strong>Version 1.6.0</strong> [26/Sep/2012]</dt>
<dd><ul>
<li>getcwd fix for Android</li>
<li>support for Lua 5.2</li>
<li>add lfs.link</li>
<li>other bug fixes</li>
</ul></dd>
<dt><strong>Version 1.5.0</strong> [20/Oct/2009]</dt>
<dd><ul>
<li>Added explicit next and close methods to second return value of lfs.dir
(the directory object), for explicit iteration or explicit closing.</li>
<li>Added directory locking via lfs.lock_dir function (see the <a href="manual.html">manual</a>).</li>
</ul></dd>
<dt><strong>Version 1.4.2</strong> [03/Feb/2009]</dt>
<dd>
<ul>
<li>fixed bug [<a href="http://luaforge.net/tracker/?func=detail&amp;group_id=66&amp;aid=13198&amp;atid=356">#13198</a>]
lfs.attributes(filename, 'size') overflow on files > 2 Gb again (bug report and patch by KUBO Takehiro).</li>
<li>fixed bug [<a href="http://luaforge.net/tracker/?group_id=66&amp;atid=356&amp;func=detail&amp;aid=39794">#39794</a>]
Compile error on Solaris 10 (bug report and patch by Aaron B).</li>
<li>fixed compilation problems with Borland C.</li>
</ul>
</dd>
<dt><strong>Version 1.4.1</strong> [07/May/2008]</dt>
<dd>
<ul>
<li>documentation review</li>
<li>fixed Windows compilation issues</li>
<li>fixed bug in the Windows tests (patch by Shmuel Zeigerman)</li>
<li>fixed bug [<a href="http://luaforge.net/tracker/?func=detail&amp;group_id=66&amp;aid=2185&amp;atid=356">#2185</a>]
<code>lfs.attributes(filename, 'size')</code> overflow on files > 2 Gb
</li>
</ul>
</dd>
<dt><strong>Version 1.4.0</strong> [13/Feb/2008]</dt>
<dd>
<ul>
<li>added function
<a href="manual.html#setmode"><code>lfs.setmode</code></a>
(works only in Windows systems).</li>
<li><a href="manual.html#attributes"><code>lfs.attributes</code></a>
raises an error if attribute does not exist</li>
</ul>
</dd>
<dt><strong>Version 1.3.0</strong> [26/Oct/2007]</dt>
<dd>
<ul>
<li>added function
<a href="manual.html#symlinkattributes"><code>lfs.symlinkattributes</code></a>
(works only in non Windows systems).</li>
</ul>
</dd>
<dt><strong>Version 1.2.1</strong> [08/May/2007]</dt>
<dd>
<ul>
<li>compatible only with Lua 5.1 (Lua 5.0 support was dropped)</li>
</ul>
</dd>
<dt><strong>Version 1.2</strong> [15/Mar/2006]</dt>
<dd>
<ul>
<li>added optional argument to
<a href="manual.html#attributes"><code>lfs.attributes</code></a></li>
<li>added function
<a href="manual.html#rmdir"><code>lfs.rmdir</code></a></li>
<li>bug correction on <a href="manual.html#dir"><code>lfs.dir</code></a></li>
</ul>
</dd>
<dt><strong>Version 1.1</strong> [30/May/2005]</dt>
<dd>
<ul>
<li>added function <a href="manual.html#touch"><code>lfs.touch</code></a>.</li>
</ul>
</dd>
<dt><strong>Version 1.0</strong> [21/Jan/2005]</dt>
<dd />
<dt><strong>Version 1.0 Beta</strong> [10/Nov/2004]</dt>
<dd />
</dl>
<h2><a name="credits"></a>Credits</h2>
<p>LuaFileSystem was designed by Roberto Ierusalimschy,
Andr&eacute; Carregal and Tom&aacute;s Guisasola as part of the
<a href="http://www.keplerproject.org">Kepler Project</a>,
which holds its copyright. LuaFileSystem is currently maintained by F&aacute;bio Mascarenhas.</p>
<h2><a name="contact"></a>Contact us</h2>
<p>For more information please
<a href="mailto:info-NO-SPAM-THANKS@keplerproject.org">contact us</a>.
Comments are welcome!</p>
<p>You can also reach other Kepler developers and users on the Kepler Project
<a href="http://luaforge.net/mail/?group_id=104">mailing list</a>.</p>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
<p><small>$Id: index.html,v 1.44 2009/02/04 21:21:33 carregal Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@ -0,0 +1,122 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>LuaFileSystem</title>
<link rel="stylesheet" href="doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<a href="http://www.keplerproject.org">
<img alt="LuaFileSystem" src="luafilesystem.png"/>
</a>
</div>
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
<div id="product_description">File System Library for the Lua Programming Language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaFileSystem</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#building">Building</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#reference">Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
<ul>
<li><a href="https://github.com/keplerproject/luafilesystem/issues/">Bug Tracker</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
</ul>
</li>
<li><strong>License</strong></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h1>License</h1>
<p>
LuaFileSystem is free software: it can be used for both academic
and commercial purposes at absolutely no cost. There are no
royalties or GNU-like "copyleft" restrictions. LuaFileSystem
qualifies as
<a href="http://www.opensource.org/docs/definition.html">Open Source</a>
software.
Its licenses are compatible with
<a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.
LuaFileSystem is not in the public domain and the
<a href="http://www.keplerproject.org">Kepler Project</a>
keep its copyright.
The legal details are below.
</p>
<p>The spirit of the license is that you are free to use
LuaFileSystem for any purpose at no cost without having to ask us.
The only requirement is that if you do use LuaFileSystem, then you
should give us credit by including the appropriate copyright notice
somewhere in your product or its documentation.</p>
<p>The LuaFileSystem library is designed and implemented by Roberto
Ierusalimschy, Andr&eacute; Carregal and Tom&aacute;s Guisasola.
The implementation is not derived from licensed software.</p>
<hr/>
<p>Copyright &copy; 2003 Kepler Project.</p>
<p>Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</p>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
<p><small>$Id: license.html,v 1.13 2008/02/11 22:42:21 carregal Exp $</small></p>
</div><!-- id="about" -->
</div><!-- id="container" -->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -0,0 +1,280 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>LuaFileSystem</title>
<link rel="stylesheet" href="doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo">
<a href="http://www.keplerproject.org"><img alt="LuaFileSystem" src="luafilesystem.png"/></a>
</div>
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
<div id="product_description">File System Library for the Lua Programming Language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaFileSystem</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><strong>Manual</strong>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#building">Building</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#reference">Reference</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
<ul>
<li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="introduction"></a>Introduction</h2>
<p>LuaFileSystem is a <a href="http://www.lua.org">Lua</a> library
developed to complement the set of functions related to file
systems offered by the standard Lua distribution.</p>
<p>LuaFileSystem offers a portable way to access
the underlying directory structure and file attributes.</p>
<h2><a name="building"></a>Building</h2>
<p>
LuaFileSystem should be built with Lua 5.1 so the language library
and header files for the target version must be installed properly.
</p>
<p>
LuaFileSystem offers a Makefile and a separate configuration file,
<code>config</code>,
which should be edited to suit your installation before running
<code>make</code>.
The file has some definitions like paths to the external libraries,
compiler options and the like.
</p>
<p>On Windows, the C runtime used to compile LuaFileSystem must be the same
runtime that Lua uses, or some LuaFileSystem functions will not work.</p>
<h2><a name="installation"></a>Installation</h2>
<p>The easiest way to install LuaFileSystem is to use LuaRocks:</p>
<pre class="example">
luarocks install luafilesystem
</pre>
<p>If you prefer to install LuaFileSystem manually, the compiled binary should be copied to a directory in your
<a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.cpath">C path</a>.</p>
<h2><a name="reference"></a>Reference</h2>
<p>
LuaFileSystem offers the following functions:
</p>
<dl class="reference">
<dt><a name="attributes"></a><strong><code>lfs.attributes (filepath [, aname])</code></strong></dt>
<dd>Returns a table with the file attributes corresponding to
<code>filepath</code> (or <code>nil</code> followed by an error message
in case of error).
If the second optional argument is given, then only the value of the
named attribute is returned (this use is equivalent to
<code>lfs.attributes(filepath).aname</code>, but the table is not created
and only one attribute is retrieved from the O.S.).
The attributes are described as follows;
attribute <code>mode</code> is a string, all the others are numbers,
and the time related attributes use the same time reference of
<a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.time"><code>os.time</code></a>:
<dl>
<dt><strong><code>dev</code></strong></dt>
<dd>on Unix systems, this represents the device that the inode resides on. On Windows systems,
represents the drive number of the disk containing the file</dd>
<dt><strong><code>ino</code></strong></dt>
<dd>on Unix systems, this represents the inode number. On Windows systems this has no meaning</dd>
<dt><strong><code>mode</code></strong></dt>
<dd>string representing the associated protection mode (the values could be
<code>file</code>, <code>directory</code>, <code>link</code>, <code>socket</code>,
<code>named pipe</code>, <code>char device</code>, <code>block device</code> or
<code>other</code>)</dd>
<dt><strong><code>nlink</code></strong></dt>
<dd>number of hard links to the file</dd>
<dt><strong><code>uid</code></strong></dt>
<dd>user-id of owner (Unix only, always 0 on Windows)</dd>
<dt><strong><code>gid</code></strong></dt>
<dd>group-id of owner (Unix only, always 0 on Windows)</dd>
<dt><strong><code>rdev</code></strong></dt>
<dd>on Unix systems, represents the device type, for special file inodes.
On Windows systems represents the same as <code>dev</code></dd>
<dt><strong><code>access</code></strong></dt>
<dd>time of last access</dd>
<dt><strong><code>modification</code></strong></dt>
<dd>time of last data modification</dd>
<dt><strong><code>change</code></strong></dt>
<dd>time of last file status change</dd>
<dt><strong><code>size</code></strong></dt>
<dd>file size, in bytes</dd>
<dt><strong><code>blocks</code></strong></dt>
<dd>block allocated for file; (Unix only)</dd>
<dt><strong><code>blksize</code></strong></dt>
<dd>optimal file system I/O blocksize; (Unix only)</dd>
</dl>
This function uses <code>stat</code> internally thus if the given
<code>filepath</code> is a symbolic link, it is followed (if it points to
another link the chain is followed recursively) and the information
is about the file it refers to.
To obtain information about the link itself, see function
<a href="#symlinkattributes">lfs.symlinkattributes</a>.
</dd>
<dt><a name="chdir"></a><strong><code>lfs.chdir (path)</code></strong></dt>
<dd>Changes the current working directory to the given
<code>path</code>.<br />
Returns <code>true</code> in case of success or <code>nil</code> plus an
error string.</dd>
<dt><a name="chdir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt>
<dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not
exist and returns the lock. If the lock already exists checks if
it's stale, using the second parameter (default for the second
parameter is <code>INT_MAX</code>, which in practice means the lock will never
be stale. To free the the lock call <code>lock:free()</code>. <br/>
In case of any errors it returns nil and the error message. In
particular, if the lock exists and is not stale it returns the
"File exists" message.</dd>
<dt><a name="getcwd"></a><strong><code>lfs.currentdir ()</code></strong></dt>
<dd>Returns a string with the current working directory or <code>nil</code>
plus an error string.</dd>
<dt><a name="dir"></a><strong><code>iter, dir_obj = lfs.dir (path)</code></strong></dt>
<dd>
Lua iterator over the entries of a given directory.
Each time the iterator is called with <code>dir_obj</code> it returns a directory entry's name as a string, or
<code>nil</code> if there are no more entries. You can also iterate by calling <code>dir_obj:next()</code>, and
explicitly close the directory before the iteration finished with <code>dir_obj:close()</code>.
Raises an error if <code>path</code> is not a directory.
</dd>
<dt><a name="lock"></a><strong><code>lfs.lock (filehandle, mode[, start[, length]])</code></strong></dt>
<dd>Locks a file or a part of it. This function works on <em>open files</em>; the
file handle should be specified as the first argument.
The string <code>mode</code> could be either
<code>r</code> (for a read/shared lock) or <code>w</code> (for a
write/exclusive lock). The optional arguments <code>start</code>
and <code>length</code> can be used to specify a starting point and
its length; both should be numbers.<br />
Returns <code>true</code> if the operation was successful; in
case of error, it returns <code>nil</code> plus an error string.
</dd>
<dt><a name="link"></a><strong><code>lfs.link (old, new[, symlink])</code></strong></dt>
<dd>Creates a link. The first argument is the object to link to
and the second is the name of the link. If the optional third
argument is true, the link will by a symbolic link (by default, a
hard link is created).
</dd>
<dt><a name="mkdir"></a><strong><code>lfs.mkdir (dirname)</code></strong></dt>
<dd>Creates a new directory. The argument is the name of the new
directory.<br />
Returns <code>true</code> if the operation was successful;
in case of error, it returns <code>nil</code> plus an error string.
</dd>
<dt><a name="rmdir"></a><strong><code>lfs.rmdir (dirname)</code></strong></dt>
<dd>Removes an existing directory. The argument is the name of the directory.<br />
Returns <code>true</code> if the operation was successful;
in case of error, it returns <code>nil</code> plus an error string.</dd>
<dt><a name="setmode"></a><strong><code>lfs.setmode (file, mode)</code></strong></dt>
<dd>Sets the writing mode for a file. The mode string can be either <code>"binary"</code> or <code>"text"</code>.
Returns <code>true</code> followed the previous mode string for the file, or
<code>nil</code> followed by an error string in case of errors.
On non-Windows platforms, where the two modes are identical,
setting the mode has no effect, and the mode is always returned as <code>binary</code>.
</dd>
<dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, aname])</code></strong></dt>
<dd>Identical to <a href="#attributes">lfs.attributes</a> except that
it obtains information about the link itself (not the file it refers to).
On Windows this function does not yet support links, and is identical to
<code>lfs.attributes</code>.
</dd>
<dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt>
<dd>Set access and modification times of a file. This function is
a bind to <code>utime</code> function. The first argument is the
filename, the second argument (<code>atime</code>) is the access time,
and the third argument (<code>mtime</code>) is the modification time.
Both times are provided in seconds (which should be generated with
Lua standard function <code>os.time</code>).
If the modification time is omitted, the access time provided is used;
if both times are omitted, the current time is used.<br />
Returns <code>true</code> if the operation was successful;
in case of error, it returns <code>nil</code> plus an error string.
</dd>
<dt><a name="unlock"></a><strong><code>lfs.unlock (filehandle[, start[, length]])</code></strong></dt>
<dd>Unlocks a file or a part of it. This function works on
<em>open files</em>; the file handle should be specified as the first
argument. The optional arguments <code>start</code> and
<code>length</code> can be used to specify a starting point and its
length; both should be numbers.<br />
Returns <code>true</code> if the operation was successful;
in case of error, it returns <code>nil</code> plus an error string.
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
<p><small>$Id: manual.html,v 1.45 2009/06/03 20:53:55 mascarenhas Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.3.0-1"
source = {
url = "http://luaforge.net/frs/download.php/2679/luafilesystem-1.3.0.tar.gz"
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "make",
build_variables = {
LUA_INC = "$(LUA_INCDIR)",
LIB_OPTION = "$(LIBFLAG)"
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.4.0-1"
source = {
url = "http://luaforge.net/frs/download.php/3158/luafilesystem-1.4.0.tar.gz"
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "make",
build_variables = {
LUA_INC = "$(LUA_INCDIR)",
LIB_OPTION = "$(LIBFLAG)"
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
}

View File

@ -0,0 +1,43 @@
package = "LuaFileSystem"
version = "1.4.0-2"
source = {
url = "http://luaforge.net/frs/download.php/3158/luafilesystem-1.4.0.tar.gz"
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
platforms = {
unix = {
type = "make",
build_variables = {
LIB_OPTION = "$(LIBFLAG)",
CFLAGS = "$(CFLAGS) -I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
},
win32 = {
type = "make",
build_variables = {
LUA_LIB = "$(LUA_LIBDIR)\\lua5.1.lib",
CFLAGS = "/MD $(CFLAGS) /I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)",
LUA_DIR = "$(LUADIR)",
BIN_DIR = "$(BINDIR)"
}
}
}
}

View File

@ -0,0 +1,43 @@
package = "LuaFileSystem"
version = "1.4.1-1"
source = {
url = "http://luaforge.net/frs/download.php/3345/luafilesystem-1.4.1.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
platforms = {
unix = {
type = "make",
build_variables = {
LIB_OPTION = "$(LIBFLAG)",
CFLAGS = "$(CFLAGS) -I$(LUA_INCDIR) $(STAT64)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
},
win32 = {
type = "make",
build_variables = {
LUA_LIB = "$(LUA_LIBDIR)\\lua5.1.lib",
CFLAGS = "/MD $(CFLAGS) /I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)",
LUA_DIR = "$(LUADIR)",
BIN_DIR = "$(BINDIR)"
}
}
}
}

View File

@ -0,0 +1,43 @@
package = "LuaFileSystem"
version = "1.4.1rc1-1"
source = {
url = "http://luafilesystem.luaforge.net/luafilesystem-1.4.1rc1.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
platforms = {
unix = {
type = "make",
build_variables = {
LIB_OPTION = "$(LIBFLAG)",
CFLAGS = "$(CFLAGS) -I$(LUA_INCDIR) $(STAT64)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
},
win32 = {
type = "make",
build_variables = {
LUA_LIB = "$(LUA_LIBDIR)\\lua5.1.lib",
CFLAGS = "/MD $(CFLAGS) /I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)",
LUA_DIR = "$(LUADIR)",
BIN_DIR = "$(BINDIR)"
}
}
}
}

View File

@ -0,0 +1,26 @@
package = "LuaFileSystem"
version = "1.4.2-1"
source = {
url = "http://luaforge.net/frs/download.php/3931/luafilesystem-1.4.2.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "module",
modules = { lfs = "src/lfs.c" }
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.5.0-1"
source = {
url = "http://cloud.github.com/downloads/keplerproject/luafilesystem/luafilesystem-1.5.0.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "module",
modules = { lfs = "src/lfs.c" },
copy_directories = { "doc", "tests" }
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.6.0-1"
source = {
url = "https://github.com/downloads/keplerproject/luafilesystem/luafilesystem-1.6.0.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "builtin",
modules = { lfs = "src/lfs.c" },
copy_directories = { "doc", "tests" }
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.6.1-1"
source = {
url = "https://github.com/downloads/keplerproject/luafilesystem/luafilesystem-1.6.1.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "builtin",
modules = { lfs = "src/lfs.c" },
copy_directories = { "doc", "tests" }
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "1.6.2-1"
source = {
url = "https://github.com/downloads/keplerproject/luafilesystem/luafilesystem-1.6.2.tar.gz",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "builtin",
modules = { lfs = "src/lfs.c" },
copy_directories = { "doc", "tests" }
}

View File

@ -0,0 +1,28 @@
package = "LuaFileSystem"
version = "1.6.3-1"
source = {
url = "git://github.com/keplerproject/luafilesystem",
tag = "v_1_6_3",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]],
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "builtin",
modules = {
lfs = "src/lfs.c"
},
copy_directories = {
"doc", "tests"
}
}

View File

@ -0,0 +1,44 @@
package = "LuaFileSystem"
version = "cvs-1"
source = {
url = "cvs://:pserver:anonymous:@cvs.luaforge.net:/cvsroot/luafilesystem",
cvs_tag = "HEAD"
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
platforms = {
unix = {
type = "make",
build_variables = {
LIB_OPTION = "$(LIBFLAG)",
CFLAGS = "$(CFLAGS) -I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)"
}
},
win32 = {
type = "make",
build_variables = {
LUA_LIB = "$(LUA_LIBDIR)\\lua5.1.lib",
CFLAGS = "$(CFLAGS) /I$(LUA_INCDIR)",
},
install_variables = {
LUA_LIBDIR = "$(LIBDIR)",
LUA_DIR = "$(LUADIR)",
BIN_DIR = "$(BINDIR)"
}
}
}
}

View File

@ -0,0 +1,26 @@
package = "LuaFileSystem"
version = "cvs-2"
source = {
url = "git://github.com/keplerproject/luafilesystem.git",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1"
}
build = {
type = "module",
modules = { lfs = "src/lfs.c" }
}

View File

@ -0,0 +1,27 @@
package = "LuaFileSystem"
version = "cvs-3"
source = {
url = "git://github.com/keplerproject/luafilesystem.git",
}
description = {
summary = "File System Library for the Lua Programming Language",
detailed = [[
LuaFileSystem is a Lua library developed to complement the set of
functions related to file systems offered by the standard Lua
distribution. LuaFileSystem offers a portable way to access the
underlying directory structure and file attributes.
]]
}
dependencies = {
"lua >= 5.1, < 5.4"
}
build = {
type = "builtin",
modules = { lfs = "src/lfs.c" },
copy_directories = { "doc", "tests" }
}

2
3rdparty/luafilesystem/src/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
*.so

906
3rdparty/luafilesystem/src/lfs.c vendored Normal file
View File

@ -0,0 +1,906 @@
/*
** LuaFileSystem
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
**
** File system manipulation library.
** This library offers these functions:
** lfs.attributes (filepath [, attributename])
** lfs.chdir (path)
** lfs.currentdir ()
** lfs.dir (path)
** lfs.lock (fh, mode)
** lfs.lock_dir (path)
** lfs.mkdir (path)
** lfs.rmdir (path)
** lfs.setmode (filepath, mode)
** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts
** lfs.touch (filepath [, atime [, mtime]])
** lfs.unlock (fh)
**
** $Id: lfs.c,v 1.61 2009/07/04 02:10:16 mascarenhas Exp $
*/
#ifndef LFS_DO_NOT_USE_LARGE_FILE
#ifndef _WIN32
#ifndef _AIX
#define _FILE_OFFSET_BITS 64 /* Linux, Solaris and HP-UX */
#else
#define _LARGE_FILES 1 /* AIX */
#endif
#endif
#endif
#ifndef LFS_DO_NOT_USE_LARGE_FILE
#define _LARGEFILE64_SOURCE
#endif
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#include <io.h>
#include <sys/locking.h>
#ifdef __BORLANDC__
#include <utime.h>
#else
#include <sys/utime.h>
#endif
#include <fcntl.h>
#else
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#endif
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "lfs.h"
#define LFS_VERSION "1.6.3"
#define LFS_LIBNAME "lfs"
#if LUA_VERSION_NUM >= 503 /* Lua 5.3 */
#ifndef luaL_optlong
#define luaL_optlong luaL_optinteger
#endif
#endif
#if LUA_VERSION_NUM < 502
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
#endif
/* Define 'strerror' for systems that do not implement it */
#ifdef NO_STRERROR
#define strerror(_) "System unable to describe the error"
#endif
/* Define 'getcwd' for systems that do not implement it */
#ifdef NO_GETCWD
#define getcwd(p,s) NULL
#define getcwd_error "Function 'getcwd' not provided by system"
#else
#define getcwd_error strerror(errno)
#ifdef _WIN32
/* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */
#define LFS_MAXPATHLEN MAX_PATH
#else
/* For MAXPATHLEN: */
#include <sys/param.h>
#define LFS_MAXPATHLEN MAXPATHLEN
#endif
#endif
#define DIR_METATABLE "directory metatable"
typedef struct dir_data {
int closed;
#ifdef _WIN32
intptr_t hFile;
char pattern[MAX_PATH+1];
#else
DIR *dir;
#endif
} dir_data;
#define LOCK_METATABLE "lock metatable"
#ifdef _WIN32
#ifdef __BORLANDC__
#define lfs_setmode(L,file,m) ((void)L, setmode(_fileno(file), m))
#define STAT_STRUCT struct stati64
#else
#define lfs_setmode(L,file,m) ((void)L, _setmode(_fileno(file), m))
#define STAT_STRUCT struct _stati64
#endif
#define STAT_FUNC _stati64
#define LSTAT_FUNC STAT_FUNC
#else
#define _O_TEXT 0
#define _O_BINARY 0
#define lfs_setmode(L,file,m) ((void)L, (void)file, (void)m, 0)
#define STAT_STRUCT struct stat
#define STAT_FUNC stat
#define LSTAT_FUNC lstat
#endif
/*
** Utility functions
*/
static int pusherror(lua_State *L, const char *info)
{
lua_pushnil(L);
if (info==NULL)
lua_pushstring(L, strerror(errno));
else
lua_pushfstring(L, "%s: %s", info, strerror(errno));
lua_pushinteger(L, errno);
return 3;
}
#ifndef _WIN32
static int pushresult(lua_State *L, int i, const char *info)
{
if (i==-1)
return pusherror(L, info);
lua_pushinteger(L, i);
return 1;
}
#endif
/*
** This function changes the working (current) directory
*/
static int change_dir (lua_State *L) {
const char *path = luaL_checkstring(L, 1);
if (chdir(path)) {
lua_pushnil (L);
lua_pushfstring (L,"Unable to change working directory to '%s'\n%s\n",
path, chdir_error);
return 2;
} else {
lua_pushboolean (L, 1);
return 1;
}
}
/*
** This function returns the current directory
** If unable to get the current directory, it returns nil
** and a string describing the error
*/
static int get_dir (lua_State *L) {
char *path;
/* Passing (NULL, 0) is not guaranteed to work. Use a temp buffer and size instead. */
char buf[LFS_MAXPATHLEN];
if ((path = getcwd(buf, LFS_MAXPATHLEN)) == NULL) {
lua_pushnil(L);
lua_pushstring(L, getcwd_error);
return 2;
}
else {
lua_pushstring(L, path);
return 1;
}
}
/*
** Check if the given element on the stack is a file and returns it.
*/
static FILE *check_file (lua_State *L, int idx, const char *funcname) {
#if LUA_VERSION_NUM == 501
FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*");
if (*fh == NULL) {
luaL_error (L, "%s: closed file", funcname);
return 0;
} else
return *fh;
#elif LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM <= 503
luaL_Stream *fh = (luaL_Stream *)luaL_checkudata (L, idx, "FILE*");
if (fh->closef == 0 || fh->f == NULL) {
luaL_error (L, "%s: closed file", funcname);
return 0;
} else
return fh->f;
#else
#error unsupported Lua version
#endif
}
/*
**
*/
static int _file_lock (lua_State *L, FILE *fh, const char *mode, const long start, long len, const char *funcname) {
int code;
#ifdef _WIN32
/* lkmode valid values are:
LK_LOCK Locks the specified bytes. If the bytes cannot be locked, the program immediately tries again after 1 second. If, after 10 attempts, the bytes cannot be locked, the constant returns an error.
LK_NBLCK Locks the specified bytes. If the bytes cannot be locked, the constant returns an error.
LK_NBRLCK Same as _LK_NBLCK.
LK_RLCK Same as _LK_LOCK.
LK_UNLCK Unlocks the specified bytes, which must have been previously locked.
Regions should be locked only briefly and should be unlocked before closing a file or exiting the program.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__locking.asp
*/
int lkmode;
switch (*mode) {
case 'r': lkmode = LK_NBLCK; break;
case 'w': lkmode = LK_NBLCK; break;
case 'u': lkmode = LK_UNLCK; break;
default : return luaL_error (L, "%s: invalid mode", funcname);
}
if (!len) {
fseek (fh, 0L, SEEK_END);
len = ftell (fh);
}
fseek (fh, start, SEEK_SET);
#ifdef __BORLANDC__
code = locking (fileno(fh), lkmode, len);
#else
code = _locking (fileno(fh), lkmode, len);
#endif
#else
struct flock f;
switch (*mode) {
case 'w': f.l_type = F_WRLCK; break;
case 'r': f.l_type = F_RDLCK; break;
case 'u': f.l_type = F_UNLCK; break;
default : return luaL_error (L, "%s: invalid mode", funcname);
}
f.l_whence = SEEK_SET;
f.l_start = (off_t)start;
f.l_len = (off_t)len;
code = fcntl (fileno(fh), F_SETLK, &f);
#endif
return (code != -1);
}
#ifdef _WIN32
typedef struct lfs_Lock {
HANDLE fd;
} lfs_Lock;
static int lfs_lock_dir(lua_State *L) {
size_t pathl; HANDLE fd;
lfs_Lock *lock;
char *ln;
const char *lockfile = "/lockfile.lfs";
const char *path = luaL_checklstring(L, 1, &pathl);
ln = (char*)malloc(pathl + strlen(lockfile) + 1);
if(!ln) {
lua_pushnil(L); lua_pushstring(L, strerror(errno)); return 2;
}
strcpy(ln, path); strcat(ln, lockfile);
if((fd = CreateFile(ln, GENERIC_WRITE, 0, NULL, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL)) == INVALID_HANDLE_VALUE) {
int en = GetLastError();
free(ln); lua_pushnil(L);
if(en == ERROR_FILE_EXISTS || en == ERROR_SHARING_VIOLATION)
lua_pushstring(L, "File exists");
else
lua_pushstring(L, strerror(en));
return 2;
}
free(ln);
lock = (lfs_Lock*)lua_newuserdata(L, sizeof(lfs_Lock));
lock->fd = fd;
luaL_getmetatable (L, LOCK_METATABLE);
lua_setmetatable (L, -2);
return 1;
}
static int lfs_unlock_dir(lua_State *L) {
lfs_Lock *lock = (lfs_Lock *)luaL_checkudata(L, 1, LOCK_METATABLE);
if(lock->fd != INVALID_HANDLE_VALUE) {
CloseHandle(lock->fd);
lock->fd=INVALID_HANDLE_VALUE;
}
return 0;
}
#else
typedef struct lfs_Lock {
char *ln;
} lfs_Lock;
static int lfs_lock_dir(lua_State *L) {
lfs_Lock *lock;
size_t pathl;
char *ln;
const char *lockfile = "/lockfile.lfs";
const char *path = luaL_checklstring(L, 1, &pathl);
lock = (lfs_Lock*)lua_newuserdata(L, sizeof(lfs_Lock));
ln = (char*)malloc(pathl + strlen(lockfile) + 1);
if(!ln) {
lua_pushnil(L); lua_pushstring(L, strerror(errno)); return 2;
}
strcpy(ln, path); strcat(ln, lockfile);
if(symlink("lock", ln) == -1) {
free(ln); lua_pushnil(L);
lua_pushstring(L, strerror(errno)); return 2;
}
lock->ln = ln;
luaL_getmetatable (L, LOCK_METATABLE);
lua_setmetatable (L, -2);
return 1;
}
static int lfs_unlock_dir(lua_State *L) {
lfs_Lock *lock = (lfs_Lock *)luaL_checkudata(L, 1, LOCK_METATABLE);
if(lock->ln) {
unlink(lock->ln);
free(lock->ln);
lock->ln = NULL;
}
return 0;
}
#endif
static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
static const int mode[] = {_O_BINARY, _O_TEXT};
static const char *const modenames[] = {"binary", "text", NULL};
int op = luaL_checkoption(L, arg, NULL, modenames);
int res = lfs_setmode(L, f, mode[op]);
if (res != -1) {
int i;
lua_pushboolean(L, 1);
for (i = 0; modenames[i] != NULL; i++) {
if (mode[i] == res) {
lua_pushstring(L, modenames[i]);
goto exit;
}
}
lua_pushnil(L);
exit:
return 2;
} else {
int en = errno;
lua_pushnil(L);
lua_pushfstring(L, "%s", strerror(en));
lua_pushinteger(L, en);
return 3;
}
}
static int lfs_f_setmode(lua_State *L) {
return lfs_g_setmode(L, check_file(L, 1, "setmode"), 2);
}
/*
** Locks a file.
** @param #1 File handle.
** @param #2 String with lock mode ('w'rite, 'r'ead).
** @param #3 Number with start position (optional).
** @param #4 Number with length (optional).
*/
static int file_lock (lua_State *L) {
FILE *fh = check_file (L, 1, "lock");
const char *mode = luaL_checkstring (L, 2);
const long start = (long) luaL_optinteger (L, 3, 0);
long len = (long) luaL_optinteger (L, 4, 0);
if (_file_lock (L, fh, mode, start, len, "lock")) {
lua_pushboolean (L, 1);
return 1;
} else {
lua_pushnil (L);
lua_pushfstring (L, "%s", strerror(errno));
return 2;
}
}
/*
** Unlocks a file.
** @param #1 File handle.
** @param #2 Number with start position (optional).
** @param #3 Number with length (optional).
*/
static int file_unlock (lua_State *L) {
FILE *fh = check_file (L, 1, "unlock");
const long start = (long) luaL_optinteger (L, 2, 0);
long len = (long) luaL_optinteger (L, 3, 0);
if (_file_lock (L, fh, "u", start, len, "unlock")) {
lua_pushboolean (L, 1);
return 1;
} else {
lua_pushnil (L);
lua_pushfstring (L, "%s", strerror(errno));
return 2;
}
}
/*
** Creates a link.
** @param #1 Object to link to.
** @param #2 Name of link.
** @param #3 True if link is symbolic (optional).
*/
static int make_link(lua_State *L)
{
#ifndef _WIN32
const char *oldpath = luaL_checkstring(L, 1);
const char *newpath = luaL_checkstring(L, 2);
return pushresult(L,
(lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL);
#else
return pusherror(L, "make_link is not supported on Windows");
#endif
}
/*
** Creates a directory.
** @param #1 Directory path.
*/
static int make_dir (lua_State *L) {
const char *path = luaL_checkstring (L, 1);
int fail;
#ifdef _WIN32
fail = _mkdir (path);
#else
fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
#endif
if (fail) {
lua_pushnil (L);
lua_pushfstring (L, "%s", strerror(errno));
return 2;
}
lua_pushboolean (L, 1);
return 1;
}
/*
** Removes a directory.
** @param #1 Directory path.
*/
static int remove_dir (lua_State *L) {
const char *path = luaL_checkstring (L, 1);
int fail;
fail = rmdir (path);
if (fail) {
lua_pushnil (L);
lua_pushfstring (L, "%s", strerror(errno));
return 2;
}
lua_pushboolean (L, 1);
return 1;
}
/*
** Directory iterator
*/
static int dir_iter (lua_State *L) {
#ifdef _WIN32
struct _finddata_t c_file;
#else
struct dirent *entry;
#endif
dir_data *d = (dir_data *)luaL_checkudata (L, 1, DIR_METATABLE);
luaL_argcheck (L, d->closed == 0, 1, "closed directory");
#ifdef _WIN32
if (d->hFile == 0L) { /* first entry */
if ((d->hFile = _findfirst (d->pattern, &c_file)) == -1L) {
lua_pushnil (L);
lua_pushstring (L, strerror (errno));
d->closed = 1;
return 2;
} else {
lua_pushstring (L, c_file.name);
return 1;
}
} else { /* next entry */
if (_findnext (d->hFile, &c_file) == -1L) {
/* no more entries => close directory */
_findclose (d->hFile);
d->closed = 1;
return 0;
} else {
lua_pushstring (L, c_file.name);
return 1;
}
}
#else
if ((entry = readdir (d->dir)) != NULL) {
lua_pushstring (L, entry->d_name);
return 1;
} else {
/* no more entries => close directory */
closedir (d->dir);
d->closed = 1;
return 0;
}
#endif
}
/*
** Closes directory iterators
*/
static int dir_close (lua_State *L) {
dir_data *d = (dir_data *)lua_touserdata (L, 1);
#ifdef _WIN32
if (!d->closed && d->hFile) {
_findclose (d->hFile);
}
#else
if (!d->closed && d->dir) {
closedir (d->dir);
}
#endif
d->closed = 1;
return 0;
}
/*
** Factory of directory iterators
*/
static int dir_iter_factory (lua_State *L) {
const char *path = luaL_checkstring (L, 1);
dir_data *d;
lua_pushcfunction (L, dir_iter);
d = (dir_data *) lua_newuserdata (L, sizeof(dir_data));
luaL_getmetatable (L, DIR_METATABLE);
lua_setmetatable (L, -2);
d->closed = 0;
#ifdef _WIN32
d->hFile = 0L;
if (strlen(path) > MAX_PATH-2)
luaL_error (L, "path too long: %s", path);
else
sprintf (d->pattern, "%s/*", path);
#else
d->dir = opendir (path);
if (d->dir == NULL)
luaL_error (L, "cannot open %s: %s", path, strerror (errno));
#endif
return 2;
}
/*
** Creates directory metatable.
*/
static int dir_create_meta (lua_State *L) {
luaL_newmetatable (L, DIR_METATABLE);
/* Method table */
lua_newtable(L);
lua_pushcfunction (L, dir_iter);
lua_setfield(L, -2, "next");
lua_pushcfunction (L, dir_close);
lua_setfield(L, -2, "close");
/* Metamethods */
lua_setfield(L, -2, "__index");
lua_pushcfunction (L, dir_close);
lua_setfield (L, -2, "__gc");
return 1;
}
/*
** Creates lock metatable.
*/
static int lock_create_meta (lua_State *L) {
luaL_newmetatable (L, LOCK_METATABLE);
/* Method table */
lua_newtable(L);
lua_pushcfunction(L, lfs_unlock_dir);
lua_setfield(L, -2, "free");
/* Metamethods */
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, lfs_unlock_dir);
lua_setfield(L, -2, "__gc");
return 1;
}
#ifdef _WIN32
#ifndef S_ISDIR
#define S_ISDIR(mode) (mode&_S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (mode&_S_IFREG)
#endif
#ifndef S_ISLNK
#define S_ISLNK(mode) (0)
#endif
#ifndef S_ISSOCK
#define S_ISSOCK(mode) (0)
#endif
#ifndef S_ISFIFO
#define S_ISFIFO(mode) (0)
#endif
#ifndef S_ISCHR
#define S_ISCHR(mode) (mode&_S_IFCHR)
#endif
#ifndef S_ISBLK
#define S_ISBLK(mode) (0)
#endif
#endif
/*
** Convert the inode protection mode to a string.
*/
#ifdef _WIN32
static const char *mode2string (unsigned short mode) {
#else
static const char *mode2string (mode_t mode) {
#endif
if ( S_ISREG(mode) )
return "file";
else if ( S_ISDIR(mode) )
return "directory";
else if ( S_ISLNK(mode) )
return "link";
else if ( S_ISSOCK(mode) )
return "socket";
else if ( S_ISFIFO(mode) )
return "named pipe";
else if ( S_ISCHR(mode) )
return "char device";
else if ( S_ISBLK(mode) )
return "block device";
else
return "other";
}
/*
** Set access time and modification values for file
*/
static int file_utime (lua_State *L) {
const char *file = luaL_checkstring (L, 1);
struct utimbuf utb, *buf;
if (lua_gettop (L) == 1) /* set to current date/time */
buf = NULL;
else {
utb.actime = luaL_optnumber (L, 2, 0);
utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime);
buf = &utb;
}
if (utime (file, buf)) {
lua_pushnil (L);
lua_pushfstring (L, "%s", strerror (errno));
return 2;
}
lua_pushboolean (L, 1);
return 1;
}
/* inode protection mode */
static void push_st_mode (lua_State *L, STAT_STRUCT *info) {
lua_pushstring (L, mode2string (info->st_mode));
}
/* device inode resides on */
static void push_st_dev (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_dev);
}
/* inode's number */
static void push_st_ino (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_ino);
}
/* number of hard links to the file */
static void push_st_nlink (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_nlink);
}
/* user-id of owner */
static void push_st_uid (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_uid);
}
/* group-id of owner */
static void push_st_gid (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_gid);
}
/* device type, for special file inode */
static void push_st_rdev (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_rdev);
}
/* time of last access */
static void push_st_atime (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_atime);
}
/* time of last data modification */
static void push_st_mtime (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_mtime);
}
/* time of last file status change */
static void push_st_ctime (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer) info->st_ctime);
}
/* file size, in bytes */
static void push_st_size (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_size);
}
#ifndef _WIN32
/* blocks allocated for file */
static void push_st_blocks (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_blocks);
}
/* optimal file system I/O blocksize */
static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
lua_pushinteger (L, (lua_Integer)info->st_blksize);
}
#endif
/*
** Convert the inode protection mode to a permission list.
*/
#ifdef _WIN32
static const char *perm2string (unsigned short mode) {
static char perms[10] = "---------";
int i;
for (i=0;i<9;i++) perms[i]='-';
if (mode & _S_IREAD)
{ perms[0] = 'r'; perms[3] = 'r'; perms[6] = 'r'; }
if (mode & _S_IWRITE)
{ perms[1] = 'w'; perms[4] = 'w'; perms[7] = 'w'; }
if (mode & _S_IEXEC)
{ perms[2] = 'x'; perms[5] = 'x'; perms[8] = 'x'; }
return perms;
}
#else
static const char *perm2string (mode_t mode) {
static char perms[10] = "---------";
int i;
for (i=0;i<9;i++) perms[i]='-';
if (mode & S_IRUSR) perms[0] = 'r';
if (mode & S_IWUSR) perms[1] = 'w';
if (mode & S_IXUSR) perms[2] = 'x';
if (mode & S_IRGRP) perms[3] = 'r';
if (mode & S_IWGRP) perms[4] = 'w';
if (mode & S_IXGRP) perms[5] = 'x';
if (mode & S_IROTH) perms[6] = 'r';
if (mode & S_IWOTH) perms[7] = 'w';
if (mode & S_IXOTH) perms[8] = 'x';
return perms;
}
#endif
/* permssions string */
static void push_st_perm (lua_State *L, STAT_STRUCT *info) {
lua_pushstring (L, perm2string (info->st_mode));
}
typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info);
struct _stat_members {
const char *name;
_push_function push;
};
struct _stat_members members[] = {
{ "mode", push_st_mode },
{ "dev", push_st_dev },
{ "ino", push_st_ino },
{ "nlink", push_st_nlink },
{ "uid", push_st_uid },
{ "gid", push_st_gid },
{ "rdev", push_st_rdev },
{ "access", push_st_atime },
{ "modification", push_st_mtime },
{ "change", push_st_ctime },
{ "size", push_st_size },
{ "permissions", push_st_perm },
#ifndef _WIN32
{ "blocks", push_st_blocks },
{ "blksize", push_st_blksize },
#endif
{ NULL, NULL }
};
/*
** Get file or symbolic link information
*/
static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
STAT_STRUCT info;
const char *file = luaL_checkstring (L, 1);
int i;
if (st(file, &info)) {
lua_pushnil (L);
lua_pushfstring (L, "cannot obtain information from file `%s'", file);
return 2;
}
if (lua_isstring (L, 2)) {
const char *member = lua_tostring (L, 2);
for (i = 0; members[i].name; i++) {
if (strcmp(members[i].name, member) == 0) {
/* push member value and return */
members[i].push (L, &info);
return 1;
}
}
/* member not found */
return luaL_error(L, "invalid attribute name");
}
/* creates a table if none is given */
if (!lua_istable (L, 2)) {
lua_newtable (L);
}
/* stores all members in table on top of the stack */
for (i = 0; members[i].name; i++) {
lua_pushstring (L, members[i].name);
members[i].push (L, &info);
lua_rawset (L, -3);
}
return 1;
}
/*
** Get file information using stat.
*/
static int file_info (lua_State *L) {
return _file_info_ (L, STAT_FUNC);
}
/*
** Get symbolic link information using lstat.
*/
static int link_info (lua_State *L) {
return _file_info_ (L, LSTAT_FUNC);
}
/*
** Assumes the table is on top of the stack.
*/
static void set_info (lua_State *L) {
lua_pushliteral (L, "_COPYRIGHT");
lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project");
lua_settable (L, -3);
lua_pushliteral (L, "_DESCRIPTION");
lua_pushliteral (L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution");
lua_settable (L, -3);
lua_pushliteral (L, "_VERSION");
lua_pushliteral (L, "LuaFileSystem "LFS_VERSION);
lua_settable (L, -3);
}
static const struct luaL_Reg fslib[] = {
{"attributes", file_info},
{"chdir", change_dir},
{"currentdir", get_dir},
{"dir", dir_iter_factory},
{"link", make_link},
{"lock", file_lock},
{"mkdir", make_dir},
{"rmdir", remove_dir},
{"symlinkattributes", link_info},
{"setmode", lfs_f_setmode},
{"touch", file_utime},
{"unlock", file_unlock},
{"lock_dir", lfs_lock_dir},
{NULL, NULL},
};
int luaopen_lfs (lua_State *L) {
dir_create_meta (L);
lock_create_meta (L);
luaL_newlib (L, fslib);
lua_pushvalue(L, -1);
lua_setglobal(L, LFS_LIBNAME);
set_info (L);
return 1;
}

4
3rdparty/luafilesystem/src/lfs.def vendored Normal file
View File

@ -0,0 +1,4 @@
LIBRARY lfs.dll
VERSION 1.6
EXPORTS
luaopen_lfs

34
3rdparty/luafilesystem/src/lfs.h vendored Normal file
View File

@ -0,0 +1,34 @@
/*
** LuaFileSystem
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
**
** $Id: lfs.h,v 1.5 2008/02/19 20:08:23 mascarenhas Exp $
*/
/* Define 'chdir' for systems that do not implement it */
#ifdef NO_CHDIR
#define chdir(p) (-1)
#define chdir_error "Function 'chdir' not provided by system"
#else
#define chdir_error strerror(errno)
#endif
#ifdef _WIN32
#define chdir(p) (_chdir(p))
#define getcwd(d, s) (_getcwd(d, s))
#define rmdir(p) (_rmdir(p))
#ifndef fileno
#define fileno(f) (_fileno(f))
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
int luaopen_lfs (lua_State *L);
#ifdef __cplusplus
}
#endif

175
3rdparty/luafilesystem/tests/test.lua vendored Normal file
View File

@ -0,0 +1,175 @@
#!/usr/bin/env lua5.1
local tmp = "/tmp"
local sep = string.match (package.config, "[^\n]+")
local upper = ".."
local lfs = require"lfs"
print (lfs._VERSION)
io.write(".")
io.flush()
function attrdir (path)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..sep..file
print ("\t=> "..f.." <=")
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
attrdir (f)
else
for name, value in pairs(attr) do
print (name, value)
end
end
end
end
end
-- Checking changing directories
local current = assert (lfs.currentdir())
local reldir = string.gsub (current, "^.*%"..sep.."([^"..sep.."])$", "%1")
assert (lfs.chdir (upper), "could not change to upper directory")
assert (lfs.chdir (reldir), "could not change back to current directory")
assert (lfs.currentdir() == current, "error trying to change directories")
assert (lfs.chdir ("this couldn't be an actual directory") == nil, "could change to a non-existent directory")
io.write(".")
io.flush()
-- Changing creating and removing directories
local tmpdir = current..sep.."lfs_tmp_dir"
local tmpfile = tmpdir..sep.."tmp_file"
-- Test for existence of a previous lfs_tmp_dir
-- that may have resulted from an interrupted test execution and remove it
if lfs.chdir (tmpdir) then
assert (lfs.chdir (upper), "could not change to upper directory")
assert (os.remove (tmpfile), "could not remove file from previous test")
assert (lfs.rmdir (tmpdir), "could not remove directory from previous test")
end
io.write(".")
io.flush()
-- tries to create a directory
assert (lfs.mkdir (tmpdir), "could not make a new directory")
local attrib, errmsg = lfs.attributes (tmpdir)
if not attrib then
error ("could not get attributes of file `"..tmpdir.."':\n"..errmsg)
end
local f = io.open(tmpfile, "w")
f:close()
io.write(".")
io.flush()
-- Change access time
local testdate = os.time({ year = 2007, day = 10, month = 2, hour=0})
assert (lfs.touch (tmpfile, testdate))
local new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == testdate, "could not set access time")
assert (new_att.modification == testdate, "could not set modification time")
io.write(".")
io.flush()
-- Change access and modification time
local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0})
local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0})
assert (lfs.touch (tmpfile, testdate2, testdate1))
local new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == testdate2, "could not set access time")
assert (new_att.modification == testdate1, "could not set modification time")
io.write(".")
io.flush()
-- Checking link (does not work on Windows)
if lfs.link (tmpfile, "_a_link_for_test_", true) then
assert (lfs.attributes"_a_link_for_test_".mode == "file")
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
assert (lfs.link (tmpfile, "_a_hard_link_for_test_"))
assert (lfs.attributes (tmpfile, "nlink") == 2)
assert (os.remove"_a_link_for_test_")
assert (os.remove"_a_hard_link_for_test_")
end
io.write(".")
io.flush()
-- Checking text/binary modes (only has an effect in Windows)
local f = io.open(tmpfile, "w")
local result, mode = lfs.setmode(f, "binary")
assert(result) -- on non-Windows platforms, mode is always returned as "binary"
result, mode = lfs.setmode(f, "text")
assert(result and mode == "binary")
f:close()
io.write(".")
io.flush()
-- Restore access time to current value
assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == attrib.access)
assert (new_att.modification == attrib.modification)
io.write(".")
io.flush()
-- Check consistency of lfs.attributes values
local attr = lfs.attributes (tmpfile)
for key, value in pairs(attr) do
assert (value == lfs.attributes (tmpfile, key),
"lfs.attributes values not consistent")
end
-- Remove new file and directory
assert (os.remove (tmpfile), "could not remove new file")
assert (lfs.rmdir (tmpdir), "could not remove new directory")
assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one")
io.write(".")
io.flush()
-- Trying to get attributes of a non-existent file
assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")
assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
io.write(".")
io.flush()
-- Stressing directory iterator
count = 0
for i = 1, 4000 do
for file in lfs.dir (tmp) do
count = count + 1
end
end
io.write(".")
io.flush()
-- Stressing directory iterator, explicit version
count = 0
for i = 1, 4000 do
local iter, dir = lfs.dir(tmp)
local file = dir:next()
while file do
count = count + 1
file = dir:next()
end
assert(not pcall(dir.next, dir))
end
io.write(".")
io.flush()
-- directory explicit close
local iter, dir = lfs.dir(tmp)
dir:close()
assert(not pcall(dir.next, dir))
print"Ok!"

5
3rdparty/luafilesystem/vc6/lfs.def vendored Normal file
View File

@ -0,0 +1,5 @@
LIBRARY lfs.dll
DESCRIPTION "LuaFileSystem"
VERSION 1.2
EXPORTS
luaopen_lfs

View File

@ -0,0 +1,33 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "luafilesystem_dll"=.\luafilesystem_dll.dsp - Package Owner=<4>
Package=<5>
{{{
begin source code control
luafilesystem
..
end source code control
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@ -0,0 +1,127 @@
# Microsoft Developer Studio Project File - Name="luafilesystem_dll" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=luafilesystem_dll - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "luafilesystem_dll.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "luafilesystem_dll.mak" CFG="luafilesystem_dll - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "luafilesystem_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "luafilesystem_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "luafilesystem_dll"
# PROP Scc_LocalPath ".."
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "luafilesystem_dll - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../lib/vc6"
# PROP Intermediate_Dir "luafilesystem_dll/Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUAFILESYSTEM_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../external-src/lua50/include" /I "../../compat/src" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUAFILESYSTEM_EXPORTS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x416 /d "NDEBUG"
# ADD RSC /l 0x416 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 lua50.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"../bin/vc6/lfs.dll" /libpath:"../../external-src/lua50/lib/dll"
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Cmds=cd ../bin/vc6 zip.exe luafilesystem-1.2-win32.zip lfs.dll
# End Special Build Tool
!ELSEIF "$(CFG)" == "luafilesystem_dll - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../lib/vc6"
# PROP Intermediate_Dir "luafilesystem_dll/Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUAFILESYSTEM_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../external-src/lua50/include" /I "../../compat/src" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUAFILESYSTEM_EXPORTS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x416 /d "_DEBUG"
# ADD RSC /l 0x416 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 lua50.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"../bin/vc6/lfsd.dll" /pdbtype:sept /libpath:"../../external-src/lua50/lib/dll"
!ENDIF
# Begin Target
# Name "luafilesystem_dll - Win32 Release"
# Name "luafilesystem_dll - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE="..\..\compat\src\compat-5.1.c"
# End Source File
# Begin Source File
SOURCE=..\src\lfs.c
# End Source File
# Begin Source File
SOURCE=.\lfs.def
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE="..\..\compat\src\compat-5.1.h"
# End Source File
# Begin Source File
SOURCE=..\src\lfs.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

270
3rdparty/luv/.ci/install.bat vendored Normal file
View File

@ -0,0 +1,270 @@
@echo off
cd %APPVEYOR_BUILD_FOLDER%
:: =========================================================
:: Set some defaults. Infer some variables.
::
:: These are set globally
if "%LUA_VER%" NEQ "" (
set LUA=lua
set LUA_SHORTV=%LUA_VER:~0,3%
) else (
set LUA=luajit
set LJ_SHORTV=%LJ_VER:~0,3%
set LUA_SHORTV=5.1
)
:: defines LUA_DIR so Cmake can find this Lua install
if "%LUA%"=="luajit" (
set LUA_DIR=c:\lua\%platform%\lj%LJ_SHORTV%
) else (
set LUA_DIR=c:\lua\%platform%\%LUA_VER%
)
:: Now we declare a scope
Setlocal EnableDelayedExpansion EnableExtensions
if not defined LUAROCKS_URL set LUAROCKS_URL=http://keplerproject.github.io/luarocks/releases
if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org
if not defined LUA_URL set LUA_URL=http://www.lua.org/ftp
if defined NOCOMPAT (
set COMPATFLAG=--nocompat
) else (
set COMPATFLAG=
)
if not defined LUAJIT_GIT_REPO set LUAJIT_GIT_REPO=https://github.com/LuaJIT/LuaJIT.git
if not defined LUAJIT_URL set LUAJIT_URL=https://github.com/LuaJIT/LuaJIT/archive
if not defined LR_EXTERNAL set LR_EXTERNAL=c:\external
if not defined LUAROCKS_INSTALL set LUAROCKS_INSTALL=%LUA_DIR%\LuaRocks
:: LuaRocks <= 2.2.2 used a versioned directory
:: HEAD and newer versions do not, so act accordingly.
if defined LR_ROOT goto :skiplrver
if "%LUAROCKS_VER%" EQU "HEAD" (
set LR_ROOT=%LUAROCKS_INSTALL%
goto :skiplrver
)
set LR_ROOT=%LUAROCKS_INSTALL%
if %LUAROCKS_VER:~0,1% LEQ 2 (
if %LUAROCKS_VER:~2,1% LEQ 2 (
if %LUAROCKS_VER:~4,1% LEQ 3 (
set LR_ROOT=%LUAROCKS_INSTALL%\!LUAROCKS_VER:~0,3!
)
)
)
:skiplrver
if not defined LR_SYSTREE set LR_SYSTREE=%LUAROCKS_INSTALL%\systree
if not defined SEVENZIP set SEVENZIP=7z
::
:: =========================================================
:: first create some necessary directories:
mkdir downloads 2>NUL
:: Download and compile Lua (or LuaJIT)
if "%LUA%"=="luajit" (
if not exist %LUA_DIR% (
if "%LJ_SHORTV%"=="2.1" (
:: Clone repository and checkout 2.1 branch
set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
if not exist !lj_source_folder! (
echo Cloning git repo %LUAJIT_GIT_REPO% !lj_source_folder!
git clone %LUAJIT_GIT_REPO% !lj_source_folder! || call :die "Failed to clone repository"
) else (
cd !lj_source_folder!
git pull || call :die "Failed to update repository"
)
cd !lj_source_folder!\src
git checkout v2.1 || call :die
) else (
set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
if not exist !lj_source_folder! (
echo Downloading... %LUAJIT_URL%/v%LJ_VER%.tar.gz
curl --location --silent --fail --max-time 120 --connect-timeout 30 %LUAJIT_URL%/v%LJ_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
)
cd !lj_source_folder!\src
)
:: Compiles LuaJIT
if "%Configuration%"=="MinGW" (
call mingw32-make
) else (
call msvcbuild.bat
)
mkdir %LUA_DIR% 2> NUL
for %%a in (bin bin\lua bin\lua\jit include lib) do ( mkdir "%LUA_DIR%\%%a" )
for %%a in (luajit.exe lua51.dll) do ( move "!lj_source_folder!\src\%%a" "%LUA_DIR%\bin" )
copy "%LUA_DIR%\bin\luajit.exe" "%LUA_DIR%\bin\lua.exe"
move "!lj_source_folder!\src\lua51.lib" "%LUA_DIR%\lib"
for %%a in (lauxlib.h lua.h lua.hpp luaconf.h lualib.h luajit.h) do (
copy "!lj_source_folder!\src\%%a" "%LUA_DIR%\include"
)
copy "!lj_source_folder!\src\jit\*.lua" "%LUA_DIR%\bin\lua\jit"
) else (
echo LuaJIT %LJ_VER% already installed at %LUA_DIR%
)
) else (
if not exist %LUA_DIR% (
:: Download and compile Lua
if not exist downloads\lua-%LUA_VER% (
curl --silent --fail --max-time 120 --connect-timeout 30 %LUA_URL%/lua-%LUA_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
)
mkdir downloads\lua-%LUA_VER%\etc 2> NUL
copy %~dp0\winmake.bat downloads\lua-%LUA_VER%\etc\winmake.bat
cd downloads\lua-%LUA_VER%
call etc\winmake %COMPATFLAG%
call etc\winmake install %LUA_DIR%
) else (
echo Lua %LUA_VER% already installed at %LUA_DIR%
)
)
if not exist %LUA_DIR%\bin\%LUA%.exe call :die "Missing Lua interpreter at %LUA_DIR%\bin\%LUA%.exe"
set PATH=%LUA_DIR%\bin;%PATH%
call !LUA! -v
:: ==========================================================
:: LuaRocks
:: ==========================================================
if not exist "%LR_ROOT%" (
:: Downloads and installs LuaRocks
cd %APPVEYOR_BUILD_FOLDER%
if %LUAROCKS_VER%==HEAD (
set lr_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luarocks-%LUAROCKS_VER%-win32
if not exist !lr_source_folder! (
git clone https://github.com/keplerproject/luarocks.git --single-branch --depth 1 !lr_source_folder! || call :die "Failed to clone LuaRocks repository"
) else (
cd !lr_source_folder!
git pull || call :die "Failed to update LuaRocks repository"
)
) else (
if not exist downloads\luarocks-%LUAROCKS_VER%-win32.zip (
echo Downloading LuaRocks...
curl --silent --fail --max-time 120 --connect-timeout 30 --output downloads\luarocks-%LUAROCKS_VER%-win32.zip %LUAROCKS_URL%/luarocks-%LUAROCKS_VER%-win32.zip
%SEVENZIP% x -aoa -odownloads downloads\luarocks-%LUAROCKS_VER%-win32.zip
)
)
cd downloads\luarocks-%LUAROCKS_VER%-win32
if "%Configuration%"=="MinGW" (
call install.bat /LUA %LUA_DIR% /Q /LV %LUA_SHORTV% /P "%LUAROCKS_INSTALL%" /TREE "%LR_SYSTREE%" /MW
) else (
call install.bat /LUA %LUA_DIR% /Q /LV %LUA_SHORTV% /P "%LUAROCKS_INSTALL%" /TREE "%LR_SYSTREE%"
)
:: Configures LuaRocks to instruct CMake the correct generator to use. Else, CMake will pick the highest
:: Visual Studio version installed
if "%Configuration%"=="MinGW" (
echo cmake_generator = "MinGW Makefiles" >> %LUAROCKS_INSTALL%\config-%LUA_SHORTV%.lua
) else (
set MSVS_GENERATORS[2008]=Visual Studio 9 2008
set MSVS_GENERATORS[2010]=Visual Studio 10 2010
set MSVS_GENERATORS[2012]=Visual Studio 11 2012
set MSVS_GENERATORS[2013]=Visual Studio 12 2013
set MSVS_GENERATORS[2015]=Visual Studio 14 2015
set CMAKE_GENERATOR=!MSVS_GENERATORS[%Configuration%]!
if "%platform%" EQU "x64" (set CMAKE_GENERATOR=!CMAKE_GENERATOR! Win64)
echo cmake_generator = "!CMAKE_GENERATOR!" >> %LUAROCKS_INSTALL%\config-%LUA_SHORTV%.lua
)
)
if not exist "%LR_ROOT%" call :die "LuaRocks not found at %LR_ROOT%"
set PATH=%LR_ROOT%;%LR_SYSTREE%\bin;%PATH%
:: Lua will use just the system rocks
set LUA_PATH=%LR_ROOT%\lua\?.lua;%LR_ROOT%\lua\?\init.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?\init.lua
set LUA_PATH=%LUA_PATH%;.\?.lua;.\?\init.lua
set LUA_CPATH=%LR_SYSTREE%\lib\lua\%LUA_SHORTV%\?.dll;.\?.dll
call luarocks --version || call :die "Error with LuaRocks installation"
call luarocks list
if not exist "%LR_EXTERNAL%" (
mkdir "%LR_EXTERNAL%"
mkdir "%LR_EXTERNAL%\lib"
mkdir "%LR_EXTERNAL%\include"
)
set PATH=%LR_EXTERNAL%;%PATH%
:: Exports the following variables:
:: (beware of whitespace between & and ^ below)
endlocal & set PATH=%PATH%&^
set LR_SYSTREE=%LR_SYSTREE%&^
set LUA_PATH=%LUA_PATH%&^
set LUA_CPATH=%LUA_CPATH%&^
set LR_EXTERNAL=%LR_EXTERNAL%
echo.
echo ======================================================
if "%LUA%"=="luajit" (
echo Installation of LuaJIT %LJ_VER% and LuaRocks %LUAROCKS_VER% done.
) else (
echo Installation of Lua %LUA_VER% and LuaRocks %LUAROCKS_VER% done.
if defined NOCOMPAT echo Lua was built with compatibility flags disabled.
)
echo Platform - %platform%
echo LUA - %LUA%
echo LUA_SHORTV - %LUA_SHORTV%
echo LJ_SHORTV - %LJ_SHORTV%
echo LUA_PATH - %LUA_PATH%
echo LUA_CPATH - %LUA_CPATH%
echo.
echo LR_EXTERNAL - %LR_EXTERNAL%
echo ======================================================
echo.
goto :eof
:: This blank space is intentional. If you see errors like "The system cannot find the batch label specified 'foo'"
:: then try adding or removing blank lines lines above.
:: Yes, really.
:: http://stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-e
:: helper functions:
:: for bailing out when an error occurred
:die %1
echo %1
exit /B 1
goto :eof

15
3rdparty/luv/.ci/platform.sh vendored Normal file
View File

@ -0,0 +1,15 @@
if [ -z "${PLATFORM:-}" ]; then
PLATFORM=$TRAVIS_OS_NAME;
fi
if [ "$PLATFORM" == "osx" ]; then
PLATFORM="macosx";
fi
if [ -z "$PLATFORM" ]; then
if [ "$(uname)" == "Linux" ]; then
PLATFORM="linux";
else
PLATFORM="macosx";
fi;
fi

40
3rdparty/luv/.ci/set_compiler_env.bat vendored Normal file
View File

@ -0,0 +1,40 @@
@echo off
:: Now we declare a scope
Setlocal EnableDelayedExpansion EnableExtensions
if not defined Configuration set Configuration=2015
if "%Configuration%"=="MinGW" ( goto :mingw )
set arch=x86
if "%platform%" EQU "x64" ( set arch=x86_amd64 )
if "%Configuration%"=="2015" (
set SET_VS_ENV="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
)
if "%Configuration%"=="2013" (
set SET_VS_ENV="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
)
if "%Configuration%"=="2012" (
set SET_VS_ENV="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
)
if "%Configuration%"=="2010" (
set SET_VS_ENV="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
)
if "%Configuration%"=="2008" (
set SET_VS_ENV="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
)
:: Visual Studio detected
endlocal & call %SET_VS_ENV% %arch%
goto :eof
:: MinGW detected
:mingw
endlocal & set PATH=c:\mingw\bin;%PATH%

3
3rdparty/luv/.ci/setenv_lua.sh vendored Normal file
View File

@ -0,0 +1,3 @@
export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin
bash .ci/setup_lua.sh
eval `$HOME/.lua/luarocks path`

122
3rdparty/luv/.ci/setup_lua.sh vendored Normal file
View File

@ -0,0 +1,122 @@
#! /bin/bash
# A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit".
# luajit2.0 - master v2.0
# luajit2.1 - master v2.1
set -eufo pipefail
LUAJIT_VERSION="2.0.4"
LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION"
source .ci/platform.sh
LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/lua
LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks
mkdir $HOME/.lua
LUAJIT="no"
if [ "$PLATFORM" == "macosx" ]; then
if [ "$LUA" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.0" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.1" ]; then
LUAJIT="yes";
fi;
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
LUAJIT="yes";
fi
mkdir -p "$LUA_HOME_DIR"
if [ "$LUAJIT" == "yes" ]; then
if [ "$LUA" == "luajit" ]; then
curl --location https://github.com/LuaJIT/LuaJIT/archive/v$LUAJIT_VERSION.tar.gz | tar xz;
else
git clone https://github.com/LuaJIT/LuaJIT.git $LUAJIT_BASE;
fi
cd $LUAJIT_BASE
if [ "$LUA" == "luajit2.1" ]; then
git checkout v2.1;
# force the INSTALL_TNAME to be luajit
perl -i -pe 's/INSTALL_TNAME=.+/INSTALL_TNAME= luajit/' Makefile
fi
make && make install PREFIX="$LUA_HOME_DIR"
ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit
ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua;
else
if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz
cd lua-5.2.4;
elif [ "$LUA" == "lua5.3" ]; then
curl http://www.lua.org/ftp/lua-5.3.2.tar.gz | tar xz
cd lua-5.3.2;
fi
# Build Lua without backwards compatibility for testing
perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile
make $PLATFORM
make INSTALL_TOP="$LUA_HOME_DIR" install;
ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua
ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac;
fi
cd $TRAVIS_BUILD_DIR
lua -v
LUAROCKS_BASE=luarocks-$LUAROCKS
curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
cd $LUAROCKS_BASE
if [ "$LUA" == "luajit" ]; then
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
elif [ "$LUA" == "luajit2.0" ]; then
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
elif [ "$LUA" == "luajit2.1" ]; then
./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR";
else
./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR"
fi
make build && make install
ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks
cd $TRAVIS_BUILD_DIR
luarocks --version
rm -rf $LUAROCKS_BASE
if [ "$LUAJIT" == "yes" ]; then
rm -rf $LUAJIT_BASE;
elif [ "$LUA" == "lua5.1" ]; then
rm -rf lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
rm -rf lua-5.2.4;
elif [ "$LUA" == "lua5.3" ]; then
rm -rf lua-5.3.2;
fi

457
3rdparty/luv/.ci/winmake.bat vendored Normal file
View File

@ -0,0 +1,457 @@
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM *****************************
REM * Customization section *
REM *****************************
REM use the /help option for generic usage information
REM Where is the source code located (the unpacked Lua source archive, toplevel dir)
SET SOURCETREE=.\
REM set the toolchain to either MS or GCC (allcaps), leave blank to autodetect
SET TOOLCHAIN=
REM set the compatibility flags, defaults to empty for 5.1, -DLUA_COMPAT_ALL for 5.2,
REM and -DLUA_COMPAT_5_2 for 5.3, which are the same as the unix make files
REM This setting can be overridden with the --nocompat flag
SET COMPATFLAG=
REM **********************************
REM * Nothing to customize below *
REM **********************************
SET BATCHNAME=%~n0
SET SOURCE=%SOURCETREE%src\
SET LUA_H=%SOURCE%lua.h
SET CURDIR=%CD%
REM the following line ends with a TAB. DO NOT REMOVE IT!
SET TABCHAR=
REM Define LF to contain a linefeed character
set ^"LFCHAR=^
^" The above empty line is critical. DO NOT REMOVE
REM Supported toolchains (allcaps)
SET TOOLCHAINS=MS GCC
REM Commands which, if exiting without error, indicate presence of the toolchain
SET CHECK_GCC=gcc --version
SET CHECK_MS=cl
REM **********************************
REM * Check for help request *
REM **********************************
SET HELPCMDS=help -help --help /help ? -? /?
for %%L in ("!LFCHAR!") do for /f %%a in ("!HELPCMDS: =%%~L!") do (
if "%%a"=="%~1" (
echo.
echo Builds a standalone Lua installation. Supports Lua version 5.1, 5.2 and 5.3.
echo Your compiler must be in the system path, and this "%BATCHNAME%.bat" file must be located
echo in ".\etc\" in the unpacked Lua source archive.
echo.
echo USAGE etc\%BATCHNAME% [FLAG] [COMMAND] [...]
echo ^(execute from the root of the unpacked archive^)
echo.
echo Commands;
echo clean : cleans the source tree of build ^(intermediate^) files
echo install [path] : installs the build results into "path"
echo local : installs into ".\local\" in the unpacked Lua source structure
echo [toolchain] : uses a specific toolchain to build. If not provided then supported
echo toolchains will be tested and the first available will be picked.
echo Supported toolchains are: "%TOOLCHAINS%" ^(must use ALLCAPS^)
echo.
echo Flags;
echo --nocompat : Specifies that no compatibility flags should be set when building.
echo If not specified, the default compatibility flags will be used.
echo.
echo Example use;
echo set PATH=C:\path\to\your\compiler\;%%PATH%%
echo etc\%BATCHNAME% clean
echo etc\%BATCHNAME%
echo etc\%BATCHNAME% --nocompat GCC
echo etc\%BATCHNAME% install "C:\Program Files\Lua"
echo.
goto :EXITOK
)
)
REM **********************************
REM * Check commandline *
REM **********************************
SET CMDOK=FALSE
if "%~1"=="" (
SET CMDOK=TRUE
)
for %%a in (local install clean) do (
if "%%a"=="%~1" (
SET CMDOK=TRUE
)
)
for %%a in (--nocompat) do (
if "%%a"=="%~1" (
SET NOCOMPAT=TRUE
if "%~2"=="" (
SET CMDOK=TRUE
)
SHIFT
)
)
for %%a in (%TOOLCHAINS%) do (
if "%%a"=="%~1" (
SET CMDOK=TRUE
SET TOOLCHAIN=%~1
)
)
if NOT %CMDOK%==TRUE (
echo.
echo Unknown command or toolchain specified.
goto :EXITERROR
)
REM **************************************
REM * Check for cleaning *
REM **************************************
if "%1"=="clean" (
if NOT [%2]==[] (
echo.
echo ERROR: The clean command does not take extra parameters.
) else (
echo Cleaning...
if exist "%SOURCE%*.exe" del "%SOURCE%*.exe"
if exist "%SOURCE%*.dll" del "%SOURCE%*.dll"
if exist "%SOURCE%*.o" del "%SOURCE%*.o"
if exist "%SOURCE%*.a" del "%SOURCE%*.a"
if exist "%SOURCE%*.obj" del "%SOURCE%*.obj"
if exist "%SOURCE%*.manifest" del "%SOURCE%*.manifest"
if exist "%SOURCE%*.lib" del "%SOURCE%*.lib"
echo Done.
)
goto :EXITOK
)
REM **************************************************
REM * Fetch the Lua version from the source code *
REM **************************************************
Echo.
Echo Checking source code to extract Lua version...
IF NOT EXIST %LUA_H% (
Echo Cannot locate Lua header file; %LUA_H%
goto :EXITERROR
)
findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR" %LUA_H% > NUL
if NOT %ERRORLEVEL%==0 (
rem ECHO We've got a Lua version 5.1
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION[ %TABCHAR%]" %LUA_H%
SET LUA_VER=5.1
) else (
rem ECHO We've got a Lua version 5.2+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%') do set LUA_MAJOR=%%a
SET LUA_MAJOR=!LUA_MAJOR:#define=!
SET LUA_MAJOR=!LUA_MAJOR:LUA_VERSION_MAJOR=!
SET LUA_MAJOR=!LUA_MAJOR: =!
SET LUA_MAJOR=!LUA_MAJOR:%TABCHAR%=!
SET LUA_MAJOR=!LUA_MAJOR:"=!
SET LUA_MAJOR=!LUA_MAJOR:~0,1!
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%') do set LUA_MINOR=%%a
SET LUA_MINOR=!LUA_MINOR:#define=!
SET LUA_MINOR=!LUA_MINOR:LUA_VERSION_MINOR=!
SET LUA_MINOR=!LUA_MINOR: =!
SET LUA_MINOR=!LUA_MINOR:%TABCHAR%=!
SET LUA_MINOR=!LUA_MINOR:"=!
SET LUA_MINOR=!LUA_MINOR:~0,1!
SET LUA_VER=!LUA_MAJOR!.!LUA_MINOR!
)
SET LUA_SVER=!LUA_VER:.=!
Echo Lua version found: %LUA_VER%
Echo.
REM **************************************
REM * Set some Lua version specifics *
REM **************************************
REM FILES_CORE; files for Lua core (+lauxlib, needed for Luac)
REM FILES_LIB; files for Lua standard libraries
REM FILES_DLL; vm files to be build with dll option
REM FILES_OTH; vm files to be build without dll, for static linking
if %LUA_SVER%==51 (
set FILES_CORE=lapi lcode ldebug ldo ldump lfunc lgc llex lmem lobject lopcodes lparser lstate lstring ltable ltm lundump lvm lzio lauxlib
set FILES_LIB=lbaselib ldblib liolib lmathlib loslib ltablib lstrlib loadlib linit
set FILES_DLL=lua
set FILES_OTH=luac print
set INSTALL_H=lauxlib.h lua.h luaconf.h lualib.h ..\etc\lua.hpp
)
if %LUA_SVER%==52 (
set FILES_CORE=lapi lcode lctype ldebug ldo ldump lfunc lgc llex lmem lobject lopcodes lparser lstate lstring ltable ltm lundump lvm lzio lauxlib
set FILES_LIB=lbaselib lbitlib lcorolib ldblib liolib lmathlib loslib lstrlib ltablib loadlib linit
set FILES_DLL=lua
set FILES_OTH=luac
set INSTALL_H=lauxlib.h lua.h lua.hpp luaconf.h lualib.h
if "%COMPATFLAG%"=="" (
set COMPATFLAG=-DLUA_COMPAT_ALL
)
)
if %LUA_SVER%==53 (
set FILES_CORE=lapi lcode lctype ldebug ldo ldump lfunc lgc llex lmem lobject lopcodes lparser lstate lstring ltable ltm lundump lvm lzio lauxlib
set FILES_LIB=lbaselib lbitlib lcorolib ldblib liolib lmathlib loslib lstrlib ltablib lutf8lib loadlib linit
set FILES_DLL=lua
set FILES_OTH=luac
set INSTALL_H=lauxlib.h lua.h lua.hpp luaconf.h lualib.h
if "%COMPATFLAG%"=="" (
set COMPATFLAG=-DLUA_COMPAT_5_2
)
)
if "%NOCOMPAT%"=="TRUE" (
set COMPATFLAG=
)
SET FILES_BASE=%FILES_DLL% %FILES_CORE% %FILES_LIB%
if "%FILES_BASE%"=="" (
Echo Unknown Lua version; %LUA_VER%
goto :EXITERROR
)
REM *********************************
REM * Check available toolchain *
REM *********************************
if [%TOOLCHAIN%]==[] (
Echo Testing for MS...
%CHECK_MS%
IF !ERRORLEVEL!==0 SET TOOLCHAIN=MS
)
if [%TOOLCHAIN%]==[] (
Echo Testing for GCC...
%CHECK_GCC%
IF !ERRORLEVEL!==0 SET TOOLCHAIN=GCC
)
if [%TOOLCHAIN%]==[] (
Echo No supported toolchain found ^(please make sure it is in the system path^)
goto :EXITERROR
)
REM ***************************
REM * Configure toolchain *
REM ***************************
if %TOOLCHAIN%==GCC (
echo Using GCC toolchain...
SET OBJEXT=o
SET LIBFILE=liblua%LUA_SVER%.a
)
if %TOOLCHAIN%==MS (
echo Using Microsoft toolchain...
SET OBJEXT=obj
SET LIBFILE=lua%LUA_SVER%.lib
)
echo.
REM **************************************
REM * Check for installing *
REM **************************************
if "%1"=="install" (
if "%~2"=="" (
echo.
echo ERROR: The install command requires a path where to install to.
goto :EXITERROR
)
SET TARGETPATH=%~2
)
if "%1"=="local" (
if NOT "%~2"=="" (
echo.
echo ERROR: The local command does not take extra parameters.
goto :EXITERROR
)
SET TARGETPATH=%SOURCETREE%local
)
if NOT "%TARGETPATH%"=="" (
mkdir "%TARGETPATH%\bin"
mkdir "%TARGETPATH%\include"
mkdir "%TARGETPATH%\lib\lua\%LUA_VER%"
mkdir "%TARGETPATH%\man\man1"
mkdir "%TARGETPATH%\share\lua\%LUA_VER%"
copy "%SOURCE%lua.exe" "%TARGETPATH%\bin"
copy "%SOURCE%luac.exe" "%TARGETPATH%\bin"
copy "%SOURCE%lua%LUA_SVER%.dll" "%TARGETPATH%\bin"
for %%a in (%INSTALL_H%) do ( copy "%SOURCE%%%a" "%TARGETPATH%\include" )
copy "%SOURCE%%LIBFILE%" "%TARGETPATH%\lib"
copy "%SOURCETREE%doc\lua.1" "%TARGETPATH%\man\man1"
copy "%SOURCETREE%doc\luac.1" "%TARGETPATH%\man\man1"
echo Installation completed in "%TARGETPATH%".
goto :EXITOK
)
REM ***********************
REM * Compile sources *
REM ***********************
goto :after_compile_function
:compile_function
REM Params: %1 is filelist (must be quoted)
REM Return: same list, with the object file extension included, will be stored in global OBJLIST
for %%a in (%~1) do (
SET FILENAME=%%a
if %TOOLCHAIN%==GCC (
SET COMPCMD=gcc -O2 -Wall !EXTRAFLAG! !COMPATFLAG! -c -o !FILENAME!.%OBJEXT% !FILENAME!.c
)
if %TOOLCHAIN%==MS (
SET COMPCMD=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE !COMPATFLAG! !EXTRAFLAG! !FILENAME!.c
)
echo !COMPCMD!
!COMPCMD!
SET OBJLIST=!OBJLIST! !FILENAME!.%OBJEXT%
)
goto :eof
:after_compile_function
CD %SOURCE%
REM Traverse the 4 lists of source files
for %%b in (CORE LIB DLL OTH) do (
SET LTYPE=%%b
SET OBJLIST=
if !LTYPE!==OTH (
REM OTH is the only list of files build without DLL option
SET EXTRAFLAG=
) else (
SET EXTRAFLAG=-DLUA_BUILD_AS_DLL
)
if !LTYPE!==CORE SET FILELIST=%FILES_CORE%
if !LTYPE!==LIB SET FILELIST=%FILES_LIB%
if !LTYPE!==DLL SET FILELIST=%FILES_DLL%
if !LTYPE!==OTH SET FILELIST=%FILES_OTH%
echo Now compiling !LTYPE! file set...
call:compile_function "!FILELIST!"
if !LTYPE!==CORE SET FILES_CORE_O=!OBJLIST!
if !LTYPE!==LIB SET FILES_LIB_O=!OBJLIST!
if !LTYPE!==DLL SET FILES_DLL_O=!OBJLIST!
if !LTYPE!==OTH SET FILES_OTH_O=!OBJLIST!
)
REM ****************************
REM * Link GCC based files *
REM ****************************
if %TOOLCHAIN%==GCC (
REM Link the LuaXX.dll file
SET LINKCMD=gcc -shared -o lua%LUA_SVER%.dll %FILES_CORE_O% %FILES_LIB_O%
echo !LINKCMD!
!LINKCMD!
REM strip from LuaXX.dll
SET RANCMD=strip --strip-unneeded lua%LUA_SVER%.dll
echo !RANCMD!
!RANCMD!
REM Link the Lua.exe file
SET LINKCMD=gcc -o lua.exe -s lua.%OBJEXT% lua%LUA_SVER%.dll -lm
echo !LINKCMD!
!LINKCMD!
REM create lib archive
SET LIBCMD=ar rcu liblua%LUA_SVER%.a %FILES_CORE_O% %FILES_LIB_O%
echo !LIBCMD!
!LIBCMD!
REM Speedup index using ranlib
SET RANCMD=ranlib liblua%LUA_SVER%.a
echo !RANCMD!
!RANCMD!
REM Link Luac.exe file
SET LINKCMD=gcc -o luac.exe %FILES_OTH_O% liblua%LUA_SVER%.a -lm
echo !LINKCMD!
!LINKCMD!
)
REM ****************************
REM * Link MS based files *
REM ****************************
if %TOOLCHAIN%==MS (
REM Link the LuaXX.dll file, and LuaXX.obj
SET LINKCMD=link /nologo /DLL /out:lua%LUA_SVER%.dll %FILES_CORE_O% %FILES_LIB_O%
echo !LINKCMD!
!LINKCMD!
REM handle dll manifest
if exist lua%LUA_SVER%.dll.manifest (
SET MANICMD=mt /nologo -manifest lua%LUA_SVER%.dll.manifest -outputresource:lua%LUA_SVER%.dll;2
echo !MANICMD!
!MANICMD!
)
REM Link Lua.exe
SET LINKCMD=link /nologo /out:lua.exe lua.%OBJEXT% lua%LUA_SVER%.lib
echo !LINKCMD!
!LINKCMD!
REM handle manifest
if exist lua.exe.manifest (
SET MANICMD=mt /nologo -manifest lua.exe.manifest -outputresource:lua.exe
echo !MANICMD!
!MANICMD!
)
REM Link Luac.exe
SET LINKCMD=link /nologo /out:luac.exe %FILES_OTH_O% %FILES_CORE_O%
echo !LINKCMD!
!LINKCMD!
REM handle manifest
if exist luac.exe.manifest (
SET MANICMD=mt /nologo -manifest luac.exe.manifest -outputresource:luac.exe
echo !MANICMD!
!MANICMD!
)
)
CD %CURDIR%
REM ****************************
REM * Finished building *
REM ****************************
echo.
echo Build completed.
goto :EXITOK
:EXITOK
exit /B 0
:EXITERROR
echo For help try; etc\%BATCHNAME% /help
exit /B 1

10
3rdparty/luv/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
build
libluv.a
libluv.so
luv.so
luv.dll
luajit.exe
luv-*.tar.gz
luv-*.src.rock
luv-*/
build.luarocks/

36
3rdparty/luv/.travis.yml vendored Normal file
View File

@ -0,0 +1,36 @@
language: c
sudo: false
addons:
apt:
sources:
- kalakris-cmake
packages:
- cmake
env:
global:
- LUAROCKS=2.3.0
matrix:
- WITH_LUA_ENGINE=Lua LUA=lua5.3
- WITH_LUA_ENGINE=LuaJIT LUA=luajit2.1
- PROCESS_CLEANUP_TEST=1 LUA=lua5.2
os:
- linux
- osx
before_install:
- git submodule update --init --recursive
- git submodule update --recursive
script:
- if [ "x$PROCESS_CLEANUP_TEST" = "x" ]; then make && make test; else ./tests/test-sigchld-after-lua_close.sh; fi
# Test rock installation
- source .ci/setenv_lua.sh
- luarocks make
- test $PWD = `lua -e "print(require'luv'.cwd())"`
notifications:
email: true
irc: "irc.freenode.org#luvit"

191
3rdparty/luv/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,191 @@
cmake_minimum_required(VERSION 2.8)
if(POLICY CMP0053)
cmake_policy(SET CMP0053 NEW) # faster evaluation of variable references
endif()
project (luv C ASM)
set(LUV_VERSION_MAJOR 1)
set(LUV_VERSION_MINOR 8)
set(LUV_VERSION_PATCH 0)
set(LUV_VERSION ${LUV_VERSION_MAJOR}.${LUV_VERSION_MINOR}.${LUV_VERSION_PATCH})
option(BUILD_MODULE "Build as module" ON)
option(BUILD_SHARED_LIBS "Build shared library" OFF)
option(WITH_SHARED_LIBUV "Link to a shared libuv library instead of static linking" OFF)
if (NOT WITH_LUA_ENGINE)
set(WITH_LUA_ENGINE "LuaJIT"
CACHE STRING "Link to LuaJIT or PUC Lua" FORCE)
set_property(CACHE WITH_LUA_ENGINE
PROPERTY STRINGS "Lua;LuaJIT")
endif (NOT WITH_LUA_ENGINE)
if (NOT LUA_BUILD_TYPE)
set(LUA_BUILD_TYPE "Static"
CACHE STRING "Build Lua/LuaJIT as static, dynamic libary, or use system one" FORCE)
set_property(CACHE LUA_BUILD_TYPE
PROPERTY STRINGS "Static;Dynamic;System")
endif (NOT LUA_BUILD_TYPE)
if (WITH_LUA_ENGINE STREQUAL Lua)
add_definitions(-DLUA_USE_DLOPEN)
set(USE_LUAJIT OFF)
else ()
set(USE_LUAJIT ON)
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
if (WITH_SHARED_LIBUV)
find_package(Libuv)
if (LIBUV_FOUND)
include_directories(${LIBUV_INCLUDE_DIR})
endif (LIBUV_FOUND)
else (WITH_SHARED_LIBUV)
include(deps/uv.cmake)
if (BUILD_MODULE)
add_definitions( -DBUILDING_UV_SHARED )
endif (BUILD_MODULE)
endif (WITH_SHARED_LIBUV)
if (LUA)
MESSAGE(STATUS "Lua: using information from luarocks")
MESSAGE(STATUS "LUA_LIBDIR: " ${LUA_LIBDIR})
MESSAGE(STATUS "LUA_INCDIR: " ${LUA_INCDIR})
MESSAGE(STATUS "LUA: " ${LUA})
SET(LUA_EXECUTABLE "${LUA}")
SET(LUA_INCLUDE_DIR "${LUA_INCDIR}")
SET(LUA_PACKAGE_PATH "${LUADIR}")
SET(LUA_PACKAGE_CPATH "${LIBDIR}")
SET(INSTALL_LIB_DIR ${LIBDIR})
GET_FILENAME_COMPONENT(LUA_EXEC_NAME ${LUA_EXECUTABLE} NAME_WE)
IF(LUA_EXEC_NAME STREQUAL "luajit")
FIND_LIBRARY(LUA_LIBRARIES
NAMES luajit libluajit
PATHS ${LUA_LIBDIR}
NO_DEFAULT_PATH)
ELSEIF(LUA_EXEC_NAME STREQUAL "lua")
FIND_LIBRARY(LUA_LIBRARIES
NAMES lua lua53 lua52 lua51 liblua liblua53 liblua52 liblua51
PATHS ${LUA_LIBDIR}
NO_DEFAULT_PATH)
ENDIF()
MESSAGE(STATUS "Lua library: ${LUA_LIBRARIES}")
include_directories(${LUA_INCLUDE_DIR})
else (LUA)
if (LUA_BUILD_TYPE STREQUAL System)
if (USE_LUAJIT)
find_package(LuaJIT)
if (LUAJIT_FOUND)
include_directories(${LUAJIT_INCLUDE_DIR})
link_directories(${LUAJIT_LIBRARIES})
endif (LUAJIT_FOUND)
else (USE_LUAJIT)
find_package(Lua)
if (LUA_FOUND)
include_directories(${LUA_INCLUDE_DIR})
endif (LUA_FOUND)
endif (USE_LUAJIT)
else (LUA_BUILD_TYPE STREQUAL System)
if (LUA_BUILD_TYPE STREQUAL Static)
SET(WITH_SHARED_LUA OFF)
else (LUA_BUILD_TYPE STREQUAL Static)
SET(WITH_SHARED_LUA ON)
endif (LUA_BUILD_TYPE STREQUAL Static)
if (USE_LUAJIT)
include(deps/luajit.cmake)
include_directories(deps/luajit/src)
else(USE_LUAJIT)
include(deps/lua.cmake)
include_directories(deps/lua/src)
endif (USE_LUAJIT)
endif (LUA_BUILD_TYPE STREQUAL System)
endif (LUA)
if (BUILD_MODULE)
add_library(luv MODULE src/luv.c)
set_target_properties(luv PROPERTIES PREFIX "")
else (BUILD_MODULE)
add_library(luv src/luv.c)
if (BUILD_SHARED_LIBS)
set_target_properties(luv
PROPERTIES VERSION ${LUV_VERSION} SOVERSION ${LUV_VERSION_MAJOR})
endif (BUILD_SHARED_LIBS)
endif (BUILD_MODULE)
if(APPLE)
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress"
)
# execute_process(COMMAND which luajit OUTPUT_VARIABLE LUAJIT)
# set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
# "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -bundle_loader ${LUAJIT}"
# )
endif()
if(WIN32)
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB)
if (LUA)
target_link_libraries(luv uv ${LUA_LIBRARIES})
else (LUA)
if (USE_LUAJIT)
target_link_libraries(luv uv luajit-5.1)
else (USE_LUAJIT)
if (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(luv uv ${LUA_LIBRARIES})
else (LUA_BUILD_TYPE STREQUAL System)
target_link_libraries(luv uv lualib)
endif (LUA_BUILD_TYPE STREQUAL System)
endif (USE_LUAJIT)
endif (LUA)
# replace /MD to /MT to avoid link msvcr*.dll
set(CompilerFlags
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_RELEASE)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(luv uv rt)
else()
target_link_libraries(luv uv)
endif()
if (NOT LUA)
if (BUILD_MODULE)
if (WIN32)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
else (WIN32)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
endif (WIN32)
else (BUILD_MODULE)
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib"
CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include/luv"
CACHE PATH "Installation directory for headers")
endif (BUILD_MODULE)
endif ()
if (CMAKE_INSTALL_PREFIX)
install(TARGETS luv
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
)
if (NOT BUILD_MODULE)
install(
FILES src/luv.h src/util.h src/lhandle.h src/lreq.h
DESTINATION "${INSTALL_INC_DIR}"
)
endif (NOT BUILD_MODULE)
endif (CMAKE_INSTALL_PREFIX)

202
3rdparty/luv/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

61
3rdparty/luv/Makefile vendored Normal file
View File

@ -0,0 +1,61 @@
LUV_TAG=$(shell git describe --tags)
ifdef WITHOUT_AMALG
CMAKE_OPTIONS+= -DWITH_AMALG=OFF
endif
BUILD_MODULE ?= ON
BUILD_SHARED_LIBS ?= OFF
WITH_SHARED_LIBUV ?= OFF
WITH_LUA_ENGINE ?= LuaJIT
LUA_BUILD_TYPE ?= Static
ifeq ($(WITH_LUA_ENGINE), LuaJIT)
LUABIN=build/luajit
else
LUABIN=build/lua
endif
CMAKE_OPTIONS += \
-DBUILD_MODULE=$(BUILD_MODULE) \
-DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DWITH_SHARED_LIBUV=$(WITH_SHARED_LIBUV) \
-DWITH_LUA_ENGINE=$(WITH_LUA_ENGINE) \
-DLUA_BUILD_TYPE=$(LUA_BUILD_TYPE) \
all: luv
deps/libuv/include:
git submodule update --init deps/libuv
deps/luajit/src:
git submodule update --init deps/luajit
build/Makefile: deps/libuv/include deps/luajit/src
cmake -H. -Bbuild ${CMAKE_OPTIONS} -DWITH_AMALG=OFF
luv: build/Makefile
cmake --build build --config Debug
ln -sf build/luv.so
clean:
rm -rf build luv.so
test: luv
${LUABIN} tests/run.lua
reset:
git submodule update --init --recursive && \
git clean -f -d && \
git checkout .
publish-luarocks:
rm -rf luv-${LUV_TAG}
mkdir -p luv-${LUV_TAG}/deps
cp -r src cmake CMakeLists.txt LICENSE.txt README.md docs.md luv-${LUV_TAG}/
cp -r deps/libuv deps/*.cmake deps/lua_one.c luv-${LUV_TAG}/deps/
tar -czvf luv-${LUV_TAG}.tar.gz luv-${LUV_TAG}
github-release upload --user luvit --repo luv --tag ${LUV_TAG} \
--file luv-${LUV_TAG}.tar.gz --name luv-${LUV_TAG}.tar.gz
luarocks upload luv-${LUV_TAG}.rockspec --api-key=${LUAROCKS_TOKEN}

213
3rdparty/luv/README.md vendored Normal file
View File

@ -0,0 +1,213 @@
luv
===
[![Linux Build Status](https://travis-ci.org/luvit/luv.svg?branch=master)](https://travis-ci.org/luvit/luv)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/uo1qhdcc0vcqsiok/branch/master?svg=true)](https://ci.appveyor.com/project/racker-buildbot/luv/branch/master)
[libuv](https://github.com/joyent/libuv) bindings for
[luajit](http://luajit.org/) and [lua](http://www.lua.org/)
[5.1](http://www.lua.org/manual/5.1/manual.html)/
[5.2](http://www.lua.org/manual/5.2/manual.html)/
[5.3](http://www.lua.org/manual/5.3/manual.html).
This library makes libuv available to lua scripts. It was made for the [luvit](http://luvit.io/) project but should usable from nearly any lua project.
The library can be used by multiple threads at once. Each thread is assumed to load the library from a different `lua_State`. Luv will create a unique `uv_loop_t` for each state. You can't share uv handles between states/loops.
The best docs currently are the [libuv docs](http://docs.libuv.org/) themselves. Hopfully soon we'll have a copy locally tailored for lua.
```lua
local uv = require('luv')
-- Create a handle to a uv_timer_t
local timer = uv.new_timer()
-- This will wait 1000ms and then continue inside the callback
timer:start(1000, 0, function ()
-- timer here is the value we passed in before from new_timer.
print ("Awake!")
-- You must always close your uv handles or you'll leak memory
-- We can't depend on the GC since it doesn't know enough about libuv.
timer:close()
end)
print("Sleeping");
-- uv.run will block and wait for all events to run.
-- When there are no longer any active handles, it will return
uv.run()
```
Here is an example of an TCP echo server
```lua
local uv = require('luv')
local function create_server(host, port, on_connection)
local server = uv.new_tcp()
server:bind(host, port)
server:listen(128, function(err)
-- Make sure there was no problem setting up listen
assert(not err, err)
-- Accept the client
local client = uv.new_tcp()
server:accept(client)
on_connection(client)
end)
return server
end
local server = create_server("0.0.0.0", 0, function (client)
client:read_start(function (err, chunk)
-- Crash on errors
assert(not err, err)
if chunk then
-- Echo anything heard
client:write(chunk)
else
-- When the stream ends, close the socket
client:close()
end
end)
end)
print("TCP Echo serverr listening on port " .. server:getsockname().port)
uv.run()
```
More examples can be found in the [examples](examples) and [tests](tests) folders.
## Building From Source
To build, first install your compiler tools.
### Get a Compiler
On linux this probably means `gcc` and `make`. On Ubuntu, the `build-essential`
package is good for this.
On OSX, you probably want XCode which comes with `clang` and `make` and friends.
For windows the free Visual Studio Express works. If you get the 2013 edition,
make sure to get the `Windows Deskop` edition. The `Windows` version doesn't
include a working C compiler. Make sure to run all of setup including getting a
free license.
### Install CMake
Now install Cmake. The version in `brew` on OSX or most Linux package managers
is good. The version on Travis CI is too old and so I use a PPA there. On
windows use the installer and make sure to add cmake to your command prompt
path.
### Install Git
If you haven't already, install git and make sure it's in your path. This comes
with XCode on OSX. On Linux it's in your package manager. For windows, use the
installer at <http://git-scm.com>. Make sure it's available to your windows
command prompt.
### Clone the Code
Now open a terminal and clone the code. For windows I recommend the special
developer command prompt that came with Visual Studio.
```
git clone https://github.com/luvit/luv.git --recursive
cd luv
```
### Build the Code and Test
On windows I wrote a small batch file that runs the correct cmake commands and
copies the output files for easy access.
```
C:\Code\luv> msvcbuild.bat
C:\Code\luv> luajit tests\run.lua
```
On unix systems, use the Makefile.
```
~/Code/luv> make test
```
This will build luv as a module library. Module libraries are plugins that are
not linked into other targets.
#### Build with PUC Lua 5.3
By default luv is linked with LuaJIT 2.0.4. If you rather like to link luv
with PUC Lua 5.3 you can run make with:
```
~/Code/luv> WITH_LUA_ENGINE=Lua make
```
#### Build as static library
If you want to build luv as a static library run make with:
```
~/Code/luv> BUILD_MODULE=OFF make
```
This will create a static library `libluv.a`.
#### Build as shared library
If you want to build luv as a shared library run make with:
```
~/Code/luv> BUILD_MODULE=OFF BUILD_SHARED_LIBS=ON make
```
This will create a shared library `libluv.so`.
#### Build with shared libraries
By default the build system will build luv with the supplied dependencies.
These are:
* libuv
* LuaJIT or Lua
However, if your target system has already one or more of these dependencies
installed you can link `luv` against them.
##### Linking with shared libuv
The default shared library name for libuv is `libuv`. To link against it use:
```
~/Code/luv> WITH_SHARED_LIBUV=ON make
```
##### Linking with shared LuaJIT
The default shared library name for LuaJIT is `libluajit-5.1`. To link against
it use:
```
~/Code/luv> LUA_BUILD_TYPE=System make
```
##### Linking with shared Lua 5.x
The default shared library name for Lua 5.x is `liblua5.x`. To link against
it use:
```
~/Code/luv> LUA_BUILD_TYPE=System WITH_LUA_ENGINE=Lua make
```

42
3rdparty/luv/appveyor.yml vendored Normal file
View File

@ -0,0 +1,42 @@
os: Visual Studio 2015
# Test with the latest two releases of MSVC
configuration:
- 2015
- 2013
# Test with the latest Lua and LuaJIT versions
environment:
LUAROCKS_VER: 2.3.0
matrix:
- LUA_VER: 5.3.2
NOCOMPAT: true # with compatibility flags disabled.
- LJ_VER: 2.1
platform:
- x86
- x64
matrix:
fast_finish: true
cache:
- c:\lua -> appveyor.yml
- c:\external -> appveyor.yml
install:
- git submodule update --init
build_script:
- msvcbuild.bat
- luajit.exe tests\run.lua
# Test rock installation
- call .ci\set_compiler_env.bat
- call .ci\install.bat
- luarocks make
- ps: if("$(Get-Location)" -eq $(lua -e "print(require'luv'.cwd())")) { "LuaRocks test OK" } else { "LuaRocks test failed"; exit 1 }
- luarocks remove luv
artifacts:
- path: luv.dll
- path: luajit.exe

View File

@ -0,0 +1,11 @@
# Locate libuv library
# This module defines
# LIBUV_FOUND, if false, do not try to link to libuv
# LIBUV_LIBRARIES
# LIBUV_INCLUDE_DIR, where to find uv.h
FIND_PATH(LIBUV_INCLUDE_DIR NAMES uv.h)
FIND_LIBRARY(LIBUV_LIBRARIES NAMES uv libuv)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUV DEFAULT_MSG LIBUV_LIBRARIES LIBUV_INCLUDE_DIR)

View File

@ -0,0 +1,55 @@
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
# Copyright 2013 Rolf Eike Beer <eike@sf-mail.de>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# We use code from the CMake project to detect the Lua version.
# Locate LuaJIT library
# This module defines
# LUAJIT_FOUND, if false, do not try to link to Lua JIT
# LUAJIT_LIBRARIES
# LUAJIT_INCLUDE_DIR, where to find lua.h
#
# Additionally it defines the Lua API/ABI version:
# LUA_VERSION_STRING - the version of Lua found
# LUA_VERSION_MAJOR - the major version of Lua
# LUA_VERSION_MINOR - the minor version of Lua
# LUA_VERSION_PATCH - the patch version of Lua
FIND_PATH(LUAJIT_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES luajit-2.0)
FIND_LIBRARY(LUAJIT_LIBRARIES NAMES luajit-5.1)
if (LUAJIT_INCLUDE_DIR AND EXISTS "${LUAJIT_INCLUDE_DIR}/lua.h")
# At least 5.[012] have different ways to express the version
# so all of them need to be tested. Lua 5.2 defines LUA_VERSION
# and LUA_RELEASE as joined by the C preprocessor, so avoid those.
file(STRINGS "${LUAJIT_INCLUDE_DIR}/lua.h" lua_version_strings
REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
else ()
string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
endif ()
string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
endif ()
unset(lua_version_strings)
endif()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUAJIT DEFAULT_MSG LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR)

128
3rdparty/luv/deps/lua.cmake vendored Normal file
View File

@ -0,0 +1,128 @@
# Modfied from luajit.cmake
# Added LUAJIT_ADD_EXECUTABLE Ryan Phillips <ryan at trolocsis.com>
# This CMakeLists.txt has been first taken from LuaDist
# Copyright (C) 2007-2011 LuaDist.
# Created by Peter Drahoš
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# Debugged and (now seriously) modified by Ronan Collobert, for Torch7
#project(Lua53 C)
SET(LUA_DIR ${CMAKE_CURRENT_LIST_DIR}/lua)
SET(CMAKE_REQUIRED_INCLUDES
${LUA_DIR}
${LUA_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
)
OPTION(WITH_AMALG "Build eveything in one shot (needs memory)" ON)
# Ugly warnings
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
# Various includes
INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE("void*" SIZEOF_VOID_P)
IF(SIZEOF_VOID_P EQUAL 8)
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
ENDIF()
IF(NOT WIN32)
FIND_LIBRARY(DL_LIBRARY "dl")
IF(DL_LIBRARY)
SET(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY})
LIST(APPEND LIBS ${DL_LIBRARY})
ENDIF(DL_LIBRARY)
CHECK_FUNCTION_EXISTS(dlopen LUA_USE_DLOPEN)
IF(NOT LUA_USE_DLOPEN)
MESSAGE(FATAL_ERROR "Cannot compile a useful lua.
Function dlopen() seems not to be supported on your platform.
Apparently you are not on a Windows platform as well.
So lua has no way to deal with shared libraries!")
ENDIF(NOT LUA_USE_DLOPEN)
ENDIF(NOT WIN32)
check_library_exists(m sin "" LUA_USE_LIBM)
if ( LUA_USE_LIBM )
list ( APPEND LIBS m )
endif ()
## SOURCES
SET(SRC_LUALIB
${LUA_DIR}/src/lbaselib.c
${LUA_DIR}/src/lcorolib.c
${LUA_DIR}/src/ldblib.c
${LUA_DIR}/src/liolib.c
${LUA_DIR}/src/lmathlib.c
${LUA_DIR}/src/loadlib.c
${LUA_DIR}/src/loslib.c
${LUA_DIR}/src/lstrlib.c
${LUA_DIR}/src/ltablib.c
${LUA_DIR}/src/lutf8lib.c)
SET(SRC_LUACORE
${LUA_DIR}/src/lauxlib.c
${LUA_DIR}/src/lapi.c
${LUA_DIR}/src/lcode.c
${LUA_DIR}/src/lctype.c
${LUA_DIR}/src/ldebug.c
${LUA_DIR}/src/ldo.c
${LUA_DIR}/src/ldump.c
${LUA_DIR}/src/lfunc.c
${LUA_DIR}/src/lgc.c
${LUA_DIR}/src/linit.c
${LUA_DIR}/src/llex.c
${LUA_DIR}/src/lmem.c
${LUA_DIR}/src/lobject.c
${LUA_DIR}/src/lopcodes.c
${LUA_DIR}/src/lparser.c
${LUA_DIR}/src/lstate.c
${LUA_DIR}/src/lstring.c
${LUA_DIR}/src/ltable.c
${LUA_DIR}/src/ltm.c
${LUA_DIR}/src/lundump.c
${LUA_DIR}/src/lvm.c
${LUA_DIR}/src/lzio.c
${SRC_LUALIB})
## GENERATE
IF(WITH_SHARED_LUA)
IF(WITH_AMALG)
add_library(lualib SHARED ${LUA_DIR}/../lua_one.c ${DEPS})
ELSE()
add_library(lualib SHARED ${SRC_LUACORE} ${DEPS} )
ENDIF()
ELSE()
IF(WITH_AMALG)
add_library(lualib STATIC ${LUA_DIR}/../lua_one.c ${DEPS} )
ELSE()
add_library(lualib STATIC ${SRC_LUACORE} ${DEPS} )
ENDIF()
set_target_properties(lualib PROPERTIES
PREFIX "lib" IMPORT_PREFIX "lib")
ENDIF()
target_link_libraries (lualib ${LIBS} )
set_target_properties (lualib PROPERTIES OUTPUT_NAME "lua53")
IF(WIN32)
add_executable(lua ${LUA_DIR}/src/lua.c)
target_link_libraries(lua lualib)
ELSE()
IF(WITH_AMALG)
add_executable(lua ${LUA_DIR}/src/lua.c ${LUA_DIR}/lua_one.c ${DEPS})
ELSE()
add_executable(lua ${LUA_DIR}/src/lua.c ${SRC_LUACORE} ${DEPS})
ENDIF()
target_link_libraries(lua ${LIBS})
SET_TARGET_PROPERTIES(lua PROPERTIES ENABLE_EXPORTS ON)
ENDIF(WIN32)

97
3rdparty/luv/deps/lua_one.c vendored Normal file
View File

@ -0,0 +1,97 @@
/*
* one.c -- Lua core, libraries, and interpreter in a single file
*/
/* default is to build the full interpreter */
#ifndef MAKE_LIB
#ifndef MAKE_LUAC
#ifndef MAKE_LUA
#define MAKE_LIB
#endif
#endif
#endif
/* choose suitable platform-specific features */
/* some of these may need extra libraries such as -ldl -lreadline -lncurses */
#if 0
#define LUA_USE_LINUX
#define LUA_USE_MACOSX
#define LUA_USE_POSIX
#define LUA_ANSI
#endif
/* no need to change anything below this line ----------------------------- */
/* setup for luaconf.h */
#if HAVE_LPREFIX
# include "lprefix.h"
#endif
#define LUA_CORE
#define LUA_LIB
#define ltable_c
#define lvm_c
#include "luaconf.h"
/* do not export internal symbols */
#undef LUAI_FUNC
#undef LUAI_DDEC
#undef LUAI_DDEF
#define LUAI_FUNC static
#define LUAI_DDEC static
#define LUAI_DDEF static
/* core -- used by all */
#include "lapi.c"
#include "lcode.c"
#include "lctype.c"
#include "ldebug.c"
#include "ldo.c"
#include "ldump.c"
#include "lfunc.c"
#include "lgc.c"
#include "llex.c"
#include "lmem.c"
#include "lobject.c"
#include "lopcodes.c"
#include "lparser.c"
#include "lstate.c"
#include "lstring.c"
#include "ltable.c"
#include "ltm.c"
#include "lundump.c"
#include "lvm.c"
#include "lzio.c"
/* auxiliary library -- used by all */
#include "lauxlib.c"
/* standard library -- not used by luac */
#ifndef MAKE_LUAC
#include "lbaselib.c"
#if LUA_VERSION_NUM == 502
# include "lbitlib.c"
#endif
#include "lcorolib.c"
#include "ldblib.c"
#include "liolib.c"
#include "lmathlib.c"
#include "loadlib.c"
#include "loslib.c"
#include "lstrlib.c"
#include "ltablib.c"
#if LUA_VERSION_NUM >= 503
# include "lutf8lib.c"
#endif
#include "linit.c"
#endif
/* lua */
#ifdef MAKE_LUA
#include "lua.c"
#endif
/* luac */
#ifdef MAKE_LUAC
#include "luac.c"
#endif

407
3rdparty/luv/deps/luajit.cmake vendored Normal file
View File

@ -0,0 +1,407 @@
# Added LUAJIT_ADD_EXECUTABLE Ryan Phillips <ryan at trolocsis.com>
# This CMakeLists.txt has been first taken from LuaDist
# Copyright (C) 2007-2011 LuaDist.
# Created by Peter Drahoš
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# Debugged and (now seriously) modified by Ronan Collobert, for Torch7
#project(LuaJIT C ASM)
SET(LUAJIT_DIR ${CMAKE_CURRENT_LIST_DIR}/luajit)
SET(CMAKE_REQUIRED_INCLUDES
${LUAJIT_DIR}
${LUAJIT_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
)
OPTION(WITH_AMALG "Build eveything in one shot (needs memory)" ON)
# Ugly warnings
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
# Various includes
INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckTypeSize)
# LuaJIT specific
option(LUAJIT_DISABLE_FFI "Disable FFI." OFF)
option(LUAJIT_ENABLE_LUA52COMPAT "Enable Lua 5.2 compatibility." ON)
option(LUAJIT_DISABLE_JIT "Disable JIT." OFF)
option(LUAJIT_CPU_SSE2 "Use SSE2 instead of x87 instructions." ON)
option(LUAJIT_CPU_NOCMOV "Disable NOCMOV." OFF)
MARK_AS_ADVANCED(LUAJIT_DISABLE_FFI LUAJIT_ENABLE_LUA52COMPAT LUAJIT_DISABLE_JIT LUAJIT_CPU_SSE2 LUAJIT_CPU_NOCMOV)
IF(LUAJIT_DISABLE_FFI)
ADD_DEFINITIONS(-DLUAJIT_DISABLE_FFI)
ENDIF()
IF(LUAJIT_ENABLE_LUA52COMPAT)
ADD_DEFINITIONS(-DLUAJIT_ENABLE_LUA52COMPAT)
ENDIF()
IF(LUAJIT_DISABLE_JIT)
ADD_DEFINITIONS(-DLUAJIT_DISABLE_JIT)
ENDIF()
IF(LUAJIT_CPU_SSE2)
ADD_DEFINITIONS(-DLUAJIT_CPU_SSE2)
ENDIF()
IF(LUAJIT_CPU_NOCMOV)
ADD_DEFINITIONS(-DLUAJIT_CPU_NOCMOV)
ENDIF()
######
CHECK_TYPE_SIZE("void*" SIZEOF_VOID_P)
IF(SIZEOF_VOID_P EQUAL 8)
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
ENDIF()
if ( WIN32 AND NOT CYGWIN )
add_definitions ( -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
set ( LJVM_MODE coffasm )
elseif ( APPLE )
set ( CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000 ${CMAKE_EXE_LINKER_FLAGS}" )
set ( LJVM_MODE machasm )
else ()
set ( LJVM_MODE elfasm )
endif ()
IF(NOT WIN32)
FIND_LIBRARY(DL_LIBRARY "dl")
IF(DL_LIBRARY)
SET(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY})
LIST(APPEND LIBS ${DL_LIBRARY})
ENDIF(DL_LIBRARY)
CHECK_FUNCTION_EXISTS(dlopen LUA_USE_DLOPEN)
IF(NOT LUA_USE_DLOPEN)
MESSAGE(FATAL_ERROR "Cannot compile a useful lua.
Function dlopen() seems not to be supported on your platform.
Apparently you are not on a Windows platform as well.
So lua has no way to deal with shared libraries!")
ENDIF(NOT LUA_USE_DLOPEN)
ENDIF(NOT WIN32)
check_library_exists(m sin "" LUA_USE_LIBM)
if ( LUA_USE_LIBM )
list ( APPEND LIBS m )
endif ()
## SOURCES
MACRO(LJ_TEST_ARCH stuff)
CHECK_C_SOURCE_COMPILES("
#undef ${stuff}
#include \"lj_arch.h\"
#if ${stuff}
int main() { return 0; }
#else
#error \"not defined\"
#endif
" ${stuff})
ENDMACRO()
MACRO(LJ_TEST_ARCH_VALUE stuff value)
CHECK_C_SOURCE_COMPILES("
#undef ${stuff}
#include \"lj_arch.h\"
#if ${stuff} == ${value}
int main() { return 0; }
#else
#error \"not defined\"
#endif
" ${stuff}_${value})
ENDMACRO()
FOREACH(arch X64 X86 ARM PPC PPCSPE MIPS)
LJ_TEST_ARCH(LJ_TARGET_${arch})
if(LJ_TARGET_${arch})
STRING(TOLOWER ${arch} TARGET_LJARCH)
MESSAGE(STATUS "LuaJIT Target: ${TARGET_LJARCH}")
BREAK()
ENDIF()
ENDFOREACH()
IF(NOT TARGET_LJARCH)
MESSAGE(FATAL_ERROR "architecture not supported")
ELSE()
MESSAGE(STATUS "LuaJIT target ${TARGET_LJARCH}")
ENDIF()
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/jit)
FILE(GLOB jit_files ${LUAJIT_DIR}/src/jit/*.lua)
FILE(COPY ${jit_files} DESTINATION ${CMAKE_BINARY_DIR}/jit)
SET(DASM_ARCH ${TARGET_LJARCH})
SET(DASM_FLAGS)
SET(TARGET_ARCH)
LIST(APPEND TARGET_ARCH "LUAJIT_TARGET=LUAJIT_ARCH_${TARGET_LJARCH}")
LJ_TEST_ARCH_VALUE(LJ_ARCH_BITS 64)
IF(LJ_ARCH_BITS_64)
SET(DASM_FLAGS ${DASM_FLAGS} -D P64)
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_HASJIT 1)
IF(LJ_HASJIT_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D JIT)
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_HASFFI 1)
IF(LJ_HASFFI_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D FFI)
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_DUALNUM 1)
IF(LJ_DUALNUM_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D DUALNUM)
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_ARCH_HASFPU 1)
IF(LJ_ARCH_HASFPU_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D FPU)
LIST(APPEND TARGET_ARCH "LJ_ARCH_HASFPU=1")
ELSE()
LIST(APPEND TARGET_ARCH "LJ_ARCH_HASFPU=0")
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_ABI_SOFTFP 1)
IF(NOT LJ_ABI_SOFTFP_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D HFABI)
LIST(APPEND TARGET_ARCH "LJ_ABI_SOFTFP=0")
ELSE()
LIST(APPEND TARGET_ARCH "LJ_ABI_SOFTFP=1")
ENDIF()
IF(WIN32)
SET(DASM_FLAGS ${DASM_FLAGS} -LN -D WIN)
ENDIF()
IF(TARGET_LJARCH STREQUAL "x86")
LJ_TEST_ARCH_VALUE(__SSE2__ 1)
IF(__SSE2__1)
SET(DASM_FLAGS ${DASM_FLAGS} -D SSE)
ENDIF()
ENDIF()
IF(TARGET_LJARCH STREQUAL "x64")
SET(DASM_ARCH "x86")
ENDIF()
IF(TARGET_LJARCH STREQUAL "ppc")
LJ_TEST_ARCH_VALUE(LJ_ARCH_SQRT 1)
IF(NOT LJ_ARCH_SQRT_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D SQRT)
ENDIF()
LJ_TEST_ARCH_VALUE(LJ_ARCH_PPC64 1)
IF(NOT LJ_ARCH_PPC64_1)
SET(DASM_FLAGS ${DASM_FLAGS} -D GPR64)
ENDIF()
ENDIF()
add_executable(minilua ${LUAJIT_DIR}/src/host/minilua.c)
SET_TARGET_PROPERTIES(minilua PROPERTIES COMPILE_DEFINITIONS "${TARGET_ARCH}")
CHECK_LIBRARY_EXISTS(m sin "" MINILUA_USE_LIBM)
if(MINILUA_USE_LIBM)
TARGET_LINK_LIBRARIES(minilua m)
endif()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildvm_arch.h
COMMAND minilua ${LUAJIT_DIR}/dynasm/dynasm.lua ${DASM_FLAGS} -o ${CMAKE_CURRENT_BINARY_DIR}/buildvm_arch.h ${LUAJIT_DIR}/src/vm_${DASM_ARCH}.dasc
DEPENDS ${LUAJIT_DIR}/dynasm/dynasm.lua minilua
)
SET(SRC_LJLIB
${LUAJIT_DIR}/src/lib_base.c
${LUAJIT_DIR}/src/lib_math.c
${LUAJIT_DIR}/src/lib_bit.c
${LUAJIT_DIR}/src/lib_string.c
${LUAJIT_DIR}/src/lib_table.c
${LUAJIT_DIR}/src/lib_io.c
${LUAJIT_DIR}/src/lib_os.c
${LUAJIT_DIR}/src/lib_package.c
${LUAJIT_DIR}/src/lib_debug.c
${LUAJIT_DIR}/src/lib_jit.c
${LUAJIT_DIR}/src/lib_ffi.c)
SET(SRC_LJCORE
${LUAJIT_DIR}/src/lj_gc.c
${LUAJIT_DIR}/src/lj_err.c
${LUAJIT_DIR}/src/lj_char.c
${LUAJIT_DIR}/src/lj_buf.c
${LUAJIT_DIR}/src/lj_profile.c
${LUAJIT_DIR}/src/lj_strfmt.c
${LUAJIT_DIR}/src/lj_bc.c
${LUAJIT_DIR}/src/lj_obj.c
${LUAJIT_DIR}/src/lj_str.c
${LUAJIT_DIR}/src/lj_tab.c
${LUAJIT_DIR}/src/lj_func.c
${LUAJIT_DIR}/src/lj_udata.c
${LUAJIT_DIR}/src/lj_meta.c
${LUAJIT_DIR}/src/lj_debug.c
${LUAJIT_DIR}/src/lj_state.c
${LUAJIT_DIR}/src/lj_dispatch.c
${LUAJIT_DIR}/src/lj_vmevent.c
${LUAJIT_DIR}/src/lj_vmmath.c
${LUAJIT_DIR}/src/lj_strscan.c
${LUAJIT_DIR}/src/lj_api.c
${LUAJIT_DIR}/src/lj_lex.c
${LUAJIT_DIR}/src/lj_parse.c
${LUAJIT_DIR}/src/lj_bcread.c
${LUAJIT_DIR}/src/lj_bcwrite.c
${LUAJIT_DIR}/src/lj_load.c
${LUAJIT_DIR}/src/lj_ir.c
${LUAJIT_DIR}/src/lj_opt_mem.c
${LUAJIT_DIR}/src/lj_opt_fold.c
${LUAJIT_DIR}/src/lj_opt_narrow.c
${LUAJIT_DIR}/src/lj_opt_dce.c
${LUAJIT_DIR}/src/lj_opt_loop.c
${LUAJIT_DIR}/src/lj_opt_split.c
${LUAJIT_DIR}/src/lj_opt_sink.c
${LUAJIT_DIR}/src/lj_mcode.c
${LUAJIT_DIR}/src/lj_snap.c
${LUAJIT_DIR}/src/lj_record.c
${LUAJIT_DIR}/src/lj_crecord.c
${LUAJIT_DIR}/src/lj_ffrecord.c
${LUAJIT_DIR}/src/lj_asm.c
${LUAJIT_DIR}/src/lj_trace.c
${LUAJIT_DIR}/src/lj_gdbjit.c
${LUAJIT_DIR}/src/lj_ctype.c
${LUAJIT_DIR}/src/lj_cdata.c
${LUAJIT_DIR}/src/lj_cconv.c
${LUAJIT_DIR}/src/lj_ccall.c
${LUAJIT_DIR}/src/lj_ccallback.c
${LUAJIT_DIR}/src/lj_carith.c
${LUAJIT_DIR}/src/lj_clib.c
${LUAJIT_DIR}/src/lj_cparse.c
${LUAJIT_DIR}/src/lj_lib.c
${LUAJIT_DIR}/src/lj_alloc.c
${LUAJIT_DIR}/src/lj_vmmath.c
${LUAJIT_DIR}/src/lib_aux.c
${LUAJIT_DIR}/src/lib_init.c
${SRC_LJLIB})
SET(SRC_BUILDVM
${LUAJIT_DIR}/src/host/buildvm.c
${LUAJIT_DIR}/src/host/buildvm_asm.c
${LUAJIT_DIR}/src/host/buildvm_peobj.c
${LUAJIT_DIR}/src/host/buildvm_lib.c
${LUAJIT_DIR}/src/host/buildvm_fold.c
${CMAKE_CURRENT_BINARY_DIR}/buildvm_arch.h)
## GENERATE
ADD_EXECUTABLE(buildvm ${SRC_BUILDVM})
SET_TARGET_PROPERTIES(buildvm PROPERTIES COMPILE_DEFINITIONS "${TARGET_ARCH}")
macro(add_buildvm_target _target _mode)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}
COMMAND buildvm ARGS -m ${_mode} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS buildvm ${ARGN}
)
endmacro(add_buildvm_target)
if (MSVC)
add_buildvm_target ( lj_vm.obj peobj )
set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.obj)
else ()
add_buildvm_target ( lj_vm.S ${LJVM_MODE} )
set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.S)
endif ()
add_buildvm_target ( lj_ffdef.h ffdef ${SRC_LJLIB} )
add_buildvm_target ( lj_bcdef.h bcdef ${SRC_LJLIB} )
add_buildvm_target ( lj_folddef.h folddef ${LUAJIT_DIR}/src/lj_opt_fold.c )
add_buildvm_target ( lj_recdef.h recdef ${SRC_LJLIB} )
add_buildvm_target ( lj_libdef.h libdef ${SRC_LJLIB} )
add_buildvm_target ( vmdef.lua vmdef ${SRC_LJLIB} )
SET(DEPS
${LJ_VM_SRC}
${CMAKE_CURRENT_BINARY_DIR}/lj_ffdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_bcdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_libdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_recdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_folddef.h
${CMAKE_CURRENT_BINARY_DIR}/vmdef.lua
)
## COMPILE
include_directories(
${LUAJIT_DIR}/dynasm
${LUAJIT_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
)
IF(WITH_SHARED_LUA)
IF(WITH_AMALG)
add_library(luajit-5.1 SHARED ${LUAJIT_DIR}/src/ljamalg.c ${DEPS} )
ELSE()
add_library(luajit-5.1 SHARED ${SRC_LJCORE} ${DEPS} )
ENDIF()
SET_TARGET_PROPERTIES(luajit-5.1 PROPERTIES OUTPUT_NAME "lua51")
ELSE()
IF(WITH_AMALG)
add_library(luajit-5.1 STATIC ${LUAJIT_DIR}/src/ljamalg.c ${DEPS} )
ELSE()
add_library(luajit-5.1 STATIC ${SRC_LJCORE} ${DEPS} )
ENDIF()
SET_TARGET_PROPERTIES(luajit-5.1 PROPERTIES
PREFIX "lib" IMPORT_PREFIX "lib" OUTPUT_NAME "luajit")
ENDIF()
target_link_libraries (luajit-5.1 ${LIBS} )
IF(WIN32)
add_executable(luajit ${LUAJIT_DIR}/src/luajit.c)
target_link_libraries(luajit luajit-5.1)
ELSE()
IF(WITH_AMALG)
add_executable(luajit ${LUAJIT_DIR}/src/luajit.c ${LUAJIT_DIR}/src/ljamalg.c ${DEPS})
ELSE()
add_executable(luajit ${LUAJIT_DIR}/src/luajit.c ${SRC_LJCORE} ${DEPS})
ENDIF()
target_link_libraries(luajit ${LIBS})
SET_TARGET_PROPERTIES(luajit PROPERTIES ENABLE_EXPORTS ON)
ENDIF()
MACRO(LUAJIT_add_custom_commands luajit_target)
SET(target_srcs "")
FOREACH(file ${ARGN})
IF(${file} MATCHES ".*\\.lua$")
set(file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
set(source_file ${file})
string(LENGTH ${CMAKE_SOURCE_DIR} _luajit_source_dir_length)
string(LENGTH ${file} _luajit_file_length)
math(EXPR _begin "${_luajit_source_dir_length} + 1")
math(EXPR _stripped_file_length "${_luajit_file_length} - ${_luajit_source_dir_length} - 1")
string(SUBSTRING ${file} ${_begin} ${_stripped_file_length} stripped_file)
set(generated_file "${CMAKE_BINARY_DIR}/jitted_tmp/${stripped_file}_${luajit_target}_generated${CMAKE_C_OUTPUT_EXTENSION}")
add_custom_command(
OUTPUT ${generated_file}
MAIN_DEPENDENCY ${source_file}
DEPENDS luajit
COMMAND luajit
ARGS -bg
${source_file}
${generated_file}
COMMENT "Building Luajitted ${source_file}: ${generated_file}"
)
get_filename_component(basedir ${generated_file} PATH)
file(MAKE_DIRECTORY ${basedir})
set(target_srcs ${target_srcs} ${generated_file})
set_source_files_properties(
${generated_file}
properties
external_object true # this is an object file
generated true # to say that "it is OK that the obj-files do not exist before build time"
)
ELSE()
set(target_srcs ${target_srcs} ${file})
ENDIF(${file} MATCHES ".*\\.lua$")
ENDFOREACH(file)
ENDMACRO()
MACRO(LUAJIT_ADD_EXECUTABLE luajit_target)
LUAJIT_add_custom_commands(${luajit_target} ${ARGN})
add_executable(${luajit_target} ${target_srcs})
ENDMACRO(LUAJIT_ADD_EXECUTABLE luajit_target)

224
3rdparty/luv/deps/uv.cmake vendored Normal file
View File

@ -0,0 +1,224 @@
## Modifications
## Copyright 2014 The Luvit Authors. All Rights Reserved.
## Original Copyright
# Copyright (c) 2014 David Capello
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include(CheckTypeSize)
cmake_minimum_required(VERSION 2.8.9)
set(LIBUVDIR ${CMAKE_CURRENT_LIST_DIR}/libuv)
include_directories(
${LIBUVDIR}/src
${LIBUVDIR}/include
)
set(SOURCES
${LIBUVDIR}/include/uv.h
${LIBUVDIR}/include/tree.h
${LIBUVDIR}/include/uv-errno.h
${LIBUVDIR}/include/uv-threadpool.h
${LIBUVDIR}/include/uv-version.h
${LIBUVDIR}/src/fs-poll.c
${LIBUVDIR}/src/heap-inl.h
${LIBUVDIR}/src/inet.c
${LIBUVDIR}/src/queue.h
${LIBUVDIR}/src/threadpool.c
${LIBUVDIR}/src/uv-common.c
${LIBUVDIR}/src/uv-common.h
${LIBUVDIR}/src/version.c
)
if(WIN32)
add_definitions(
-D_WIN32_WINNT=0x0600
-D_CRT_SECURE_NO_WARNINGS
-D_GNU_SOURCE
)
set(SOURCES ${SOURCES}
${LIBUVDIR}/include/uv-win.h
${LIBUVDIR}/src/win/async.c
${LIBUVDIR}/src/win/atomicops-inl.h
${LIBUVDIR}/src/win/core.c
${LIBUVDIR}/src/win/dl.c
${LIBUVDIR}/src/win/error.c
${LIBUVDIR}/src/win/fs.c
${LIBUVDIR}/src/win/fs-event.c
${LIBUVDIR}/src/win/getaddrinfo.c
${LIBUVDIR}/src/win/getnameinfo.c
${LIBUVDIR}/src/win/handle.c
${LIBUVDIR}/src/win/handle-inl.h
${LIBUVDIR}/src/win/internal.h
${LIBUVDIR}/src/win/loop-watcher.c
${LIBUVDIR}/src/win/pipe.c
${LIBUVDIR}/src/win/thread.c
${LIBUVDIR}/src/win/poll.c
${LIBUVDIR}/src/win/process.c
${LIBUVDIR}/src/win/process-stdio.c
${LIBUVDIR}/src/win/req.c
${LIBUVDIR}/src/win/req-inl.h
${LIBUVDIR}/src/win/signal.c
${LIBUVDIR}/src/win/snprintf.c
${LIBUVDIR}/src/win/stream.c
${LIBUVDIR}/src/win/stream-inl.h
${LIBUVDIR}/src/win/tcp.c
${LIBUVDIR}/src/win/tty.c
${LIBUVDIR}/src/win/timer.c
${LIBUVDIR}/src/win/udp.c
${LIBUVDIR}/src/win/util.c
${LIBUVDIR}/src/win/winapi.c
${LIBUVDIR}/src/win/winapi.h
${LIBUVDIR}/src/win/winsock.c
${LIBUVDIR}/src/win/winsock.h
)
else()
include_directories(${LIBUVDIR}/src/unix)
set(SOURCES ${SOURCES}
${LIBUVDIR}/include/uv-unix.h
${LIBUVDIR}/include/uv-linux.h
${LIBUVDIR}/include/uv-sunos.h
${LIBUVDIR}/include/uv-darwin.h
${LIBUVDIR}/include/uv-bsd.h
${LIBUVDIR}/include/uv-aix.h
${LIBUVDIR}/src/unix/async.c
${LIBUVDIR}/src/unix/atomic-ops.h
${LIBUVDIR}/src/unix/core.c
${LIBUVDIR}/src/unix/dl.c
${LIBUVDIR}/src/unix/fs.c
${LIBUVDIR}/src/unix/getaddrinfo.c
${LIBUVDIR}/src/unix/getnameinfo.c
${LIBUVDIR}/src/unix/internal.h
${LIBUVDIR}/src/unix/loop.c
${LIBUVDIR}/src/unix/loop-watcher.c
${LIBUVDIR}/src/unix/pipe.c
${LIBUVDIR}/src/unix/poll.c
${LIBUVDIR}/src/unix/process.c
${LIBUVDIR}/src/unix/signal.c
${LIBUVDIR}/src/unix/spinlock.h
${LIBUVDIR}/src/unix/stream.c
${LIBUVDIR}/src/unix/tcp.c
${LIBUVDIR}/src/unix/thread.c
${LIBUVDIR}/src/unix/timer.c
${LIBUVDIR}/src/unix/tty.c
${LIBUVDIR}/src/unix/udp.c
)
endif()
check_type_size("void*" SIZEOF_VOID_P)
if(SIZEOF_VOID_P EQUAL 8)
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
endif()
## Freebsd
if("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/kqueue.c
${LIBUVDIR}/src/unix/freebsd.c
)
endif()
## Linux
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
add_definitions(
-D_GNU_SOURCE
)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/proctitle.c
${LIBUVDIR}/src/unix/linux-core.c
${LIBUVDIR}/src/unix/linux-inotify.c
${LIBUVDIR}/src/unix/linux-syscalls.c
${LIBUVDIR}/src/unix/linux-syscalls.h
)
endif()
## SunOS
if("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
add_definitions(
-D__EXTENSIONS__
-D_XOPEN_SOURCE=500
)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/sunos.c
)
endif()
## Darwin
if(APPLE)
add_definitions(
-D=_DARWIN_USE_64_BIT_INODE
)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/proctitle.c
${LIBUVDIR}/src/unix/darwin.c
${LIBUVDIR}/src/unix/fsevents.c
${LIBUVDIR}/src/unix/darwin-proctitle.c
${LIBUVDIR}/src/unix/kqueue.c
)
endif()
add_library(uv STATIC ${SOURCES})
set_property(TARGET uv PROPERTY POSITION_INDEPENDENT_CODE ON)
if("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
target_link_libraries(uv
pthread
kvm
)
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
target_link_libraries(uv
pthread
)
endif()
if(WIN32)
target_link_libraries(uv
ws2_32.lib
shell32.lib
psapi.lib
iphlpapi.lib
advapi32.lib
Userenv.lib
)
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
target_link_libraries(uv
kstat
socket
sendfile
)
endif()
if(APPLE)
find_library(FOUNDATION_LIBRARY Foundation)
find_library(CORESERVICES_LIBRARY CoreServices)
find_library(APPLICATION_SERVICES_LIBRARY ApplicationServices)
target_link_libraries(uv
${FOUNDATION_LIBRARY}
${CORESERVICES_LIBRARY}
${APPLICATION_SERVICES_LIBRARY}
)
endif()

1309
3rdparty/luv/docs.md vendored Normal file

File diff suppressed because it is too large Load Diff

31
3rdparty/luv/examples/cqueues-main.lua vendored Normal file
View File

@ -0,0 +1,31 @@
--[[
Demonstrates using luv with a cqueues mainloop
]]
local cqueues = require "cqueues"
local uv = require "luv"
local cq = cqueues.new()
cq:wrap(function()
while cqueues.poll({
pollfd = uv.backend_fd();
timeout = uv.backend_timeout() / 1000;
events = "r";
}) do
uv.run("nowait")
end
end)
cq:wrap(function()
while true do
cqueues.sleep(1)
print("HELLO FROM CQUEUES")
end
end)
uv.new_timer():start(1000, 1000, function()
print("HELLO FROM LUV")
end)
assert(cq:loop())

55
3rdparty/luv/examples/cqueues-slave.lua vendored Normal file
View File

@ -0,0 +1,55 @@
--[[
Demonstrates using cqueues with a luv mainloop
Starts a simple sleep+print loop using each library's native form.
They should print intertwined.
]]
local cqueues = require "cqueues"
local uv = require "luv"
local cq = cqueues.new()
do
local timer = uv.new_timer()
local function reset_timer()
local timeout = cq:timeout()
if timeout then
-- libuv takes milliseconds as an integer,
-- while cqueues gives timeouts as a floating point number
-- use `math.ceil` as we'd rather wake up late than early
timer:set_repeat(math.ceil(timeout * 1000))
timer:again()
else
-- stop timer for now; it may be restarted later.
timer:stop()
end
end
local function onready()
-- Step the cqueues loop once (sleeping for max 0 seconds)
assert(cq:step(0))
reset_timer()
end
-- Need to call `start` on libuv timer now
-- to provide callback and so that `again` works
timer:start(0, 0, onready)
-- Ask libuv to watch the cqueue pollfd
uv.new_poll(cq:pollfd()):start(cq:events(), onready)
end
-- Adds a new function to the scheduler `cq`
-- The functions is an infinite loop that sleeps for 1 second and prints
cq:wrap(function()
while true do
cqueues.sleep(1)
print("HELLO FROM CQUEUES")
end
end)
-- Start a luv timer that fires every 1 second
uv.new_timer():start(1000, 1000, function()
print("HELLO FROM LUV")
end)
-- Run luv mainloop
uv.run()

View File

@ -0,0 +1,68 @@
local p = require('lib/utils').prettyPrint
local uv = require('luv')
local function create_server(host, port, on_connection)
local server = uv.new_tcp()
p(1, server)
uv.tcp_bind(server, host, port)
uv.listen(server, 128, function(err)
assert(not err, err)
local client = uv.new_tcp()
uv.accept(server, client)
on_connection(client)
end)
return server
end
local server = create_server("0.0.0.0", 0, function (client)
p("new client", client, uv.tcp_getsockname(client), uv.tcp_getpeername(client))
uv.read_start(client, function (err, chunk)
p("onread", {err=err,chunk=chunk})
-- Crash on errors
assert(not err, err)
if chunk then
-- Echo anything heard
uv.write(client, chunk)
else
-- When the stream ends, close the socket
uv.close(client)
end
end)
end)
local address = uv.tcp_getsockname(server)
p("server", server, address)
local client = uv.new_tcp()
uv.tcp_connect(client, "127.0.0.1", address.port, function (err)
assert(not err, err)
uv.read_start(client, function (err, chunk)
p("received at client", {err=err,chunk=chunk})
assert(not err, err)
if chunk then
uv.shutdown(client)
p("client done shutting down")
else
uv.close(client)
uv.close(server)
end
end)
p("writing from client")
uv.write(client, "Hello")
uv.write(client, "World")
end)
-- Start the main event loop
uv.run()
-- Close any stray handles when done
uv.walk(uv.close)
uv.run()
uv.loop_close()

View File

@ -0,0 +1,24 @@
local p = require('lib/utils').prettyPrint
local uv = require('luv')
local child, pid
child, pid = uv.spawn("sleep", {
args = {"100"}
}, function (code, signal)
p("EXIT", {code=code,signal=signal})
uv.close(child)
end)
p{child=child, pid=pid}
-- uv.kill(pid, "SIGTERM")
uv.process_kill(child, "SIGTERM")
repeat
print("\ntick.")
until uv.run('once') == 0
print("done")

49
3rdparty/luv/examples/lots-o-dns.lua vendored Normal file
View File

@ -0,0 +1,49 @@
local p = require('lib/utils').prettyPrint
local uv = require('luv')
uv.getaddrinfo(nil, 80, nil, p)
local domains = {
"facebook.com",
"google.com",
"mail.google.com",
"maps.google.com",
"plus.google.com",
"play.google.com",
"apple.com",
"hp.com",
"yahoo.com",
"mozilla.com",
"developer.mozilla.com",
"luvit.io",
"creationix.com",
"howtonode.org",
"github.com",
"gist.github.com"
}
local i = 1
local function next()
uv.getaddrinfo(domains[i], nil, {
v4mapped = true,
all = true,
addrconfig = true,
canonname = true,
numericserv = true,
socktype = "STREAM"
}, function (err, data)
assert(not err, err)
p(data)
i = i + 1
if i <= #domains then
next()
end
end)
end
next();
repeat
print("\nTick..")
until uv.run('once') == 0
print("done")

89
3rdparty/luv/examples/repl.lua vendored Normal file
View File

@ -0,0 +1,89 @@
local uv = require('luv')
local utils = require('lib/utils')
if uv.guess_handle(0) ~= "tty" or
uv.guess_handle(1) ~= "tty" then
error "stdio must be a tty"
end
local stdin = uv.new_tty(0, true)
local stdout = require('lib/utils').stdout
local debug = require('debug')
local c = utils.color
local function gatherResults(success, ...)
local n = select('#', ...)
return success, { n = n, ... }
end
local function printResults(results)
for i = 1, results.n do
results[i] = utils.dump(results[i])
end
print(table.concat(results, '\t'))
end
local buffer = ''
local function evaluateLine(line)
if line == "<3\n" then
print("I " .. c("Bred") .. "" .. c() .. " you too!")
return '>'
end
local chunk = buffer .. line
local f, err = loadstring('return ' .. chunk, 'REPL') -- first we prefix return
if not f then
f, err = loadstring(chunk, 'REPL') -- try again without return
end
if f then
buffer = ''
local success, results = gatherResults(xpcall(f, debug.traceback))
if success then
-- successful call
if results.n > 0 then
printResults(results)
end
else
-- error
print(results[1])
end
else
if err:match "'<eof>'$" then
-- Lua expects some more input; stow it away for next time
buffer = chunk .. '\n'
return '>>'
else
print(err)
buffer = ''
end
end
return '>'
end
local function displayPrompt(prompt)
uv.write(stdout, prompt .. ' ')
end
local function onread(err, line)
if err then error(err) end
if line then
local prompt = evaluateLine(line)
displayPrompt(prompt)
else
uv.close(stdin)
end
end
coroutine.wrap(function()
displayPrompt '>'
uv.read_start(stdin, onread)
end)()
uv.run()
print("")

View File

@ -0,0 +1,47 @@
local p = require('lib/utils').prettyPrint
local uv = require('luv')
local stdout = uv.new_pipe(false)
local stderr = uv.new_pipe( false)
local stdin = uv.new_pipe(false)
local handle, pid
local function onexit(code, signal)
p("exit", {code=code,signal=signal})
end
local function onclose()
p("close")
end
local function onread(err, chunk)
assert(not err, err)
if (chunk) then
p("data", {data=chunk})
else
p("end")
end
end
local function onshutdown()
uv.close(handle, onclose)
end
handle, pid = uv.spawn("cat", {
stdio = {stdin, stdout, stderr}
}, onexit)
p{
handle=handle,
pid=pid
}
uv.read_start(stdout, onread)
uv.read_start(stderr, onread)
uv.write(stdin, "Hello World")
uv.shutdown(stdin, onshutdown)
uv.run()
uv.walk(uv.close)
uv.run()

84
3rdparty/luv/examples/tcp-cluster.lua vendored Normal file
View File

@ -0,0 +1,84 @@
-- This function will be run in a child process
local child_code = string.dump(function ()
local p = require('lib/utils').prettyPrint
local uv = require('luv')
-- The parent is going to pass us the server handle over a pipe
-- This will be our local file descriptor at PIPE_FD
local pipe = uv.new_pipe(true)
local pipe_fd = tonumber(os.getenv("PIPE_FD"))
assert(uv.pipe_open(pipe, pipe_fd))
-- Configure the server handle
local server = uv.new_tcp()
local function onconnection()
local client = uv.new_tcp()
uv.accept(server, client)
p("New TCP", client, "on", server)
p{client=client}
uv.write(client, "BYE!\n");
uv.shutdown(client, function ()
uv.close(client)
uv.close(server)
end)
end
-- Read the server handle from the parent
local function onread(err, data)
p("onread", {err=err,data=data})
assert(not err, err)
if uv.pipe_pending_count(pipe) > 0 then
local pending_type = uv.pipe_pending_type(pipe)
p("pending_type", pending_type)
assert(pending_type == "tcp")
assert(uv.accept(pipe, server))
assert(uv.listen(server, 128, onconnection))
p("Received server handle from parent process", server)
elseif data then
p("ondata", data)
else
p("onend", data)
end
end
uv.read_start(pipe, onread)
-- Start the event loop!
uv.run()
end)
local p = require('lib/utils').prettyPrint
local uv = require('luv')
local exepath = assert(uv.exepath())
local cpu_count = # assert(uv.cpu_info())
local server = uv.new_tcp()
assert(uv.tcp_bind(server, "::1", 1337))
print("Master process bound to TCP port 1337 on ::1")
local function onexit(status, signal)
p("Child exited", {status=status,signal=signal})
end
local function spawnChild()
local pipe = uv.new_pipe(true)
local input = uv.new_pipe(false)
local _, pid = assert(uv.spawn(exepath, {
stdio = {input,1,2,pipe},
env= {"PIPE_FD=3"}
}, onexit))
uv.write(input, child_code)
uv.shutdown(input)
p("Spawned child", pid, "and sending handle", server)
assert(uv.write2(pipe, "123", server))
assert(uv.shutdown(pipe))
end
-- Spawn a child process for each CPU core
for _ = 1, cpu_count do
spawnChild()
end
uv.run()

68
3rdparty/luv/examples/timers.lua vendored Normal file
View File

@ -0,0 +1,68 @@
local p = require('lib/utils').prettyPrint
local uv = require('luv')
local function set_timeout(timeout, callback)
local timer = uv.new_timer()
local function ontimeout()
p("ontimeout", timer)
uv.timer_stop(timer)
uv.close(timer)
callback(timer)
end
uv.timer_start(timer, timeout, 0, ontimeout)
return timer
end
local function clear_timeout(timer)
uv.timer_stop(timer)
uv.close(timer)
end
local function set_interval(interval, callback)
local timer = uv.new_timer()
local function ontimeout()
p("interval", timer)
callback(timer)
end
uv.timer_start(timer, interval, interval, ontimeout)
return timer
end
local clear_interval = clear_timeout
local i = set_interval(300, function()
print("interval...")
end)
set_timeout(1000, function()
clear_interval(i)
end)
local handle = uv.new_timer()
local delay = 1024
local function ontimeout()
p("tick", delay)
delay = delay / 2
if delay >= 1 then
uv.timer_set_repeat(handle, delay)
uv.timer_again(handle)
else
uv.timer_stop(handle)
uv.close(handle)
p("done")
end
end
uv.timer_start(handle, delay, 0, ontimeout)
repeat
print("\ntick.")
until uv.run('once') == 0
print("done")
uv.walk(uv.close)
uv.run()
uv.loop_close()

View File

@ -0,0 +1,5 @@
local uv = require('luv')
print('Now quitting.')
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,14 @@
local uv = require('luv')
local counter = 0
local idle = uv.new_idle()
idle:start(function()
counter = counter + 1
if counter >= 10e6 then
idle:stop()
end
end)
print("Idling...")
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,30 @@
local uv = require('luv')
if #arg==0 then
print(string.format("Usage: %s <command> <file1> [file2 ...]",arg[0]));
return
end
for i=1,#arg do
local fse = uv.new_fs_event()
assert(uv.fs_event_start(fse,arg[i],{
--"watch_entry"=true,"stat"=true,
recursive=true
},function (err,fname,status)
if(err) then
print("Error "..err)
else
print(string.format('Change detected in %s',
uv.fs_event_getpath(fse)))
for k,v in pairs(status) do
print(k,v)
end
print('file changed:'..(fname and fname or ''))
end
end))
end
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,19 @@
local uv = require('luv')
local ctx = uv.new_work(
function(n) --work,in threadpool
local uv = require('luv')
local t = uv.thread_self()
uv.sleep(100)
return n*n,n
end,
function(r,n) print(string.format('%d => %d',n,r)) end --after work, in loop thread
)
uv.queue_work(ctx,2)
uv.queue_work(ctx,4)
uv.queue_work(ctx,6)
uv.queue_work(ctx,8)
uv.queue_work(ctx,10)
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,21 @@
local uv = require('luv')
local client = uv.new_tcp()
uv.tcp_connect(client, "127.0.0.1", 1337, function (err)
assert(not err, err)
uv.read_start(client, function (err, chunk)
assert(not err, err)
if chunk then
print(chunk)
else
uv.close(client)
end
end)
uv.write(client, "Hello")
uv.write(client, "World")
end)
print('CTRL-C to break')
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,22 @@
local uv = require('luv')
local server = uv.new_tcp()
server:bind("127.0.0.1", 1337)
server:listen(128, function (err)
assert(not err, err)
local client = uv.new_tcp()
server:accept(client)
client:read_start(function (err, chunk)
assert(not err, err)
if chunk then
client:write(chunk)
else
client:shutdown()
client:close()
end
end)
end)
uv.run('default')
uv.loop_close()

View File

@ -0,0 +1,38 @@
local uv = require('luv')
local step = 10
local hare_id = uv.new_thread(function(step,...)
local ffi = require'ffi'
local uv = require('luv')
local sleep
if ffi.os=='Windows' then
ffi.cdef "void Sleep(int ms);"
sleep = ffi.C.Sleep
else
ffi.cdef "unsigned int usleep(unsigned int seconds);"
sleep = ffi.C.usleep
end
while (step>0) do
step = step - 1
uv.sleep(math.random(1000))
print("Hare ran another step")
end
print("Hare done running!")
end, step,true,'abcd','false')
local tortoise_id = uv.new_thread(function(step,...)
local uv = require('luv')
while (step>0) do
step = step - 1
uv.sleep(math.random(100))
print("Tortoise ran another step")
end
print("Tortoise done running!")
end,step,'abcd','false')
print(hare_id==hare_id,uv.thread_equal(hare_id,hare_id))
print(tortoise_id==hare_id,uv.thread_equal(tortoise_id,hare_id))
uv.thread_join(hare_id)
uv.thread_join(tortoise_id)

37
3rdparty/luv/examples/uvbook/uvcat.lua vendored Normal file
View File

@ -0,0 +1,37 @@
local uv = require('luv')
local fname = arg[1] and arg[1] or arg[0]
uv.fs_open(fname, 'r', tonumber('644', 8), function(err,fd)
if err then
print("error opening file:"..err)
else
local stat = uv.fs_fstat(fd)
local off = 0
local block = 10
local function on_read(err,chunk)
if(err) then
print("Read error: "..err);
elseif #chunk==0 then
uv.fs_close(fd)
else
off = block + off
uv.fs_write(1,chunk,-1,function(err,chunk)
if err then
print("Write error: "..err)
else
uv.fs_read(fd, block, off, on_read)
end
end)
end
end
uv.fs_read(fd, block, off, on_read)
end
end)
uv.run('default')
uv.loop_close()

35
3rdparty/luv/examples/uvbook/uvtee.lua vendored Normal file
View File

@ -0,0 +1,35 @@
local uv = require('luv')
if not arg[1] then
print(string.format("please run %s filename",arg[0]))
return
end
local stdin = uv.new_tty(0, true)
local stdout = uv.new_tty(1, true)
--local stdin_pipe = uv.new_pipe(false)
--uv.pipe_open(stdin_pipe,0)
local fname = arg[1]
uv.fs_open(fname, 'w+', tonumber('644', 8), function(err,fd)
if err then
print("error opening file:"..err)
else
local fpipe = uv.new_pipe(false)
uv.pipe_open(fpipe, fd)
uv.read_start(stdin, function(err,chunk)
if err then
print('Read error: '..err)
else
uv.write(stdout,chunk)
uv.write(fpipe,chunk)
end
end);
end
end)
uv.run('default')
uv.loop_close()

165
3rdparty/luv/lib/tap.lua vendored Normal file
View File

@ -0,0 +1,165 @@
local uv = require('luv')
local dump = require('lib/utils').dump
local stdout = require('lib/utils').stdout
local function protect(...)
local n = select('#', ...)
local arguments = {...}
for i = 1, n do
arguments[i] = tostring(arguments[i])
end
local text = table.concat(arguments, "\t")
text = " " .. string.gsub(text, "\n", "\n ")
print(text)
end
local function pprotect(...)
local n = select('#', ...)
local arguments = { ... }
for i = 1, n do
arguments[i] = dump(arguments[i])
end
protect(table.concat(arguments, "\t"))
end
local tests = {};
local function run()
local passed = 0
if #tests < 1 then
error("No tests specified!")
end
print("1.." .. #tests)
for i = 1, #tests do
local test = tests[i]
local cwd = uv.cwd()
local pass, err = xpcall(function ()
local expected = 0
local function expect(fn, count)
expected = expected + (count or 1)
return function (...)
expected = expected - 1
local ret = fn(...)
collectgarbage()
return ret
end
end
test.fn(protect, pprotect, expect, uv)
collectgarbage()
uv.run()
collectgarbage()
if expected > 0 then
error("Missing " .. expected .. " expected call" .. (expected == 1 and "" or "s"))
elseif expected < 0 then
error("Found " .. -expected .. " unexpected call" .. (expected == -1 and "" or "s"))
end
collectgarbage()
local unclosed = 0
uv.walk(function (handle)
if handle == stdout then return end
unclosed = unclosed + 1
print("UNCLOSED", handle)
end)
if unclosed > 0 then
error(unclosed .. " unclosed handle" .. (unclosed == 1 and "" or "s"))
end
if uv.cwd() ~= cwd then
error("Test moved cwd from " .. cwd .. " to " .. uv.cwd())
end
collectgarbage()
end, debug.traceback)
-- Flush out any more opened handles
uv.stop()
uv.walk(function (handle)
if handle == stdout then return end
if not uv.is_closing(handle) then uv.close(handle) end
end)
uv.run()
uv.chdir(cwd)
if pass then
print("ok " .. i .. " " .. test.name)
passed = passed + 1
else
protect(err)
print("not ok " .. i .. " " .. test.name)
end
end
local failed = #tests - passed
if failed == 0 then
print("# All tests passed")
else
print("#" .. failed .. " failed test" .. (failed == 1 and "" or "s"))
end
-- Close all then handles, including stdout
uv.walk(uv.close)
uv.run()
os.exit(-failed)
end
local single = true
local prefix
local function tap(suite)
if type(suite) == "function" then
-- Pass in suite directly for single mode
suite(function (name, fn)
if prefix then
name = prefix .. ' - ' .. name
end
tests[#tests + 1] = {
name = name,
fn = fn
}
end)
prefix = nil
elseif type(suite) == "string" then
prefix = suite
single = false
else
-- Or pass in false to collect several runs of tests
-- And then pass in true in a later call to flush tests queue.
single = suite
end
if single then run() end
end
--[[
-- Sample Usage
local passed, failed, total = tap(function (test)
test("add 1 to 2", function(print)
print("Adding 1 to 2")
assert(1 + 2 == 3)
end)
test("close handle", function (print, p, expect, uv)
local handle = uv.new_timer()
uv.close(handle, expect(function (self)
assert(self == handle)
end))
end)
test("simulate failure", function ()
error("Oopsie!")
end)
end)
]]
return tap

165
3rdparty/luv/lib/utils.lua vendored Normal file
View File

@ -0,0 +1,165 @@
local uv = require('luv')
local utils = {}
local usecolors
if uv.guess_handle(1) == "tty" then
utils.stdout = uv.new_tty(1, false)
usecolors = true
else
utils.stdout = uv.new_pipe(false)
uv.pipe_open(utils.stdout, 1)
usecolors = false
end
local colors = {
black = "0;30",
red = "0;31",
green = "0;32",
yellow = "0;33",
blue = "0;34",
magenta = "0;35",
cyan = "0;36",
white = "0;37",
B = "1;",
Bblack = "1;30",
Bred = "1;31",
Bgreen = "1;32",
Byellow = "1;33",
Bblue = "1;34",
Bmagenta = "1;35",
Bcyan = "1;36",
Bwhite = "1;37"
}
function utils.color(color_name)
if usecolors then
return "\27[" .. (colors[color_name] or "0") .. "m"
else
return ""
end
end
function utils.colorize(color_name, string, reset_name)
return utils.color(color_name) .. tostring(string) .. utils.color(reset_name)
end
local backslash, null, newline, carriage, tab, quote, quote2, obracket, cbracket
function utils.loadColors(n)
if n ~= nil then usecolors = n end
backslash = utils.colorize("Bgreen", "\\\\", "green")
null = utils.colorize("Bgreen", "\\0", "green")
newline = utils.colorize("Bgreen", "\\n", "green")
carriage = utils.colorize("Bgreen", "\\r", "green")
tab = utils.colorize("Bgreen", "\\t", "green")
quote = utils.colorize("Bgreen", '"', "green")
quote2 = utils.colorize("Bgreen", '"')
obracket = utils.colorize("B", '[')
cbracket = utils.colorize("B", ']')
end
utils.loadColors()
function utils.dump(o, depth)
local t = type(o)
if t == 'string' then
return quote .. o:gsub("\\", backslash):gsub("%z", null):gsub("\n", newline):gsub("\r", carriage):gsub("\t", tab) .. quote2
end
if t == 'nil' then
return utils.colorize("Bblack", "nil")
end
if t == 'boolean' then
return utils.colorize("yellow", tostring(o))
end
if t == 'number' then
return utils.colorize("blue", tostring(o))
end
if t == 'userdata' then
return utils.colorize("magenta", tostring(o))
end
if t == 'thread' then
return utils.colorize("Bred", tostring(o))
end
if t == 'function' then
return utils.colorize("cyan", tostring(o))
end
if t == 'cdata' then
return utils.colorize("Bmagenta", tostring(o))
end
if t == 'table' then
if type(depth) == 'nil' then
depth = 0
end
if depth > 1 then
return utils.colorize("yellow", tostring(o))
end
local indent = (" "):rep(depth)
-- Check to see if this is an array
local is_array = true
local i = 1
for k,v in pairs(o) do
if not (k == i) then
is_array = false
end
i = i + 1
end
local first = true
local lines = {}
i = 1
local estimated = 0
for k,v in (is_array and ipairs or pairs)(o) do
local s
if is_array then
s = ""
else
if type(k) == "string" and k:find("^[%a_][%a%d_]*$") then
s = k .. ' = '
else
s = '[' .. utils.dump(k, 100) .. '] = '
end
end
s = s .. utils.dump(v, depth + 1)
lines[i] = s
estimated = estimated + #s
i = i + 1
end
if estimated > 200 then
return "{\n " .. indent .. table.concat(lines, ",\n " .. indent) .. "\n" .. indent .. "}"
else
return "{ " .. table.concat(lines, ", ") .. " }"
end
end
-- This doesn't happen right?
return tostring(o)
end
-- Print replacement that goes through libuv. This is useful on windows
-- to use libuv's code to translate ansi escape codes to windows API calls.
function print(...)
local n = select('#', ...)
local arguments = {...}
for i = 1, n do
arguments[i] = tostring(arguments[i])
end
uv.write(utils.stdout, table.concat(arguments, "\t") .. "\n")
end
-- A nice global data dumper
function utils.prettyPrint(...)
local n = select('#', ...)
local arguments = { ... }
for i = 1, n do
arguments[i] = utils.dump(arguments[i])
end
print(table.concat(arguments, "\t"))
end
return utils

34
3rdparty/luv/luv-1.8.0-4.rockspec vendored Normal file
View File

@ -0,0 +1,34 @@
package = "luv"
version = "1.8.0-4"
source = {
url = 'https://github.com/luvit/luv/releases/download/1.8.0-4/luv-1.8.0-4.tar.gz',
}
description = {
summary = "Bare libuv bindings for lua",
detailed = [[
libuv bindings for luajit and lua 5.1/5.2/5.3.
This library makes libuv available to lua scripts. It was made for the luvit
project but should usable from nearly any lua project.
]],
homepage = "https://github.com/luvit/luv",
license = "Apache 2.0"
}
dependencies = {
"lua >= 5.1"
}
build = {
type = 'cmake',
variables = {
CMAKE_C_FLAGS="$(CFLAGS)",
CMAKE_MODULE_LINKER_FLAGS="$(LIBFLAG)",
LUA_LIBDIR="$(LUA_LIBDIR)",
LUA_INCDIR="$(LUA_INCDIR)",
LUA="$(LUA)",
LIBDIR="$(LIBDIR)",
LUADIR="$(LUADIR)",
},
}

13
3rdparty/luv/msvcbuild.bat vendored Normal file
View File

@ -0,0 +1,13 @@
@echo off
set VS=12
if "%configuration%"=="2015" (set VS=14)
if "%configuration%"=="2013" (set VS=12)
if not defined platform set platform=x64
if "%platform%" EQU "x64" (set VS=%VS% Win64)
cmake -H. -Bbuild -G"Visual Studio %VS%"
cmake --build build --config Release
copy build\Release\luv.dll .
copy build\Release\luajit.exe .

63
3rdparty/luv/src/async.c vendored Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
#include "lthreadpool.h"
static uv_async_t* luv_check_async(lua_State* L, int index) {
uv_async_t* handle = luv_checkudata(L, index, "uv_async");
luaL_argcheck(L, handle->type == UV_ASYNC && handle->data, index, "Expected uv_async_t");
return handle;
}
static void luv_async_cb(uv_async_t* handle) {
lua_State* L = luv_state(handle->loop);
luv_handle_t* data = handle->data;
int n = luv_thread_arg_push(L, data->extra);
luv_call_callback(L, data, LUV_ASYNC, n);
luv_thread_arg_clear(data->extra);
}
static int luv_new_async(lua_State* L) {
uv_async_t* handle;
luv_handle_t* data;
int ret;
luaL_checktype(L, 1, LUA_TFUNCTION);
handle = luv_newuserdata(L, sizeof(*handle));
ret = uv_async_init(luv_loop(L), handle, luv_async_cb);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
data = luv_setup_handle(L);
data->extra = malloc(sizeof(luv_thread_arg_t));
memset(data->extra, 0, sizeof(luv_thread_arg_t));
handle->data = data;
luv_check_callback(L, handle->data, LUV_ASYNC, 1);
return 1;
}
static int luv_async_send(lua_State* L) {
int ret;
uv_async_t* handle = luv_check_async(L, 1);
luv_thread_arg_t* arg = ((luv_handle_t*) handle->data)->extra;
luv_thread_arg_set(L, arg, 2, lua_gettop(L), 0);
ret = uv_async_send(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}

59
3rdparty/luv/src/check.c vendored Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static uv_check_t* luv_check_check(lua_State* L, int index) {
uv_check_t* handle = luv_checkudata(L, index, "uv_check");
luaL_argcheck(L, handle->type == UV_CHECK && handle->data, index, "Expected uv_check_t");
return handle;
}
static int luv_new_check(lua_State* L) {
uv_check_t* handle = luv_newuserdata(L, sizeof(*handle));
int ret = uv_check_init(luv_loop(L), handle);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
handle->data = luv_setup_handle(L);
return 1;
}
static void luv_check_cb(uv_check_t* handle) {
lua_State* L = luv_state(handle->loop);
luv_handle_t* data = handle->data;
luv_call_callback(L, data, LUV_CHECK, 0);
}
static int luv_check_start(lua_State* L) {
uv_check_t* handle = luv_check_check(L, 1);
int ret;
luv_check_callback(L, handle->data, LUV_CHECK, 2);
ret = uv_check_start(handle, luv_check_cb);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_check_stop(lua_State* L) {
uv_check_t* handle = luv_check_check(L, 1);
int ret = uv_check_stop(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}

649
3rdparty/luv/src/constants.c vendored Normal file
View File

@ -0,0 +1,649 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static int luv_constants(lua_State* L) {
lua_newtable(L);
// File open bitwise flags O_*
#ifdef O_RDONLY
lua_pushinteger(L, O_RDONLY);
lua_setfield(L, -2, "O_RDONLY");
#endif
#ifdef O_WRONLY
lua_pushinteger(L, O_WRONLY);
lua_setfield(L, -2, "O_WRONLY");
#endif
#ifdef O_RDWR
lua_pushinteger(L, O_RDWR);
lua_setfield(L, -2, "O_RDWR");
#endif
#ifdef O_APPEND
lua_pushinteger(L, O_APPEND);
lua_setfield(L, -2, "O_APPEND");
#endif
#ifdef O_CREAT
lua_pushinteger(L, O_CREAT);
lua_setfield(L, -2, "O_CREAT");
#endif
#ifdef O_DSYNC
lua_pushinteger(L, O_DSYNC);
lua_setfield(L, -2, "O_DSYNC");
#endif
#ifdef O_EXCL
lua_pushinteger(L, O_EXCL);
lua_setfield(L, -2, "O_EXCL");
#endif
#ifdef O_EXLOCK
lua_pushinteger(L, O_EXLOCK);
lua_setfield(L, -2, "O_EXLOCK");
#endif
#ifdef O_NOCTTY
lua_pushinteger(L, O_NOCTTY);
lua_setfield(L, -2, "O_NOCTTY");
#endif
#ifdef O_NONBLOCK
lua_pushinteger(L, O_NONBLOCK);
lua_setfield(L, -2, "O_NONBLOCK");
#endif
#ifdef O_RSYNC
lua_pushinteger(L, O_RSYNC);
lua_setfield(L, -2, "O_RSYNC");
#endif
#ifdef O_SYNC
lua_pushinteger(L, O_SYNC);
lua_setfield(L, -2, "O_SYNC");
#endif
#ifdef O_TRUNC
lua_pushinteger(L, O_TRUNC);
lua_setfield(L, -2, "O_TRUNC");
#endif
// Socket types SOCK_*
#ifdef SOCK_STREAM
lua_pushinteger(L, SOCK_STREAM);
lua_setfield(L, -2, "SOCK_STREAM");
#endif
#ifdef SOCK_DGRAM
lua_pushinteger(L, SOCK_DGRAM);
lua_setfield(L, -2, "SOCK_DGRAM");
#endif
#ifdef SOCK_SEQPACKET
lua_pushinteger(L, SOCK_SEQPACKET);
lua_setfield(L, -2, "SOCK_SEQPACKET");
#endif
#ifdef SOCK_RAW
lua_pushinteger(L, SOCK_RAW);
lua_setfield(L, -2, "SOCK_RAW");
#endif
#ifdef SOCK_RDM
lua_pushinteger(L, SOCK_RDM);
lua_setfield(L, -2, "SOCK_RDM");
#endif
// AF_*
#ifdef AF_UNIX
lua_pushinteger(L, AF_UNIX);
lua_setfield(L, -2, "AF_UNIX");
#endif
#ifdef AF_INET
lua_pushinteger(L, AF_INET);
lua_setfield(L, -2, "AF_INET");
#endif
#ifdef AF_INET6
lua_pushinteger(L, AF_INET6);
lua_setfield(L, -2, "AF_INET6");
#endif
#ifdef AF_IPX
lua_pushinteger(L, AF_IPX);
lua_setfield(L, -2, "AF_IPX");
#endif
#ifdef AF_NETLINK
lua_pushinteger(L, AF_NETLINK);
lua_setfield(L, -2, "AF_NETLINK");
#endif
#ifdef AF_X25
lua_pushinteger(L, AF_X25);
lua_setfield(L, -2, "AF_X25");
#endif
#ifdef AF_AX25
lua_pushinteger(L, AF_AX25);
lua_setfield(L, -2, "AF_AX25");
#endif
#ifdef AF_ATMPVC
lua_pushinteger(L, AF_ATMPVC);
lua_setfield(L, -2, "AF_ATMPVC");
#endif
#ifdef AF_APPLETALK
lua_pushinteger(L, AF_APPLETALK);
lua_setfield(L, -2, "AF_APPLETALK");
#endif
#ifdef AF_PACKET
lua_pushinteger(L, AF_PACKET);
lua_setfield(L, -2, "AF_PACKET");
#endif
// AI_*
#ifdef AI_ADDRCONFIG
lua_pushinteger(L, AI_ADDRCONFIG);
lua_setfield(L, -2, "AI_ADDRCONFIG");
#endif
#ifdef AI_V4MAPPED
lua_pushinteger(L, AI_V4MAPPED);
lua_setfield(L, -2, "AI_V4MAPPED");
#endif
#ifdef AI_ALL
lua_pushinteger(L, AI_ALL);
lua_setfield(L, -2, "AI_ALL");
#endif
#ifdef AI_NUMERICHOST
lua_pushinteger(L, AI_NUMERICHOST);
lua_setfield(L, -2, "AI_NUMERICHOST");
#endif
#ifdef AI_PASSIVE
lua_pushinteger(L, AI_PASSIVE);
lua_setfield(L, -2, "AI_PASSIVE");
#endif
#ifdef AI_NUMERICSERV
lua_pushinteger(L, AI_NUMERICSERV);
lua_setfield(L, -2, "AI_NUMERICSERV");
#endif
// Signals
#ifdef SIGHUP
lua_pushinteger(L, SIGHUP);
lua_setfield(L, -2, "SIGHUP");
#endif
#ifdef SIGINT
lua_pushinteger(L, SIGINT);
lua_setfield(L, -2, "SIGINT");
#endif
#ifdef SIGQUIT
lua_pushinteger(L, SIGQUIT);
lua_setfield(L, -2, "SIGQUIT");
#endif
#ifdef SIGILL
lua_pushinteger(L, SIGILL);
lua_setfield(L, -2, "SIGILL");
#endif
#ifdef SIGTRAP
lua_pushinteger(L, SIGTRAP);
lua_setfield(L, -2, "SIGTRAP");
#endif
#ifdef SIGABRT
lua_pushinteger(L, SIGABRT);
lua_setfield(L, -2, "SIGABRT");
#endif
#ifdef SIGIOT
lua_pushinteger(L, SIGIOT);
lua_setfield(L, -2, "SIGIOT");
#endif
#ifdef SIGBUS
lua_pushinteger(L, SIGBUS);
lua_setfield(L, -2, "SIGBUS");
#endif
#ifdef SIGFPE
lua_pushinteger(L, SIGFPE);
lua_setfield(L, -2, "SIGFPE");
#endif
#ifdef SIGKILL
lua_pushinteger(L, SIGKILL);
lua_setfield(L, -2, "SIGKILL");
#endif
#ifdef SIGUSR1
lua_pushinteger(L, SIGUSR1);
lua_setfield(L, -2, "SIGUSR1");
#endif
#ifdef SIGSEGV
lua_pushinteger(L, SIGSEGV);
lua_setfield(L, -2, "SIGSEGV");
#endif
#ifdef SIGUSR2
lua_pushinteger(L, SIGUSR2);
lua_setfield(L, -2, "SIGUSR2");
#endif
#ifdef SIGPIPE
lua_pushinteger(L, SIGPIPE);
lua_setfield(L, -2, "SIGPIPE");
#endif
#ifdef SIGALRM
lua_pushinteger(L, SIGALRM);
lua_setfield(L, -2, "SIGALRM");
#endif
#ifdef SIGTERM
lua_pushinteger(L, SIGTERM);
lua_setfield(L, -2, "SIGTERM");
#endif
#ifdef SIGCHLD
lua_pushinteger(L, SIGCHLD);
lua_setfield(L, -2, "SIGCHLD");
#endif
#ifdef SIGSTKFLT
lua_pushinteger(L, SIGSTKFLT);
lua_setfield(L, -2, "SIGSTKFLT");
#endif
#ifdef SIGCONT
lua_pushinteger(L, SIGCONT);
lua_setfield(L, -2, "SIGCONT");
#endif
#ifdef SIGSTOP
lua_pushinteger(L, SIGSTOP);
lua_setfield(L, -2, "SIGSTOP");
#endif
#ifdef SIGTSTP
lua_pushinteger(L, SIGTSTP);
lua_setfield(L, -2, "SIGTSTP");
#endif
#ifdef SIGBREAK
lua_pushinteger(L, SIGBREAK);
lua_setfield(L, -2, "SIGBREAK");
#endif
#ifdef SIGTTIN
lua_pushinteger(L, SIGTTIN);
lua_setfield(L, -2, "SIGTTIN");
#endif
#ifdef SIGTTOU
lua_pushinteger(L, SIGTTOU);
lua_setfield(L, -2, "SIGTTOU");
#endif
#ifdef SIGURG
lua_pushinteger(L, SIGURG);
lua_setfield(L, -2, "SIGURG");
#endif
#ifdef SIGXCPU
lua_pushinteger(L, SIGXCPU);
lua_setfield(L, -2, "SIGXCPU");
#endif
#ifdef SIGXFSZ
lua_pushinteger(L, SIGXFSZ);
lua_setfield(L, -2, "SIGXFSZ");
#endif
#ifdef SIGVTALRM
lua_pushinteger(L, SIGVTALRM);
lua_setfield(L, -2, "SIGVTALRM");
#endif
#ifdef SIGPROF
lua_pushinteger(L, SIGPROF);
lua_setfield(L, -2, "SIGPROF");
#endif
#ifdef SIGWINCH
lua_pushinteger(L, SIGWINCH);
lua_setfield(L, -2, "SIGWINCH");
#endif
#ifdef SIGIO
lua_pushinteger(L, SIGIO);
lua_setfield(L, -2, "SIGIO");
#endif
#ifdef SIGPOLL
lua_pushinteger(L, SIGPOLL);
lua_setfield(L, -2, "SIGPOLL");
#endif
#ifdef SIGLOST
lua_pushinteger(L, SIGLOST);
lua_setfield(L, -2, "SIGLOST");
#endif
#ifdef SIGPWR
lua_pushinteger(L, SIGPWR);
lua_setfield(L, -2, "SIGPWR");
#endif
#ifdef SIGSYS
lua_pushinteger(L, SIGSYS);
lua_setfield(L, -2, "SIGSYS");
#endif
return 1;
}
static int luv_af_string_to_num(const char* string) {
if (!string) return AF_UNSPEC;
#ifdef AF_UNIX
if (strcmp(string, "unix") == 0) return AF_UNIX;
#endif
#ifdef AF_INET
if (strcmp(string, "inet") == 0) return AF_INET;
#endif
#ifdef AF_INET6
if (strcmp(string, "inet6") == 0) return AF_INET6;
#endif
#ifdef AF_IPX
if (strcmp(string, "ipx") == 0) return AF_IPX;
#endif
#ifdef AF_NETLINK
if (strcmp(string, "netlink") == 0) return AF_NETLINK;
#endif
#ifdef AF_X25
if (strcmp(string, "x25") == 0) return AF_X25;
#endif
#ifdef AF_AX25
if (strcmp(string, "ax25") == 0) return AF_AX25;
#endif
#ifdef AF_ATMPVC
if (strcmp(string, "atmpvc") == 0) return AF_ATMPVC;
#endif
#ifdef AF_APPLETALK
if (strcmp(string, "appletalk") == 0) return AF_APPLETALK;
#endif
#ifdef AF_PACKET
if (strcmp(string, "packet") == 0) return AF_PACKET;
#endif
return 0;
}
static const char* luv_af_num_to_string(const int num) {
switch (num) {
#ifdef AF_UNIX
case AF_UNIX: return "unix";
#endif
#ifdef AF_INET
case AF_INET: return "inet";
#endif
#ifdef AF_INET6
case AF_INET6: return "inet6";
#endif
#ifdef AF_IPX
case AF_IPX: return "ipx";
#endif
#ifdef AF_NETLINK
case AF_NETLINK: return "netlink";
#endif
#ifdef AF_X25
case AF_X25: return "x25";
#endif
#ifdef AF_AX25
case AF_AX25: return "ax25";
#endif
#ifdef AF_ATMPVC
case AF_ATMPVC: return "atmpvc";
#endif
#ifdef AF_APPLETALK
case AF_APPLETALK: return "appletalk";
#endif
#ifdef AF_PACKET
case AF_PACKET: return "packet";
#endif
}
return NULL;
}
static int luv_sock_string_to_num(const char* string) {
if (!string) return 0;
#ifdef SOCK_STREAM
if (strcmp(string, "stream") == 0) return SOCK_STREAM;
#endif
#ifdef SOCK_DGRAM
if (strcmp(string, "dgram") == 0) return SOCK_DGRAM;
#endif
#ifdef SOCK_SEQPACKET
if (strcmp(string, "seqpacket") == 0) return SOCK_SEQPACKET;
#endif
#ifdef SOCK_RAW
if (strcmp(string, "raw") == 0) return SOCK_RAW;
#endif
#ifdef SOCK_RDM
if (strcmp(string, "rdm") == 0) return SOCK_RDM;
#endif
return 0;
}
static const char* luv_sock_num_to_string(const int num) {
switch (num) {
#ifdef SOCK_STREAM
case SOCK_STREAM: return "stream";
#endif
#ifdef SOCK_DGRAM
case SOCK_DGRAM: return "dgram";
#endif
#ifdef SOCK_SEQPACKET
case SOCK_SEQPACKET: return "seqpacket";
#endif
#ifdef SOCK_RAW
case SOCK_RAW: return "raw";
#endif
#ifdef SOCK_RDM
case SOCK_RDM: return "rdm";
#endif
}
return NULL;
}
static int luv_sig_string_to_num(const char* string) {
if (!string) return 0;
#ifdef SIGHUP
if (strcmp(string, "sighup") == 0) return SIGHUP;
#endif
#ifdef SIGINT
if (strcmp(string, "sigint") == 0) return SIGINT;
#endif
#ifdef SIGQUIT
if (strcmp(string, "sigquit") == 0) return SIGQUIT;
#endif
#ifdef SIGILL
if (strcmp(string, "sigill") == 0) return SIGILL;
#endif
#ifdef SIGTRAP
if (strcmp(string, "sigtrap") == 0) return SIGTRAP;
#endif
#ifdef SIGABRT
if (strcmp(string, "sigabrt") == 0) return SIGABRT;
#endif
#ifdef SIGIOT
if (strcmp(string, "sigiot") == 0) return SIGIOT;
#endif
#ifdef SIGBUS
if (strcmp(string, "sigbus") == 0) return SIGBUS;
#endif
#ifdef SIGFPE
if (strcmp(string, "sigfpe") == 0) return SIGFPE;
#endif
#ifdef SIGKILL
if (strcmp(string, "sigkill") == 0) return SIGKILL;
#endif
#ifdef SIGUSR1
if (strcmp(string, "sigusr1") == 0) return SIGUSR1;
#endif
#ifdef SIGSEGV
if (strcmp(string, "sigsegv") == 0) return SIGSEGV;
#endif
#ifdef SIGUSR2
if (strcmp(string, "sigusr2") == 0) return SIGUSR2;
#endif
#ifdef SIGPIPE
if (strcmp(string, "sigpipe") == 0) return SIGPIPE;
#endif
#ifdef SIGALRM
if (strcmp(string, "sigalrm") == 0) return SIGALRM;
#endif
#ifdef SIGTERM
if (strcmp(string, "sigterm") == 0) return SIGTERM;
#endif
#ifdef SIGCHLD
if (strcmp(string, "sigchld") == 0) return SIGCHLD;
#endif
#ifdef SIGSTKFLT
if (strcmp(string, "sigstkflt") == 0) return SIGSTKFLT;
#endif
#ifdef SIGCONT
if (strcmp(string, "sigcont") == 0) return SIGCONT;
#endif
#ifdef SIGSTOP
if (strcmp(string, "sigstop") == 0) return SIGSTOP;
#endif
#ifdef SIGTSTP
if (strcmp(string, "sigtstp") == 0) return SIGTSTP;
#endif
#ifdef SIGBREAK
if (strcmp(string, "sigbreak") == 0) return SIGBREAK;
#endif
#ifdef SIGTTIN
if (strcmp(string, "sigttin") == 0) return SIGTTIN;
#endif
#ifdef SIGTTOU
if (strcmp(string, "sigttou") == 0) return SIGTTOU;
#endif
#ifdef SIGURG
if (strcmp(string, "sigurg") == 0) return SIGURG;
#endif
#ifdef SIGXCPU
if (strcmp(string, "sigxcpu") == 0) return SIGXCPU;
#endif
#ifdef SIGXFSZ
if (strcmp(string, "sigxfsz") == 0) return SIGXFSZ;
#endif
#ifdef SIGVTALRM
if (strcmp(string, "sigvtalrm") == 0) return SIGVTALRM;
#endif
#ifdef SIGPROF
if (strcmp(string, "sigprof") == 0) return SIGPROF;
#endif
#ifdef SIGWINCH
if (strcmp(string, "sigwinch") == 0) return SIGWINCH;
#endif
#ifdef SIGIO
if (strcmp(string, "sigio") == 0) return SIGIO;
#endif
#ifdef SIGPOLL
if (strcmp(string, "sigpoll") == 0) return SIGPOLL;
#endif
#ifdef SIGLOST
if (strcmp(string, "siglost") == 0) return SIGLOST;
#endif
#ifdef SIGPWR
if (strcmp(string, "sigpwr") == 0) return SIGPWR;
#endif
#ifdef SIGSYS
if (strcmp(string, "sigsys") == 0) return SIGSYS;
#endif
return 0;
}
static const char* luv_sig_num_to_string(const int num) {
switch (num) {
#ifdef SIGHUP
case SIGHUP: return "sighup";
#endif
#ifdef SIGINT
case SIGINT: return "sigint";
#endif
#ifdef SIGQUIT
case SIGQUIT: return "sigquit";
#endif
#ifdef SIGILL
case SIGILL: return "sigill";
#endif
#ifdef SIGTRAP
case SIGTRAP: return "sigtrap";
#endif
#ifdef SIGABRT
case SIGABRT: return "sigabrt";
#endif
#ifdef SIGIOT
# if SIGIOT != SIGABRT
case SIGIOT: return "sigiot";
# endif
#endif
#ifdef SIGBUS
case SIGBUS: return "sigbus";
#endif
#ifdef SIGFPE
case SIGFPE: return "sigfpe";
#endif
#ifdef SIGKILL
case SIGKILL: return "sigkill";
#endif
#ifdef SIGUSR1
case SIGUSR1: return "sigusr1";
#endif
#ifdef SIGSEGV
case SIGSEGV: return "sigsegv";
#endif
#ifdef SIGUSR2
case SIGUSR2: return "sigusr2";
#endif
#ifdef SIGPIPE
case SIGPIPE: return "sigpipe";
#endif
#ifdef SIGALRM
case SIGALRM: return "sigalrm";
#endif
#ifdef SIGTERM
case SIGTERM: return "sigterm";
#endif
#ifdef SIGCHLD
case SIGCHLD: return "sigchld";
#endif
#ifdef SIGSTKFLT
case SIGSTKFLT: return "sigstkflt";
#endif
#ifdef SIGCONT
case SIGCONT: return "sigcont";
#endif
#ifdef SIGSTOP
case SIGSTOP: return "sigstop";
#endif
#ifdef SIGTSTP
case SIGTSTP: return "sigtstp";
#endif
#ifdef SIGBREAK
case SIGBREAK: return "sigbreak";
#endif
#ifdef SIGTTIN
case SIGTTIN: return "sigttin";
#endif
#ifdef SIGTTOU
case SIGTTOU: return "sigttou";
#endif
#ifdef SIGURG
case SIGURG: return "sigurg";
#endif
#ifdef SIGXCPU
case SIGXCPU: return "sigxcpu";
#endif
#ifdef SIGXFSZ
case SIGXFSZ: return "sigxfsz";
#endif
#ifdef SIGVTALRM
case SIGVTALRM: return "sigvtalrm";
#endif
#ifdef SIGPROF
case SIGPROF: return "sigprof";
#endif
#ifdef SIGWINCH
case SIGWINCH: return "sigwinch";
#endif
#ifdef SIGIO
case SIGIO: return "sigio";
#endif
#ifdef SIGPOLL
# if SIGPOLL != SIGIO
case SIGPOLL: return "sigpoll";
# endif
#endif
#ifdef SIGLOST
case SIGLOST: return "siglost";
#endif
#ifdef SIGPWR
# if SIGPWR != SIGLOST
case SIGPWR: return "sigpwr";
# endif
#endif
#ifdef SIGSYS
case SIGSYS: return "sigsys";
#endif
}
return NULL;
}

296
3rdparty/luv/src/dns.c vendored Normal file
View File

@ -0,0 +1,296 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#endif
static void luv_pushaddrinfo(lua_State* L, struct addrinfo* res) {
char ip[INET6_ADDRSTRLEN];
int port, i = 0;
const char *addr;
struct addrinfo* curr = res;
lua_newtable(L);
for (curr = res; curr; curr = curr->ai_next) {
if (curr->ai_family == AF_INET || curr->ai_family == AF_INET6) {
lua_newtable(L);
if (curr->ai_family == AF_INET) {
addr = (char*) &((struct sockaddr_in*) curr->ai_addr)->sin_addr;
port = ((struct sockaddr_in*) curr->ai_addr)->sin_port;
} else {
addr = (char*) &((struct sockaddr_in6*) curr->ai_addr)->sin6_addr;
port = ((struct sockaddr_in6*) curr->ai_addr)->sin6_port;
}
lua_pushstring(L, luv_af_num_to_string(curr->ai_family));
lua_setfield(L, -2, "family");
uv_inet_ntop(curr->ai_family, addr, ip, INET6_ADDRSTRLEN);
lua_pushstring(L, ip);
lua_setfield(L, -2, "addr");
if (ntohs(port)) {
lua_pushinteger(L, ntohs(port));
lua_setfield(L, -2, "port");
}
lua_pushstring(L, luv_sock_num_to_string(curr->ai_socktype));
lua_setfield(L, -2, "socktype");
lua_pushstring(L, luv_af_num_to_string(curr->ai_protocol));
lua_setfield(L, -2, "protocol");
if (curr->ai_canonname) {
lua_pushstring(L, curr->ai_canonname);
lua_setfield(L, -2, "canonname");
}
lua_rawseti(L, -2, ++i);
}
}
}
static void luv_getaddrinfo_cb(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
lua_State* L = luv_state(req->loop);
int nargs;
if (status < 0) {
luv_status(L, status);
nargs = 1;
}
else {
lua_pushnil(L);
luv_pushaddrinfo(L, res);
nargs = 2;
}
luv_fulfill_req(L, req->data, nargs);
luv_cleanup_req(L, req->data);
req->data = NULL;
if (res) uv_freeaddrinfo(res);
}
static int luv_getaddrinfo(lua_State* L) {
uv_getaddrinfo_t* req;
const char* node;
const char* service;
struct addrinfo hints_s;
struct addrinfo* hints = &hints_s;
int ret, ref;
if (lua_isnoneornil(L, 1)) node = NULL;
else node = luaL_checkstring(L, 1);
if (lua_isnoneornil(L, 2)) service = NULL;
else service = luaL_checkstring(L, 2);
if (!lua_isnoneornil(L, 3)) luaL_checktype(L, 3, LUA_TTABLE);
else hints = NULL;
ref = lua_isnoneornil(L, 4) ? LUA_NOREF : luv_check_continuation(L, 4);
if (hints) {
// Initialize the hints
memset(hints, 0, sizeof(*hints));
// Process the `family` hint.
lua_getfield(L, 3, "family");
if (lua_isnumber(L, -1)) {
hints->ai_family = lua_tointeger(L, -1);
}
else if (lua_isstring(L, -1)) {
hints->ai_family = luv_af_string_to_num(lua_tostring(L, -1));
}
else if (lua_isnil(L, -1)) {
hints->ai_family = AF_UNSPEC;
}
else {
luaL_argerror(L, 3, "family hint must be string if set");
}
lua_pop(L, 1);
// Process `socktype` hint
lua_getfield(L, 3, "socktype");
if (lua_isnumber(L, -1)) {
hints->ai_socktype = lua_tointeger(L, -1);
}
else if (lua_isstring(L, -1)) {
hints->ai_socktype = luv_sock_string_to_num(lua_tostring(L, -1));
}
else if (!lua_isnil(L, -1)) {
return luaL_argerror(L, 3, "socktype hint must be string if set");
}
lua_pop(L, 1);
// Process the `protocol` hint
lua_getfield(L, 3, "protocol");
if (lua_isnumber(L, -1)) {
hints->ai_protocol = lua_tointeger(L, -1);
}
else if (lua_isstring(L, -1)) {
int protocol = luv_af_string_to_num(lua_tostring(L, -1));
if (protocol) {
hints->ai_protocol = protocol;
}
else {
return luaL_argerror(L, 3, "Invalid protocol hint");
}
}
else if (!lua_isnil(L, -1)) {
return luaL_argerror(L, 3, "protocol hint must be string if set");
}
lua_pop(L, 1);
lua_getfield(L, 3, "addrconfig");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_ADDRCONFIG;
lua_pop(L, 1);
lua_getfield(L, 3, "v4mapped");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_V4MAPPED;
lua_pop(L, 1);
lua_getfield(L, 3, "all");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_ALL;
lua_pop(L, 1);
lua_getfield(L, 3, "numerichost");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_NUMERICHOST;
lua_pop(L, 1);
lua_getfield(L, 3, "passive");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_PASSIVE;
lua_pop(L, 1);
lua_getfield(L, 3, "numericserv");
if (lua_toboolean(L, -1)) {
hints->ai_flags |= AI_NUMERICSERV;
/* On OS X upto at least OSX 10.9, getaddrinfo crashes
* if AI_NUMERICSERV is set and the servname is NULL or "0".
* This workaround avoids a segfault in libsystem.
*/
if (NULL == service) service = "00";
}
lua_pop(L, 1);
lua_getfield(L, 3, "canonname");
if (lua_toboolean(L, -1)) hints->ai_flags |= AI_CANONNAME;
lua_pop(L, 1);
}
req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
ret = uv_getaddrinfo(luv_loop(L), req, ref == LUA_NOREF ? NULL : luv_getaddrinfo_cb, node, service, hints);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
if (ref == LUA_NOREF) {
lua_pop(L, 1);
luv_pushaddrinfo(L, req->addrinfo);
uv_freeaddrinfo(req->addrinfo);
luv_cleanup_req(L, req->data);
}
return 1;
}
static void luv_getnameinfo_cb(uv_getnameinfo_t* req, int status, const char* hostname, const char* service) {
lua_State* L = luv_state(req->loop);
int nargs;
if (status < 0) {
luv_status(L, status);
nargs = 1;
}
else {
lua_pushnil(L);
lua_pushstring(L, hostname);
lua_pushstring(L, service);
nargs = 3;
}
luv_fulfill_req(L, req->data, nargs);
luv_cleanup_req(L, req->data);
req->data = NULL;
}
static int luv_getnameinfo(lua_State* L) {
uv_getnameinfo_t* req;
struct sockaddr_storage addr;
const char* ip = NULL;
int flags = 0;
int ret, ref, port = 0;
luaL_checktype(L, 1, LUA_TTABLE);
memset(&addr, 0, sizeof(addr));
lua_getfield(L, 1, "ip");
if (lua_isstring(L, -1)) {
ip = lua_tostring(L, -1);
}
else if (!lua_isnil(L, -1)) {
luaL_argerror(L, 1, "ip property must be string if set");
}
lua_pop(L, 1);
lua_getfield(L, 1, "port");
if (lua_isnumber(L, -1)) {
port = lua_tointeger(L, -1);
}
else if (!lua_isnil(L, -1)) {
luaL_argerror(L, 1, "port property must be integer if set");
}
lua_pop(L, 1);
if (ip || port) {
if (!ip) ip = "0.0.0.0";
if (!uv_ip4_addr(ip, port, (struct sockaddr_in*)&addr)) {
addr.ss_family = AF_INET;
}
else if (!uv_ip6_addr(ip, port, (struct sockaddr_in6*)&addr)) {
addr.ss_family = AF_INET6;
}
else {
return luaL_argerror(L, 1, "Invalid ip address or port");
}
}
lua_getfield(L, 1, "family");
if (lua_isnumber(L, -1)) {
addr.ss_family = lua_tointeger(L, -1);
}
else if (lua_isstring(L, -1)) {
addr.ss_family = luv_af_string_to_num(lua_tostring(L, -1));
}
else if (!lua_isnil(L, -1)) {
luaL_argerror(L, 1, "family must be string if set");
}
lua_pop(L, 1);
ref = lua_isnoneornil(L, 2) ? LUA_NOREF : luv_check_continuation(L, 2);
req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
ret = uv_getnameinfo(luv_loop(L), req, ref == LUA_NOREF ? NULL : luv_getnameinfo_cb, (struct sockaddr*)&addr, flags);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
if (ref == LUA_NOREF) {
lua_pop(L, 1);
lua_pushstring(L, req->host);
lua_pushstring(L, req->service);
luv_cleanup_req(L, req->data);
return 2;
}
return 1;
}

614
3rdparty/luv/src/fs.c vendored Normal file
View File

@ -0,0 +1,614 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static uv_fs_t* luv_check_fs(lua_State* L, int index) {
uv_fs_t* req = luaL_checkudata(L, index, "uv_req");
luaL_argcheck(L, req->type = UV_FS && req->data, index, "Expected uv_fs_t");
return req;
}
static void luv_push_timespec_table(lua_State* L, const uv_timespec_t* t) {
lua_createtable(L, 0, 2);
lua_pushinteger(L, t->tv_sec);
lua_setfield(L, -2, "sec");
lua_pushinteger(L, t->tv_nsec);
lua_setfield(L, -2, "nsec");
}
static void luv_push_stats_table(lua_State* L, const uv_stat_t* s) {
const char* type = NULL;
lua_createtable(L, 0, 23);
lua_pushinteger(L, s->st_dev);
lua_setfield(L, -2, "dev");
lua_pushinteger(L, s->st_mode);
lua_setfield(L, -2, "mode");
lua_pushinteger(L, s->st_nlink);
lua_setfield(L, -2, "nlink");
lua_pushinteger(L, s->st_uid);
lua_setfield(L, -2, "uid");
lua_pushinteger(L, s->st_gid);
lua_setfield(L, -2, "gid");
lua_pushinteger(L, s->st_rdev);
lua_setfield(L, -2, "rdev");
lua_pushinteger(L, s->st_ino);
lua_setfield(L, -2, "ino");
lua_pushinteger(L, s->st_size);
lua_setfield(L, -2, "size");
lua_pushinteger(L, s->st_blksize);
lua_setfield(L, -2, "blksize");
lua_pushinteger(L, s->st_blocks);
lua_setfield(L, -2, "blocks");
lua_pushinteger(L, s->st_flags);
lua_setfield(L, -2, "flags");
lua_pushinteger(L, s->st_gen);
lua_setfield(L, -2, "gen");
luv_push_timespec_table(L, &s->st_atim);
lua_setfield(L, -2, "atime");
luv_push_timespec_table(L, &s->st_mtim);
lua_setfield(L, -2, "mtime");
luv_push_timespec_table(L, &s->st_ctim);
lua_setfield(L, -2, "ctime");
luv_push_timespec_table(L, &s->st_birthtim);
lua_setfield(L, -2, "birthtime");
if (S_ISREG(s->st_mode)) {
type = "file";
}
else if (S_ISDIR(s->st_mode)) {
type = "directory";
}
else if (S_ISLNK(s->st_mode)) {
type = "link";
}
else if (S_ISFIFO(s->st_mode)) {
type = "fifo";
}
#ifdef S_ISSOCK
else if (S_ISSOCK(s->st_mode)) {
type = "socket";
}
#endif
else if (S_ISCHR(s->st_mode)) {
type = "char";
}
else if (S_ISBLK(s->st_mode)) {
type = "block";
}
if (type) {
lua_pushstring(L, type);
lua_setfield(L, -2, "type");
}
}
static int luv_check_flags(lua_State* L, int index) {
const char* string;
if (lua_isnumber(L, index)) {
return lua_tointeger(L, index);
}
else if (!lua_isstring(L, index)) {
return luaL_argerror(L, index, "Expected string or integer for file open mode");
}
string = lua_tostring(L, index);
if (strcmp(string, "r") == 0) return O_RDONLY;
#ifdef O_SYNC
if (strcmp(string, "rs") == 0 ||
strcmp(string, "sr") == 0) return O_RDONLY | O_SYNC;
#endif
if (strcmp(string, "r+") == 0) return O_RDWR;
#ifdef O_SYNC
if (strcmp(string, "rs+") == 0 ||
strcmp(string, "sr+") == 0) return O_RDWR | O_SYNC;
#endif
if (strcmp(string, "w") == 0) return O_TRUNC | O_CREAT | O_WRONLY;
if (strcmp(string, "wx") == 0 ||
strcmp(string, "xw") == 0) return O_TRUNC | O_CREAT | O_WRONLY | O_EXCL;
if (strcmp(string, "w+") == 0) return O_TRUNC | O_CREAT | O_RDWR;
if (strcmp(string, "wx+") == 0 ||
strcmp(string, "xw+") == 0) return O_TRUNC | O_CREAT | O_RDWR | O_EXCL;
if (strcmp(string, "a") == 0) return O_APPEND | O_CREAT | O_WRONLY;
if (strcmp(string, "ax") == 0 ||
strcmp(string, "xa") == 0) return O_APPEND | O_CREAT | O_WRONLY | O_EXCL;
if (strcmp(string, "a+") == 0) return O_APPEND | O_CREAT | O_RDWR;
if (strcmp(string, "ax+") == 0 ||
strcmp(string, "xa+") == 0) return O_APPEND | O_CREAT | O_RDWR | O_EXCL;
return luaL_error(L, "Unknown file open flag '%s'", string);
}
static int luv_check_amode(lua_State* L, int index) {
size_t i;
int mode;
const char* string;
if (lua_isnumber(L, index)) {
return lua_tointeger(L, index);
}
else if (!lua_isstring(L, index)) {
return luaL_argerror(L, index, "Expected string or integer for file access mode check");
}
string = lua_tostring(L, index);
mode = 0;
for (i = 0; i < strlen(string); ++i) {
switch (string[i]) {
case 'r': case 'R':
mode |= R_OK;
break;
case 'w': case 'W':
mode |= W_OK;
break;
case 'x': case 'X':
mode |= X_OK;
break;
default:
return luaL_argerror(L, index, "Unknown character in access mode string");
}
}
return mode;
}
/* Processes a result and pushes the data onto the stack
returns the number of items pushed */
static int push_fs_result(lua_State* L, uv_fs_t* req) {
luv_req_t* data = req->data;
if (req->fs_type == UV_FS_ACCESS) {
lua_pushboolean(L, req->result >= 0);
return 1;
}
if (req->result < 0) {
lua_pushnil(L);
if (req->path) {
lua_pushfstring(L, "%s: %s: %s", uv_err_name(req->result), uv_strerror(req->result), req->path);
}
else {
lua_pushfstring(L, "%s: %s", uv_err_name(req->result), uv_strerror(req->result));
}
return 2;
}
switch (req->fs_type) {
case UV_FS_CLOSE:
case UV_FS_RENAME:
case UV_FS_UNLINK:
case UV_FS_RMDIR:
case UV_FS_MKDIR:
case UV_FS_FTRUNCATE:
case UV_FS_FSYNC:
case UV_FS_FDATASYNC:
case UV_FS_LINK:
case UV_FS_SYMLINK:
case UV_FS_CHMOD:
case UV_FS_FCHMOD:
case UV_FS_CHOWN:
case UV_FS_FCHOWN:
case UV_FS_UTIME:
case UV_FS_FUTIME:
lua_pushboolean(L, 1);
return 1;
case UV_FS_OPEN:
case UV_FS_SENDFILE:
case UV_FS_WRITE:
lua_pushinteger(L, req->result);
return 1;
case UV_FS_STAT:
case UV_FS_LSTAT:
case UV_FS_FSTAT:
luv_push_stats_table(L, &req->statbuf);
return 1;
case UV_FS_MKDTEMP:
lua_pushstring(L, req->path);
return 1;
case UV_FS_READLINK:
case UV_FS_REALPATH:
lua_pushstring(L, (char*)req->ptr);
return 1;
case UV_FS_READ:
lua_pushlstring(L, data->data, req->result);
return 1;
case UV_FS_SCANDIR:
// Expose the userdata for the request.
lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref);
return 1;
default:
lua_pushnil(L);
lua_pushfstring(L, "UNKNOWN FS TYPE %d\n", req->fs_type);
return 2;
}
}
static void luv_fs_cb(uv_fs_t* req) {
lua_State* L = luv_state(req->loop);
int nargs = push_fs_result(L, req);
if (nargs == 2 && lua_isnil(L, -nargs)) {
// If it was an error, convert to (err, value) format.
lua_remove(L, -nargs);
nargs--;
}
else {
// Otherwise insert a nil in front to convert to (err, value) format.
lua_pushnil(L);
lua_insert(L, -nargs - 1);
nargs++;
}
luv_fulfill_req(L, req->data, nargs);
if (req->fs_type != UV_FS_SCANDIR) {
luv_cleanup_req(L, req->data);
req->data = NULL;
uv_fs_req_cleanup(req);
}
}
#define FS_CALL(func, req, ...) { \
int ret, sync; \
luv_req_t* data = req->data; \
sync = data->callback_ref == LUA_NOREF; \
ret = uv_fs_##func(luv_loop(L), req, __VA_ARGS__, \
sync ? NULL : luv_fs_cb); \
if (req->fs_type != UV_FS_ACCESS && ret < 0) { \
lua_pushnil(L); \
if (req->path) { \
lua_pushfstring(L, "%s: %s: %s", uv_err_name(req->result), uv_strerror(req->result), req->path); \
} \
else { \
lua_pushfstring(L, "%s: %s", uv_err_name(req->result), uv_strerror(req->result)); \
} \
lua_pushstring(L, uv_err_name(req->result)); \
luv_cleanup_req(L, req->data); \
req->data = NULL; \
uv_fs_req_cleanup(req); \
return 3; \
} \
if (sync) { \
int nargs = push_fs_result(L, req); \
if (req->fs_type != UV_FS_SCANDIR) { \
luv_cleanup_req(L, req->data); \
req->data = NULL; \
uv_fs_req_cleanup(req); \
} \
return nargs; \
} \
lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref); \
return 1; \
}
static int luv_fs_close(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(close, req, file);
}
static int luv_fs_open(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int flags = luv_check_flags(L, 2);
int mode = luaL_checkinteger(L, 3);
int ref = luv_check_continuation(L, 4);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(open, req, path, flags, mode);
}
static int luv_fs_read(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int64_t len = luaL_checkinteger(L, 2);
int64_t offset = luaL_checkinteger(L, 3);
uv_buf_t buf;
int ref;
uv_fs_t* req;
char* data = malloc(len);
if (!data) return luaL_error(L, "Failure to allocate buffer");
buf = uv_buf_init(data, len);
ref = luv_check_continuation(L, 4);
req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
// TODO: find out why we can't just use req->ptr for the base
((luv_req_t*)req->data)->data = buf.base;
FS_CALL(read, req, file, &buf, 1, offset);
}
static int luv_fs_unlink(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(unlink, req, path);
}
static int luv_fs_write(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
uv_buf_t buf;
int64_t offset;
int ref;
uv_fs_t* req;
size_t count;
uv_buf_t *bufs = NULL;
if (lua_istable(L, 2)) {
bufs = luv_prep_bufs(L, 2, &count);
buf.base = NULL;
}
else if (lua_isstring(L, 2)) {
luv_check_buf(L, 2, &buf);
count = 1;
}
else {
return luaL_argerror(L, 2, "data must be string or table of strings");
}
offset = luaL_checkinteger(L, 3);
ref = luv_check_continuation(L, 4);
req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
req->ptr = buf.base;
((luv_req_t*)req->data)->data = bufs;
FS_CALL(write, req, file, bufs ? bufs : &buf, count, offset);
}
static int luv_fs_mkdir(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int mode = luaL_checkinteger(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(mkdir, req, path, mode);
}
static int luv_fs_mkdtemp(lua_State* L) {
const char* tpl = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(mkdtemp, req, tpl);
}
static int luv_fs_rmdir(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(rmdir, req, path);
}
static int luv_fs_scandir(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int flags = 0; // TODO: find out what these flags are.
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(scandir, req, path, flags);
}
static int luv_fs_scandir_next(lua_State* L) {
uv_fs_t* req = luv_check_fs(L, 1);
uv_dirent_t ent;
int ret = uv_fs_scandir_next(req, &ent);
const char* type;
if (ret == UV_EOF) {
luv_cleanup_req(L, req->data);
req->data = NULL;
uv_fs_req_cleanup(req);
return 0;
}
if (ret < 0) return luv_error(L, ret);
lua_pushstring(L, ent.name);
switch (ent.type) {
case UV_DIRENT_UNKNOWN: return 1;
case UV_DIRENT_FILE: type = "file"; break;
case UV_DIRENT_DIR: type = "directory"; break;
case UV_DIRENT_LINK: type = "link"; break;
case UV_DIRENT_FIFO: type = "fifo"; break;
case UV_DIRENT_SOCKET: type = "socket"; break;
case UV_DIRENT_CHAR: type = "char"; break;
case UV_DIRENT_BLOCK: type = "block"; break;
default: assert(0);
}
lua_pushstring(L, type);
return 2;
}
static int luv_fs_stat(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(stat, req, path);
}
static int luv_fs_fstat(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(fstat, req, file);
}
static int luv_fs_lstat(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(lstat, req, path);
}
static int luv_fs_rename(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
const char* new_path = luaL_checkstring(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(rename, req, path, new_path);
}
static int luv_fs_fsync(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(fsync, req, file);
}
static int luv_fs_fdatasync(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(fdatasync, req, file);
}
static int luv_fs_ftruncate(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int64_t offset = luaL_checkinteger(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(ftruncate, req, file, offset);
}
static int luv_fs_sendfile(lua_State* L) {
uv_file out_fd = luaL_checkinteger(L, 1);
uv_file in_fd = luaL_checkinteger(L, 2);
int64_t in_offset = luaL_checkinteger(L, 3);
size_t length = luaL_checkinteger(L, 4);
int ref = luv_check_continuation(L, 5);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(sendfile, req, out_fd, in_fd, in_offset, length);
}
static int luv_fs_access(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int amode = luv_check_amode(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(access, req, path, amode);
}
static int luv_fs_chmod(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int mode = luaL_checkinteger(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(chmod, req, path, mode);
}
static int luv_fs_fchmod(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
int mode = luaL_checkinteger(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(fchmod, req, file, mode);
}
static int luv_fs_utime(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
double atime = luaL_checknumber(L, 2);
double mtime = luaL_checknumber(L, 3);
int ref = luv_check_continuation(L, 4);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(utime, req, path, atime, mtime);
}
static int luv_fs_futime(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
double atime = luaL_checknumber(L, 2);
double mtime = luaL_checknumber(L, 3);
int ref = luv_check_continuation(L, 4);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(futime, req, file, atime, mtime);
}
static int luv_fs_link(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
const char* new_path = luaL_checkstring(L, 2);
int ref = luv_check_continuation(L, 3);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(link, req, path, new_path);
}
static int luv_fs_symlink(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
const char* new_path = luaL_checkstring(L, 2);
int flags = 0, ref;
uv_fs_t* req;
if (lua_type(L, 3) == LUA_TTABLE) {
lua_getfield(L, 3, "dir");
if (lua_toboolean(L, -1)) flags |= UV_FS_SYMLINK_DIR;
lua_pop(L, 1);
lua_getfield(L, 3, "junction");
if (lua_toboolean(L, -1)) flags |= UV_FS_SYMLINK_JUNCTION;
lua_pop(L, 1);
}
ref = luv_check_continuation(L, 4);
req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(symlink, req, path, new_path, flags);
}
static int luv_fs_readlink(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(readlink, req, path);
}
static int luv_fs_realpath(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
int ref = luv_check_continuation(L, 2);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(realpath, req, path);
}
static int luv_fs_chown(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
uv_uid_t uid = luaL_checkinteger(L, 2);
uv_uid_t gid = luaL_checkinteger(L, 3);
int ref = luv_check_continuation(L, 4);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(chown, req, path, uid, gid);
}
static int luv_fs_fchown(lua_State* L) {
uv_file file = luaL_checkinteger(L, 1);
uv_uid_t uid = luaL_checkinteger(L, 2);
uv_uid_t gid = luaL_checkinteger(L, 3);
int ref = luv_check_continuation(L, 4);
uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
req->data = luv_setup_req(L, ref);
FS_CALL(fchown, req, file, uid, gid);
}

97
3rdparty/luv/src/fs_event.c vendored Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static uv_fs_event_t* luv_check_fs_event(lua_State* L, int index) {
uv_fs_event_t* handle = luv_checkudata(L, index, "uv_fs_event");
luaL_argcheck(L, handle->type == UV_FS_EVENT && handle->data, index, "Expected uv_fs_event_t");
return handle;
}
static int luv_new_fs_event(lua_State* L) {
uv_fs_event_t* handle = luv_newuserdata(L, sizeof(*handle));
int ret = uv_fs_event_init(luv_loop(L), handle);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
handle->data = luv_setup_handle(L);
return 1;
}
static void luv_fs_event_cb(uv_fs_event_t* handle, const char* filename, int events, int status) {
lua_State* L = luv_state(handle->loop);
// err
luv_status(L, status);
// filename
lua_pushstring(L, filename);
// events
lua_newtable(L);
if (events & UV_RENAME) {
lua_pushboolean(L, 1);
lua_setfield(L, -2, "rename");
}
if (events & UV_CHANGE) {
lua_pushboolean(L, 1);
lua_setfield(L, -2, "change");
}
luv_call_callback(L, handle->data, LUV_FS_EVENT, 3);
}
static int luv_fs_event_start(lua_State* L) {
uv_fs_event_t* handle = luv_check_fs_event(L, 1);
const char* path = luaL_checkstring(L, 2);
int flags = 0, ret;
luaL_checktype(L, 3, LUA_TTABLE);
lua_getfield(L, 3, "watch_entry");
if (lua_toboolean(L, -1)) flags |= UV_FS_EVENT_WATCH_ENTRY;
lua_pop(L, 1);
lua_getfield(L, 3, "stat");
if (lua_toboolean(L, -1)) flags |= UV_FS_EVENT_STAT;
lua_pop(L, 1);
lua_getfield(L, 3, "recursive");
if (lua_toboolean(L, -1)) flags |= UV_FS_EVENT_RECURSIVE;
lua_pop(L, 1);
luv_check_callback(L, handle->data, LUV_FS_EVENT, 4);
ret = uv_fs_event_start(handle, luv_fs_event_cb, path, flags);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_fs_event_stop(lua_State* L) {
uv_fs_event_t* handle = luv_check_fs_event(L, 1);
int ret = uv_fs_event_stop(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_fs_event_getpath(lua_State* L) {
uv_fs_event_t* handle = luv_check_fs_event(L, 1);
size_t len = 2*PATH_MAX;
char buf[2*PATH_MAX];
int ret = uv_fs_event_getpath(handle, buf, &len);
if (ret < 0) return luv_error(L, ret);
lua_pushlstring(L, buf, len);
return 1;
}

90
3rdparty/luv/src/fs_poll.c vendored Normal file
View File

@ -0,0 +1,90 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static uv_fs_poll_t* luv_check_fs_poll(lua_State* L, int index) {
uv_fs_poll_t* handle = luv_checkudata(L, index, "uv_fs_poll");
luaL_argcheck(L, handle->type == UV_FS_POLL && handle->data, index, "Expected uv_fs_poll_t");
return handle;
}
static int luv_new_fs_poll(lua_State* L) {
uv_fs_poll_t* handle = luv_newuserdata(L, sizeof(*handle));
int ret = uv_fs_poll_init(luv_loop(L), handle);
if (ret < 0) {
lua_pop(L, 1);
return luv_error(L, ret);
}
handle->data = luv_setup_handle(L);
return 1;
}
static void luv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr) {
lua_State* L = luv_state(handle->loop);
// err
luv_status(L, status);
// prev
if (prev) {
luv_push_stats_table(L, prev);
}
else {
lua_pushnil(L);
}
// curr
if (curr) {
luv_push_stats_table(L, curr);
}
else {
lua_pushnil(L);
}
luv_call_callback(L, handle->data, LUV_FS_POLL, 3);
}
static int luv_fs_poll_start(lua_State* L) {
uv_fs_poll_t* handle = luv_check_fs_poll(L, 1);
const char* path = luaL_checkstring(L, 2);
unsigned int interval = luaL_checkinteger(L, 3);
int ret;
luv_check_callback(L, handle->data, LUV_FS_POLL, 4);
ret = uv_fs_poll_start(handle, luv_fs_poll_cb, path, interval);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_fs_poll_stop(lua_State* L) {
uv_fs_poll_t* handle = luv_check_fs_poll(L, 1);
int ret = uv_fs_poll_stop(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_fs_poll_getpath(lua_State* L) {
uv_fs_poll_t* handle = luv_check_fs_poll(L, 1);
size_t len = 2*PATH_MAX;
char buf[2*PATH_MAX];
int ret = uv_fs_poll_getpath(handle, buf, &len);
if (ret < 0) return luv_error(L, ret);
lua_pushlstring(L, buf, len);
return 1;
}

173
3rdparty/luv/src/handle.c vendored Normal file
View File

@ -0,0 +1,173 @@
/*
* Copyright 2014 The Luvit Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "luv.h"
static void* luv_newuserdata(lua_State* L, size_t sz) {
void* handle = malloc(sz);
if (handle) {
*(void**)lua_newuserdata(L, sizeof(void*)) = handle;
}
return handle;
}
static void* luv_checkudata(lua_State* L, int ud, const char* tname) {
return *(void**) luaL_checkudata(L, ud, tname);
}
static uv_handle_t* luv_check_handle(lua_State* L, int index) {
int isHandle;
uv_handle_t* handle;
if (!(handle = *(void**)lua_touserdata(L, index))) { goto fail; }
lua_getfield(L, LUA_REGISTRYINDEX, "uv_handle");
lua_getmetatable(L, index < 0 ? index - 1 : index);
lua_rawget(L, -2);
isHandle = lua_toboolean(L, -1);
lua_pop(L, 2);
if (isHandle) { return handle; }
fail: luaL_argerror(L, index, "Expected uv_handle userdata");
return NULL;
}
// Show the libuv type instead of generic "userdata"
static int luv_handle_tostring(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
switch (handle->type) {
#define XX(uc, lc) case UV_##uc: lua_pushfstring(L, "uv_"#lc"_t: %p", handle); break;
UV_HANDLE_TYPE_MAP(XX)
#undef XX
default: lua_pushfstring(L, "uv_handle_t: %p", handle); break;
}
return 1;
}
static int luv_is_active(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
int ret = uv_is_active(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushboolean(L, ret);
return 1;
}
static int luv_is_closing(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
int ret = uv_is_closing(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushboolean(L, ret);
return 1;
}
static void luv_close_cb(uv_handle_t* handle) {
lua_State* L = luv_state(handle->loop);
luv_handle_t* data = handle->data;
if (!data) return;
luv_call_callback(L, data, LUV_CLOSED, 0);
luv_cleanup_handle(L, data);
handle->data = NULL;
}
static int luv_close(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
if (uv_is_closing(handle)) {
luaL_error(L, "handle %p is already closing", handle);
}
if (!lua_isnoneornil(L, 2)) {
luv_check_callback(L, handle->data, LUV_CLOSED, 2);
}
uv_close(handle, luv_close_cb);
return 0;
}
static void luv_gc_cb(uv_handle_t* handle) {
luv_close_cb(handle);
free(handle);
}
static int luv_handle_gc(lua_State* L) {
void** udata = lua_touserdata(L, 1);
uv_handle_t* handle = *udata;
if (handle != NULL) {
if (!uv_is_closing(handle))
uv_close(handle, luv_gc_cb);
else
free(*udata);
*udata = NULL;
}
return 0;
}
static int luv_ref(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
uv_ref(handle);
return 0;
}
static int luv_unref(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
uv_unref(handle);
return 0;
}
static int luv_has_ref(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
int ret = uv_has_ref(handle);
if (ret < 0) return luv_error(L, ret);
lua_pushboolean(L, ret);
return 1;
}
static int luv_send_buffer_size(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
int value;
int ret;
if (lua_isnoneornil(L, 2)) {
value = 0;
}
else {
value = luaL_checkinteger(L, 2);
}
ret = uv_send_buffer_size(handle, &value);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_recv_buffer_size(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
int value;
int ret;
if (lua_isnoneornil(L, 2)) {
value = 0;
}
else {
value = luaL_checkinteger(L, 2);
}
ret = uv_recv_buffer_size(handle, &value);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, ret);
return 1;
}
static int luv_fileno(lua_State* L) {
uv_handle_t* handle = luv_check_handle(L, 1);
uv_os_fd_t fd;
int ret = uv_fileno(handle, &fd);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, (LUA_INTEGER)(ptrdiff_t)fd);
return 1;
}

Some files were not shown because too many files have changed in this diff Show More