mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-04-30 20:26:44 +02:00
Compare commits
7 Commits
8668ae6906
...
f1ea290437
Author | SHA1 | Date | |
---|---|---|---|
|
f1ea290437 | ||
|
0f37af645c | ||
|
9c6195ea62 | ||
|
708e50f8e6 | ||
|
0bc8c56043 | ||
|
f741a88b80 | ||
|
83b6fd9449 |
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@ -13,22 +13,27 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
|
||||
platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua
|
||||
platform: [ "ubuntu-20.04", "macos-11", "windows-2022" ]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup ’msvc’
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
if: ${{ !startsWith(matrix.luaVersion, 'luajit') }}
|
||||
- name: Setup ‘lua’
|
||||
uses: leafo/gh-actions-lua@v9
|
||||
uses: leso-kn/gh-actions-lua@v11-staging
|
||||
with:
|
||||
luaVersion: ${{ matrix.luaVersion }}
|
||||
- name: Setup ‘luarocks’
|
||||
uses: leafo/gh-actions-luarocks@v4
|
||||
uses: hishamhm/gh-actions-luarocks@master
|
||||
- name: Make and install
|
||||
run: |
|
||||
export DEBUG=DEBUG
|
||||
luarocks make -- luasocket-scm-3.rockspec
|
||||
env:
|
||||
DEBUG: DEBUG
|
||||
- name: Run regression tests
|
||||
shell: bash
|
||||
run: |
|
||||
cd test
|
||||
lua hello.lua
|
||||
|
121
.github/workflows/windows.yml
vendored
Normal file
121
.github/workflows/windows.yml
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
name: Windows
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
visual-studio:
|
||||
name: Visual Studio ${{ matrix.vs-version }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
vs-version:
|
||||
- 2019
|
||||
- 2017
|
||||
include:
|
||||
- cmake-architecture: x64
|
||||
cmake-generator: Visual Studio 16 2019
|
||||
runs-on: windows-2019
|
||||
vs-version: 2019
|
||||
- cmake-generator: Visual Studio 15 2017 Win64
|
||||
runs-on: windows-2016
|
||||
vs-version: 2017
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
steps:
|
||||
- name: Disable crash dialog
|
||||
run: |
|
||||
reg add "HKCU\SOFTWARE\Microsoft\Windows\Windows Error Reporting" `
|
||||
/v DontShowUI `
|
||||
/t REG_DWORD `
|
||||
/d 1 `
|
||||
/f
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set environment variables
|
||||
run: |
|
||||
Write-Output "::set-env name=CMAKE_BUILD_PARALLEL_LEVEL::${Env:NUMBER_OF_PROCESSORS}"
|
||||
|
||||
$VC_PREFIX = "C:\Program Files (x86)\Microsoft Visual Studio\${{ matrix.vs-version }}\Enterprise\VC"
|
||||
Write-Output "::set-env name=VC_PREFIX::${VC_PREFIX}"
|
||||
|
||||
$INSTALL_FOLDER = "${Env:GITHUB_WORKSPACE}\install"
|
||||
Write-Output "::set-env name=INSTALL_FOLDER::${INSTALL_FOLDER}"
|
||||
|
||||
$LUA = "${INSTALL_FOLDER}\bin\lua.exe"
|
||||
Write-Output "::set-env name=LUA::${LUA}"
|
||||
|
||||
$LUASOCKET_ROCKSPEC = $(Get-ChildItem rockspec -Exclude "*scm*").FullName
|
||||
Write-Output "::set-env name=LUASOCKET_ROCKSPEC::${LUASOCKET_ROCKSPEC}"
|
||||
- name: Install Lua
|
||||
shell: cmd
|
||||
run: |
|
||||
call "%VC_PREFIX%\Auxiliary\Build\vcvarsall.bat" x64
|
||||
mkdir lua-build
|
||||
set CMAKE_ARGS=-S ci\lua
|
||||
set CMAKE_ARGS=%CMAKE_ARGS% -B lua-build
|
||||
if not "${{ matrix.cmake-architecture }}" == "" (
|
||||
set CMAKE_ARGS=%CMAKE_ARGS% -A ${{ matrix.cmake-architecture }}
|
||||
)
|
||||
set CMAKE_ARGS=%CMAKE_ARGS% -G "${{ matrix.cmake-generator }}"
|
||||
set CMAKE_ARGS=%CMAKE_ARGS% "-DCMAKE_INSTALL_PREFIX=%INSTALL_FOLDER%"
|
||||
cmake %CMAKE_ARGS%
|
||||
cmake --build lua-build --config RelWithDebInfo
|
||||
cmake --build lua-build --config RelWithDebInfo --target Install
|
||||
- name: Install LuaRocks
|
||||
run: |
|
||||
$LUAROCKS_VERSION = "3.3.1"
|
||||
$LUAROCKS_ARCHIVE_BASE = "luarocks-${LUAROCKS_VERSION}-windows-64"
|
||||
Invoke-WebRequest `
|
||||
-Uri "http://luarocks.github.io/luarocks/releases/${LUAROCKS_ARCHIVE_BASE}.zip" `
|
||||
-OutFile "${LUAROCKS_ARCHIVE_BASE}.zip"
|
||||
Expand-Archive `
|
||||
-DestinationPath . `
|
||||
"${LUAROCKS_ARCHIVE_BASE}.zip"
|
||||
|
||||
$LUAROCKS = "${Env:GITHUB_WORKSPACE}\${LUAROCKS_ARCHIVE_BASE}\luarocks.exe"
|
||||
Write-Output "::set-env name=LUAROCKS::${LUAROCKS}"
|
||||
- name: Prepare LuaRocks
|
||||
shell: cmd
|
||||
run: |
|
||||
call "%VC_PREFIX%\Auxiliary\Build\vcvarsall.bat" x64
|
||||
%LUAROCKS% --lua-dir %INSTALL_FOLDER% path > luarocks.path.bat
|
||||
- name: Install LuaSocket
|
||||
shell: cmd
|
||||
run: |
|
||||
call "%VC_PREFIX%\Auxiliary\Build\vcvarsall.bat" x64
|
||||
%LUAROCKS% --lua-dir %INSTALL_FOLDER% make %LUASOCKET_ROCKSPEC%
|
||||
- name: Test LuaSocket
|
||||
shell: cmd
|
||||
run: |
|
||||
call "%VC_PREFIX%\Auxiliary\Build\vcvarsall.bat" x64
|
||||
call luarocks.path.bat
|
||||
cd test
|
||||
%LUA% hello.lua
|
||||
|
||||
mingw:
|
||||
name: MinGW
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- name: Disable crash dialog
|
||||
run: |
|
||||
reg add "HKCU\SOFTWARE\Microsoft\Windows\Windows Error Reporting" `
|
||||
/v DontShowUI `
|
||||
/t REG_DWORD `
|
||||
/d 1 `
|
||||
/f
|
||||
- uses: actions/checkout@v2
|
||||
- uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
install: >-
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-lua51-luarocks
|
||||
- name: Install LuaSocket
|
||||
shell: msys2 {0}
|
||||
run: |
|
||||
rm rockspec/*-scm-*.rockspec || :
|
||||
luarocks make rockspec/*.rockspec
|
||||
- name: Test LuaSocket
|
||||
shell: msys2 {0}
|
||||
run: |
|
||||
cd test
|
||||
lua5.1.exe hello.lua
|
151
ci/lua/CMakeLists.txt
Normal file
151
ci/lua/CMakeLists.txt
Normal file
@ -0,0 +1,151 @@
|
||||
# GitHub Actions ships CMake 3.18.0:
|
||||
# * https://github.com/actions/virtual-environments/blob/main/images/win/Windows2016-Readme.md#tools
|
||||
# * https://github.com/actions/virtual-environments/blob/main/images/win/Windows2016-Readme.md#tools
|
||||
cmake_minimum_required(VERSION 3.14.0)
|
||||
|
||||
set(LUA_VERSION "5.4.0" CACHE STRING "Lua version to be built")
|
||||
|
||||
project(lua
|
||||
VERSION ${LUA_VERSION}
|
||||
HOMEPAGE_URL "https://www.lua.org/"
|
||||
LANGUAGES C)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(LUA_ARCHIVE_BASE "lua-${LUA_VERSION}")
|
||||
set(LUA_ARCHIVE_NAME "${LUA_ARCHIVE_BASE}.tar.gz")
|
||||
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${LUA_ARCHIVE_NAME}")
|
||||
message("Downloading Lua ${LUA_VERSION}...")
|
||||
set(LUA_ARCHIVE_URL "https://www.lua.org/ftp/${LUA_ARCHIVE_NAME}")
|
||||
file(DOWNLOAD
|
||||
${LUA_ARCHIVE_URL}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${LUA_ARCHIVE_NAME}"
|
||||
SHOW_PROGRESS
|
||||
STATUS LUA_DOWNLOAD_STATUS)
|
||||
list(GET LUA_DOWNLOAD_STATUS 0 LUA_DOWNLOAD_STATUS_CODE)
|
||||
if(NOT ${LUA_DOWNLOAD_STATUS_CODE} EQUAL 0)
|
||||
message(FATAL_ERROR
|
||||
"Failed to download Lua source: ${LUA_ARCHIVE_URL}: ${LUA_DOWNLOAD_STATUS}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E "tar" "xf" ${LUA_ARCHIVE_NAME}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
string(REGEX REPLACE
|
||||
"^([0-9]+)\\.([0-9]+)\\..*$"
|
||||
"\\1\\2"
|
||||
LUA_DLL_VERSION
|
||||
${LUA_VERSION})
|
||||
|
||||
if(${LUA_VERSION} VERSION_LESS "5.5.0")
|
||||
add_compile_definitions("LUA_COMPAT_5_3")
|
||||
elseif(${LUA_VERSION} VERSION_LESS "5.4.0")
|
||||
add_compile_definitions("LUA_COMPAT_5_2")
|
||||
endif()
|
||||
if(WIN32)
|
||||
add_compile_definitions("LUA_BUILD_AS_DLL")
|
||||
endif()
|
||||
|
||||
set(LUA_SOURCE_BASE ${CMAKE_CURRENT_BINARY_DIR}/${LUA_ARCHIVE_BASE}/src)
|
||||
set(LIBLUA_CORE_SOURCES
|
||||
${LUA_SOURCE_BASE}/lapi.c
|
||||
${LUA_SOURCE_BASE}/lcode.c
|
||||
${LUA_SOURCE_BASE}/lctype.c
|
||||
${LUA_SOURCE_BASE}/ldebug.c
|
||||
${LUA_SOURCE_BASE}/ldo.c
|
||||
${LUA_SOURCE_BASE}/ldump.c
|
||||
${LUA_SOURCE_BASE}/lfunc.c
|
||||
${LUA_SOURCE_BASE}/lgc.c
|
||||
${LUA_SOURCE_BASE}/llex.c
|
||||
${LUA_SOURCE_BASE}/lmem.c
|
||||
${LUA_SOURCE_BASE}/lobject.c
|
||||
${LUA_SOURCE_BASE}/lopcodes.c
|
||||
${LUA_SOURCE_BASE}/lparser.c
|
||||
${LUA_SOURCE_BASE}/lstate.c
|
||||
${LUA_SOURCE_BASE}/lstring.c
|
||||
${LUA_SOURCE_BASE}/ltable.c
|
||||
${LUA_SOURCE_BASE}/ltm.c
|
||||
${LUA_SOURCE_BASE}/lundump.c
|
||||
${LUA_SOURCE_BASE}/lvm.c
|
||||
${LUA_SOURCE_BASE}/lzio.c)
|
||||
set(LIBLUA_LIB_SOURCES
|
||||
${LUA_SOURCE_BASE}/lauxlib.c
|
||||
${LUA_SOURCE_BASE}/lbaselib.c
|
||||
${LUA_SOURCE_BASE}/lcorolib.c
|
||||
${LUA_SOURCE_BASE}/ldblib.c
|
||||
${LUA_SOURCE_BASE}/liolib.c
|
||||
${LUA_SOURCE_BASE}/lmathlib.c
|
||||
${LUA_SOURCE_BASE}/loadlib.c
|
||||
${LUA_SOURCE_BASE}/loslib.c
|
||||
${LUA_SOURCE_BASE}/lstrlib.c
|
||||
${LUA_SOURCE_BASE}/ltablib.c
|
||||
${LUA_SOURCE_BASE}/lutf8lib.c
|
||||
${LUA_SOURCE_BASE}/linit.c)
|
||||
set(LIBLUA_SOURCES ${LIBLUA_CORE_SOURCES} ${LIBLUA_LIB_SOURCES})
|
||||
add_library(liblua_shared SHARED ${LIBLUA_SOURCES})
|
||||
if(NOT WIN32)
|
||||
add_library(liblua_static STATIC ${LIBLUA_SOURCES})
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(liblua_shared m)
|
||||
target_link_libraries(liblua_static m)
|
||||
endif()
|
||||
if(WIN32)
|
||||
set_target_properties(liblua_shared PROPERTIES
|
||||
OUTPUT_NAME "lua${LUA_DLL_VERSION}")
|
||||
else()
|
||||
set_target_properties(liblua_shared
|
||||
PROPERTIES OUTPUT_NAME "lua")
|
||||
set_target_properties(liblua_static
|
||||
PROPERTIES OUTPUT_NAME "lua")
|
||||
endif()
|
||||
install(TARGETS liblua_shared
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(NOT WIN32)
|
||||
install(TARGETS liblua_static
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
if(MSVC)
|
||||
install(FILES $<TARGET_PDB_FILE:liblua_shared>
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
|
||||
set(LUA_SOURCES ${LUA_SOURCE_BASE}/lua.c)
|
||||
add_executable(lua ${LUA_SOURCES})
|
||||
if(WIN32)
|
||||
target_link_libraries(lua liblua_shared)
|
||||
else()
|
||||
target_link_libraries(lua liblua_static)
|
||||
endif()
|
||||
install(TARGETS lua DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(MSVC)
|
||||
install(FILES $<TARGET_PDB_FILE:lua>
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
|
||||
set(LUAC_SOURCES ${LUA_SOURCE_BASE}/luac.c)
|
||||
if(WIN32)
|
||||
add_executable(luac ${LUAC_SOURCES} ${LIBLUA_SOURCES})
|
||||
else()
|
||||
target_link_libraries(luac liblua_static)
|
||||
endif()
|
||||
install(TARGETS luac DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(MSVC)
|
||||
install(FILES $<TARGET_PDB_FILE:luac>
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
OPTIONAL)
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${LUA_SOURCE_BASE}/lua.h
|
||||
${LUA_SOURCE_BASE}/luaconf.h
|
||||
${LUA_SOURCE_BASE}/lualib.h
|
||||
${LUA_SOURCE_BASE}/lauxlib.h
|
||||
${LUA_SOURCE_BASE}/lua.hpp
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
@ -54,6 +54,33 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
|
||||
return opt->func(L, ps);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* binds socket to network interface */
|
||||
int opt_set_bindtodevice(lua_State *L, p_socket ps)
|
||||
{
|
||||
#ifndef SO_BINDTODEVICE
|
||||
return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
|
||||
#else
|
||||
const char *dev = luaL_checkstring(L, 3);
|
||||
return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char*)dev, strlen(dev)+1);
|
||||
#endif
|
||||
}
|
||||
|
||||
int opt_get_bindtodevice(lua_State *L, p_socket ps)
|
||||
{
|
||||
#ifndef SO_BINDTODEVICE
|
||||
return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
|
||||
#else
|
||||
char dev[IFNAMSIZ];
|
||||
int len = sizeof(dev);
|
||||
int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, &dev, &len);
|
||||
if (err)
|
||||
return err;
|
||||
lua_pushstring(L, dev);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* enables reuse of local address */
|
||||
int opt_set_reuseaddr(lua_State *L, p_socket ps)
|
||||
|
@ -53,6 +53,9 @@ int opt_get_tcp_keepintvl(lua_State *L, p_socket ps);
|
||||
int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
|
||||
#endif
|
||||
|
||||
int opt_set_bindtodevice(lua_State *L, p_socket ps);
|
||||
int opt_get_bindtodevice(lua_State *L, p_socket ps);
|
||||
|
||||
int opt_set_keepalive(lua_State *L, p_socket ps);
|
||||
int opt_get_keepalive(lua_State *L, p_socket ps);
|
||||
|
||||
|
@ -71,6 +71,7 @@ static luaL_Reg tcp_methods[] = {
|
||||
|
||||
/* socket option handlers */
|
||||
static t_opt optget[] = {
|
||||
{"bindtodevice", opt_get_bindtodevice},
|
||||
{"keepalive", opt_get_keepalive},
|
||||
{"reuseaddr", opt_get_reuseaddr},
|
||||
{"reuseport", opt_get_reuseport},
|
||||
@ -92,6 +93,7 @@ static t_opt optget[] = {
|
||||
};
|
||||
|
||||
static t_opt optset[] = {
|
||||
{"bindtodevice", opt_set_bindtodevice},
|
||||
{"keepalive", opt_set_keepalive},
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
{"reuseport", opt_set_reuseport},
|
||||
|
Loading…
x
Reference in New Issue
Block a user