Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ else (WithSharedLibluv)
set(BUILD_MODULE OFF CACHE STRING "Build luv as static library")
include_directories(deps/luv/src)
include_directories(deps/luv/deps/libuv/include)
include_directories(deps/luv/deps/luajit/src)
if (WITH_LUA_ENGINE STREQUAL Lua)
include_directories(deps/luv/deps/lua/src)
set(LUVI_LIBRARIES luv lualib uv)
else()
include_directories(deps/luv/deps/luajit/src)
set(LUVI_LIBRARIES luv luajit-5.1 uv)
endif()
add_subdirectory(deps/luv)
set(LUVI_LIBRARIES luv luajit-5.1 uv)
endif (WithSharedLibluv)


Expand All @@ -118,7 +123,8 @@ add_definitions( -DLUVI_VERSION="${LUVI_VERSION}" )

if(MSVC)
set(winsvc src/winsvc.h src/winsvcaux.h src/winsvc.c src/winsvcaux.c)
add_definitions( -DWITH_WINSVC -DLUA_BUILD_AS_DLL -DLUA_LIB -DBUILDING_UV_SHARED )
add_definitions( -DWITH_WINSVC -DLUA_BUILD_AS_DLL -DBUILDING_UV_SHARED )
add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS )

add_library (luvi_renamed src/luvi_renamed.c)
endif()
Expand All @@ -127,7 +133,11 @@ if(UNIX)
add_definitions(-Wall)
endif()

luajit_add_executable(luvi
if (WITH_LUA_ENGINE STREQUAL Lua)
add_definitions(-DWITH_PLAIN_LUA)
endif ()

lua_add_executable(luvi
${winsvc}
src/main.c
src/lua/init.lua
Expand Down
192 changes: 192 additions & 0 deletions deps/bit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
** Lua BitOp -- a bit operations library for Lua 5.1/5.2.
** http://bitop.luajit.org/
**
** Copyright (C) 2008-2012 Mike Pall. All rights reserved.
**
** 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.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/

#define LUA_BITOP_VERSION "1.0.2"

#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"

#ifdef _MSC_VER
/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif

typedef int32_t SBits;
typedef uint32_t UBits;

typedef union {
lua_Number n;
#ifdef LUA_NUMBER_DOUBLE
uint64_t b;
#else
UBits b;
#endif
} BitNum;

/* Convert argument to bit type. */
static UBits barg(lua_State *L, int idx)
{
BitNum bn;
UBits b;
#if LUA_VERSION_NUM < 502
bn.n = lua_tonumber(L, idx);
#elif LUA_VERSION_NUM >= 503
(void)bn;
b = (UBits)luaL_checkinteger(L, idx);
#else
bn.n = luaL_checknumber(L, idx);
#if defined(LUA_NUMBER_DOUBLE)
bn.n += 6755399441055744.0; /* 2^52+2^51 */
#ifdef SWAPPED_DOUBLE
b = (UBits)(bn.b >> 32);
#else
b = (UBits)bn.b;
#endif
#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
defined(LUA_NUMBER_LLONG)
if (sizeof(UBits) == sizeof(lua_Number))
b = bn.b;
else
b = (UBits)(SBits)bn.n;
#elif defined(LUA_NUMBER_FLOAT)
#error "A 'float' lua_Number type is incompatible with this library"
#else
#error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
#endif
#if LUA_VERSION_NUM < 502
if (b == 0 && !lua_isnumber(L, idx)) {
luaL_typerror(L, idx, "number");
}
#endif
#endif
return b;
}

/* Return bit type. */
#define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;

static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) }
static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) }

#define BIT_OP(func, opr) \
static int func(lua_State *L) { int i; UBits b = barg(L, 1); \
for (i = lua_gettop(L); i > 1; i--) b opr barg(L, i); BRET(b) }
BIT_OP(bit_band, &=)
BIT_OP(bit_bor, |=)
BIT_OP(bit_bxor, ^=)

#define bshl(b, n) (b << n)
#define bshr(b, n) (b >> n)
#define bsar(b, n) ((SBits)b >> n)
#define brol(b, n) ((b << n) | (b >> (32-n)))
#define bror(b, n) ((b << (32-n)) | (b >> n))
#define BIT_SH(func, fn) \
static int func(lua_State *L) { \
UBits b = barg(L, 1); UBits n = barg(L, 2) & 31; BRET(fn(b, n)) }
BIT_SH(bit_lshift, bshl)
BIT_SH(bit_rshift, bshr)
BIT_SH(bit_arshift, bsar)
BIT_SH(bit_rol, brol)
BIT_SH(bit_ror, bror)

static int bit_bswap(lua_State *L)
{
UBits b = barg(L, 1);
b = (b >> 24) | ((b >> 8) & 0xff00) | ((b & 0xff00) << 8) | (b << 24);
BRET(b)
}

static int bit_tohex(lua_State *L)
{
UBits b = barg(L, 1);
SBits n = lua_isnone(L, 2) ? 8 : (SBits)barg(L, 2);
const char *hexdigits = "0123456789abcdef";
char buf[8];
int i;
if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
if (n > 8) n = 8;
for (i = (int)n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; }
lua_pushlstring(L, buf, (size_t)n);
return 1;
}

static const struct luaL_Reg bit_funcs[] = {
{ "tobit", bit_tobit },
{ "bnot", bit_bnot },
{ "band", bit_band },
{ "bor", bit_bor },
{ "bxor", bit_bxor },
{ "lshift", bit_lshift },
{ "rshift", bit_rshift },
{ "arshift", bit_arshift },
{ "rol", bit_rol },
{ "ror", bit_ror },
{ "bswap", bit_bswap },
{ "tohex", bit_tohex },
{ NULL, NULL }
};

/* Signed right-shifts are implementation-defined per C89/C99.
** But the de facto standard are arithmetic right-shifts on two's
** complement CPUs. This behaviour is required here, so test for it.
*/
#define BAD_SAR (bsar(-8, 2) != (SBits)-2)

LUALIB_API int luaopen_bit(lua_State *L)
{
UBits b;
lua_pushnumber(L, (lua_Number)1437217655L);
b = barg(L, -1);
if (b != (UBits)1437217655L || BAD_SAR) { /* Perform a simple self-test. */
const char *msg = "compiled with incompatible luaconf.h";
#ifdef LUA_NUMBER_DOUBLE
#ifdef _WIN32
if (b == (UBits)1610612736L)
msg = "use D3DCREATE_FPU_PRESERVE with DirectX";
#endif
if (b == (UBits)1127743488L)
msg = "not compiled with SWAPPED_DOUBLE";
#endif
if (BAD_SAR)
msg = "arithmetic right-shift broken";
luaL_error(L, "bit library self-test failed (%s)", msg);
}
#if LUA_VERSION_NUM < 502
luaL_register(L, "bit", bit_funcs);
#else
luaL_newlib(L, bit_funcs);
#endif
return 1;
}

6 changes: 2 additions & 4 deletions deps/lrexlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ include_directories(
${LREXLIB_DIR}/src
)

add_definitions(
-DVERSION="2.8.0"
)

add_library(lrexlib
${LREXLIB_DIR}/src/common.c
${LREXLIB_DIR}/src/pcre/lpcre.c
${LREXLIB_DIR}/src/pcre/lpcre_f.c
)

set_target_properties(lrexlib PROPERTIES
COMPILE_FLAGS "-DLUA_LIB -DLUA_COMPAT_APIINTCASTS -DVERSION=\\\"2.8.0\\\"")
target_link_libraries(lrexlib pcre)

set(EXTRA_LIBS ${EXTRA_LIBS} lrexlib)
2 changes: 1 addition & 1 deletion deps/lua-openssl
Submodule lua-openssl updated 64 files
+9 −8 .travis.yml
+9 −2 .travis/platform.sh
+3 −0 .travis/setenv_lua.sh
+48 −31 .travis/setup_lua.sh
+27 −27 appveyor.yml
+2 −2 ldoc/pkcs7.lua
+1 −1 ldoc/pkey.lua
+302 −305 lib/crypto.lua
+88 −82 lib/ssl.lua
+183 −123 src/asn1.c
+0 −1 src/bio.c
+2 −1 src/callback.c
+9 −9 src/cipher.c
+17 −17 src/cms.c
+24 −29 src/crl.c
+61 −37 src/csr.c
+12 −11 src/dh.c
+19 −13 src/digest.c
+12 −11 src/dsa.c
+36 −21 src/ec.c
+3 −9 src/engine.c
+8 −0 src/hmac.c
+0 −3 src/lbn.c
+4 −3 src/lhash.c
+84 −15 src/misc.c
+5 −5 src/ocsp.c
+42 −33 src/openssl.c
+3 −3 src/openssl.h
+29 −37 src/ots.c
+6 −7 src/pkcs12.c
+331 −203 src/pkcs7.c
+65 −74 src/pkey.c
+18 −13 src/private.h
+79 −11 src/rsa.c
+5 −154 src/sk.h
+18 −29 src/ssl.c
+0 −3 src/th-lock.c
+81 −73 src/x509.c
+74 −56 src/xalgor.c
+2 −38 src/xattrs.c
+4 −46 src/xexts.c
+7 −3 src/xname.c
+0 −2 src/xstore.c
+0 −1 test/0.engine.lua
+2 −1 test/0.misc.lua
+20 −7 test/1.asn1.lua
+1 −5 test/1.x509_attr.lua
+2 −6 test/1.x509_extension.lua
+8 −1 test/1.x509_name.lua
+8 −4 test/2.asn1.lua
+1 −1 test/2.digest.lua
+1 −1 test/2.hmac.lua
+3 −3 test/4.pkey.lua
+12 −9 test/5.ts.lua
+7 −4 test/5.x509.lua
+30 −16 test/5.x509_req.lua
+9 −15 test/6.pkcs7.lua
+5 −6 test/7.pkcs12.lua
+2 −1 test/ec.lua
+1 −1 test/luacrypto/pkeytest.lua
+21 −21 test/luacrypto/run-test.lua
+873 −399 test/luaunit.lua
+27 −8 test/memleaks.lua
+2 −0 test/test.lua
10 changes: 7 additions & 3 deletions deps/lua-openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ include_directories(
${LUA_OPENSSL_DIR}/src
)

add_definitions(
-DCOMPAT52_IS_LUAJIT
)
find_package(Threads)
if (CMAKE_THREAD_LIBS_INIT)
add_definitions(-DPTHREADS)
endif (CMAKE_THREAD_LIBS_INIT)

add_library(lua_openssl
${LUA_OPENSSL_DIR}/src/asn1.c
Expand Down Expand Up @@ -49,6 +50,9 @@ add_library(lua_openssl
${LUA_OPENSSL_DIR}/src/xstore.c
)

set_target_properties(lua_openssl PROPERTIES
COMPILE_FLAGS "-DLUA_LIB -DCOMPAT52_IS_LUAJIT")

if (WithSharedOpenSSL)
target_link_libraries(lua_openssl ssl crypto)
else (WithSharedOpenSSL)
Expand Down
2 changes: 1 addition & 1 deletion deps/lua-zlib
Submodule lua-zlib updated 4 files
+5 −3 CMakeLists.txt
+6 −1 lua_zlib.c
+5 −2 rockspec
+7 −4 tap.lua
2 changes: 2 additions & 0 deletions deps/lua-zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ add_library(lua_zlib
${LUA_ZLIB_DIR}/zlib.def
)

set_target_properties(lua_zlib PROPERTIES COMPILE_FLAGS -DLUA_LIB)

target_link_libraries(lua_zlib ${LUA_ZLIB_LIB})

set(EXTRA_LIBS ${EXTRA_LIBS} lua_zlib)
Expand Down
2 changes: 1 addition & 1 deletion deps/luv
34 changes: 34 additions & 0 deletions src/lenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,39 @@ static const luaL_Reg lenv_f[] = {

LUALIB_API int luaopen_env(lua_State *L) {
luaL_newlib(L, lenv_f);
#if defined(_WIN32) && !defined(_XBOX_VER)
lua_pushstring(L, "Windows");
#elif defined(__linux__)
lua_pushstring(L, "Linux");
#elif defined(__MACH__) && defined(__APPLE__)
lua_pushstring(L, "OSX");
#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__DragonFly__)) && !defined(__ORBIS__)
lua_pushstring(L, "BSD");
#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
lua_pushstring(L, "POSIX");
#else
lua_pushstring(L, "Other");
#endif
lua_setfield(L, -2, "os");

#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
lua_pushstring(L, "x86");
#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
lua_pushstring(L, "x64");
#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
lua_pushstring(L, "arm");
#elif defined(__aarch64__)
lua_pushstring(L, "arm64");
#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
lua_pushstring(L, "ppc");
#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
lua_pushstring(L, "mips");
#else
lua_pushstring(L, "other");
#endif
lua_setfield(L, -2, "arch");

return 1;
}
10 changes: 5 additions & 5 deletions src/lminiz.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int lmz_reader_locate_file(lua_State *L) {

static int lmz_reader_stat(lua_State* L) {
lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_reader");
mz_uint file_index = luaL_checkinteger(L, 2) - 1;
mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&(zip->archive), file_index, &stat)) {
lua_pushnil(L);
Expand Down Expand Up @@ -130,7 +130,7 @@ static int lmz_reader_stat(lua_State* L) {

static int lmz_reader_get_filename(lua_State* L) {
lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_reader");
mz_uint file_index = luaL_checkinteger(L, 2) - 1;
mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
char pFilename[PATH_MAX];
mz_uint filename_buf_size = PATH_MAX;
if (!mz_zip_reader_get_filename(&(zip->archive), file_index, pFilename, filename_buf_size)) {
Expand All @@ -144,14 +144,14 @@ static int lmz_reader_get_filename(lua_State* L) {

static int lmz_reader_is_file_a_directory(lua_State *L) {
lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_reader");
mz_uint file_index = luaL_checkinteger(L, 2) - 1;
mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
lua_pushboolean(L, mz_zip_reader_is_file_a_directory(&(zip->archive), file_index));
return 1;
}

static int lmz_reader_extract(lua_State *L) {
lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_reader");
mz_uint file_index = luaL_checkinteger(L, 2) - 1;
mz_uint file_index = (mz_uint)luaL_checkinteger(L, 2) - 1;
mz_uint flags = luaL_optint(L, 3, 0);
size_t out_len;
char* out_buf = mz_zip_reader_extract_to_heap(&(zip->archive), file_index, &out_len, flags);
Expand Down Expand Up @@ -185,7 +185,7 @@ static int lmz_writer_init(lua_State *L) {
static int lmz_writer_add_from_zip_reader(lua_State *L) {
lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_writer");
lmz_file_t* source = luaL_checkudata(L, 2, "miniz_reader");
mz_uint file_index = luaL_checkinteger(L, 3) - 1;
mz_uint file_index = (mz_uint)luaL_checkinteger(L, 3) - 1;
if (!mz_zip_writer_add_from_zip_reader(&(zip->archive), &(source->archive), file_index)) {
return luaL_error(L, "Failure to copy file between zips");
}
Expand Down
3 changes: 3 additions & 0 deletions src/lua/luvibundle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ local luviPath = require('luvipath')
local pathJoin = luviPath.pathJoin
local getenv = require('os').getenv

loadstring = loadstring or load
unpack = unpack or table.unpack

local tmpBase = luviPath.isWindows and (getenv("TMP") or uv.cwd()) or
(getenv("TMPDIR") or '/tmp')

Expand Down
Loading