Module socket.wrapper

Pure LuaJIT bindings for Windows and Linux native socket libraries.

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

See also:

Info:

  • Copyright: 2026
  • Release: 0.0.0
  • License: CC0 1.0 Universal (CC0 1.0) (Public Domain)
  • Author: Herwin Bozet (NibblePoker)

Functions

init () Initializes the native socket libraries if required.
deinit () De-initializes the native socket libraries if required, and closes all active sockets.
socket (af, socktype, protocol) Creates a new socket of a given address family, type, and protocol.
closesocket (s) Closes a given socket that was previously created.
connect (s, af, port, host) Creates a connection to a distant host via a given socket.
bind (s, af, port, host) Binds a given socket to some interface, or none.
shutdown (s, how) Closes a connection to distant host made via a given socket.
send (s, data, len, flags) Sends data over a given socket
ioctlsocket (s, cmd, arg) Sends some IOCTL command and return any potential result.

Fields

bindings Link to the socket.bindings module.
constants Link to the socket.constants module.
winsock_version Defines which Winsock version is used when calling WSAStartup via init.


Functions

init ()
Initializes the native socket libraries if required. ???

Returns:

  1. boolean true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

deinit ()
De-initializes the native socket libraries if required, and closes all active sockets. ???

Returns:

  1. boolean - true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

socket (af, socktype, protocol)
Creates a new socket of a given address family, type, and protocol. Requires a prior call to init() on some platforms.

Parameters:

  • af integer An address family from the bindings.AF_* constants, or the AddressFamilies enum.
  • socktype integer A socket type from the bindings.SOCK_* constants, or the SocketTypes enum.
  • protocol integer An address family from the bindings.IPPROTO_*/bindings.BTHPROTO_* constants, or the Protocols enum.

Returns:

  1. SOCKET? A non-nil value representating the socket if opened, nil otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

closesocket (s)
Closes a given socket that was previously created.

Parameters:

  • s SOCKET The socket to close.

Returns:

  1. boolean true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

connect (s, af, port, host)
Creates a connection to a distant host via a given socket.

Parameters:

  • s SOCKET The socket over which the connection will pass.
  • af integer An address family from the bindings.AF_* constants, or the AddressFamilies enum.
  • port integer The remote host's port.
  • host string The remote host's hostname/IP/address/...

Returns:

  1. boolean true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

bind (s, af, port, host)
Binds a given socket to some interface, or none.

Parameters:

  • s SOCKET The socket that should be bound.
  • af integer An address family from the bindings.AF_* constants, or the AddressFamilies enum.
  • port integer The bound port.
  • host string The bound interface's address, or a constant from the bindings.INADDR_* family, or the BindingAddresses enum.

Returns:

  1. boolean true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

shutdown (s, how)
Closes a connection to distant host made via a given socket.

Parameters:

  • s SOCKET The socket whose connection should be terminated.
  • how integer A combination of shutdown flags from the bindings.SD_* constants, or the ShutdownFlags enum.

Returns:

  1. boolean true if the operation succeeded, false otherwise.
  2. integer Error code if the operation was a failure, 0 otherwise.

See also:

send (s, data, len, flags)
Sends data over a given socket

Parameters:

  • s SOCKET The socket over which data is to be sent.
  • data any The data to send, its length will be calculated automatically.
  • len integer? Leave empty to auto-calculate the data length. (Remove in the future, only OOP version shoud do this !)
  • flags integer? Optional flags used to influence the way data is sent.

Returns:

    integer bytes_sent The amount of bytes sent, or SOCKET_ERROR if an error occured.
ioctlsocket (s, cmd, arg)
Sends some IOCTL command and return any potential result. This function doesn't check if the command is valid !

Parameters:

  • s SOCKET The socket over which data is to be sent.
  • cmd integer ???
  • arg integer ???

Returns:

    boolean true if the operation succeeded, false otherwise.

Or

  1. u_long The value that may have been returned by the ioctlsocket call, or the original one from the arg parameters.
  2. integer Error code if the operation was a failure.

Fields

bindings
Link to the socket.bindings module.

See also:

constants
Link to the socket.constants module.

See also:

winsock_version
Defines which Winsock version is used when calling WSAStartup via init.
The format for MAJOR.MINOR is (MAJOR & 0x00FF) | ((MINOR << 8) | 0xFF00).
Has no effect on non-Windows platforms.
generated by LDoc 1.5.0 Last updated 2026-03-29 20:25:08