LuaJIT - Sockets

Pure LuaJIT bindings and wrappers for the standard Win32 and Linux socket libraries.

⚠️ This library is still in heavy development ⚠️

Features

    <li>// BSD/POSIX-compaptible bindings (Find out which is correct)</li>
    <li>// OOP-friendly wrapper around the bindings</li>
    <li>Transparent multi-platform support
        <ul>
            <li>Constants - Comments about platform-specificity, or always defined</li>
            <li>Bindings - NOOP functions that always fail for platform-specific ones</li>
            <li>OOP - Automatic calls to WSAStartup and WSAStartup for WinSock</li>
            <li>...</li>
        </ul>
    </li>
    <li>No pre-compilation required</li>
    <li>// Fully documented (Well on its way)</li>
    

Requirements

    <li>A somewhat modern OS
        <ul>
            <li>// Windows 7+ <i>(x86/x64)</i></li>
            <li>Windows 10+ <i>(x86/x64) (Untested on ARM32/ARM64)</i></li>
            <li>// Linux 4.4+ <i>(x86/x64) (Untested on ARM32/ARM64/RISCV/...)</i></li>
        </ul>
    </li>
    <li>LuaJIT v2.1.*</li>
    

Installation

Manual

    <li>Download [latest release](https://github.com/aziascreations/LuaJIT-Sockets/releases)</li>
    <li>Extract the content of the archive in your lua/ folder</li>
    

LuaRocks

TODO: Once this is stable

Usage

Module types/scopes

Bindings

Module that provides basic and platform-dependant bindings for socket-related functions.

Wrapper

Module that provides platform-independant wrappers for socket-related functions while keeping the platform-dependant error constants.

OOP

PLANNED \ Module that provides an OOP-friendly and self-managed way of using sockets without having to manage their initialisation and proper closure.

Call flow

Windows Bindings* Linux Bindings* Wrapper OOP
WSAStartup init ** ???
socket socket socket ???
connect connect connect ???
... ... ... ???
shutdown shutdown shutdown ???
closesocket closesocket closesocket ???
WSAStartup deinit ** ???
* : Bindings module, or other system programming languages \ ** : Does nothing on Linux platforms (TODO: See it this holds true) ### Feel of the API
Bindings Wrapper OOP
-- Preparing data
local data_to_send = "Test 123"
local data_pointer = ffi.cast(
    "const char *",
    data_to_send
)
local data_length = #data_to_send

-- Sending data
local bytes_sent = socket.send(
    sock,
    data_pointer,
    data_length,
    0
)

-- Error handling
if bytes_sent == socket.SOCKET_ERROR then
    error("Error in socker.send() !")
    socket.shutdown(sock, socket.SD_BOTH)
    socket.closesocket(sock)
    socket.WSACleanup()
    return
end
-- Preparing data
local data_to_send = "Test 123"






-- Sending data
local bytes_sent = socket.send(
    sock,
    data_to_send,
    nil
)


-- Error handling
if bytes_sent == socket.SOCKET_ERROR then
    error("Error in socker.send() !")
    socket.shutdown(sock, socket.SD_BOTH)
    socket.closesocket(sock)
    socket.deinit()
    return
end
TODO: Implement OOP module

Client

Server

TODO: Implement listening capabilities

License

The code in this repository is licensed under CC0 1.0 Universal (CC0 1.0) (Public Domain).

generated by LDoc 1.5.0 Last updated 2026-03-29 20:25:08