Utils

Utilities that don’t fall under a specific class

utils.send_all(sock, s)

Attempt to call the send method on the provided, sock retrying on failure or timeout

Parameters
  • sock (luasocket.socket) – The socket to send on

  • s (str) – The string to send

Returns

the number of bytes sent if not nil

Return type

integer or nil

Returns

the last error message encountered if not nil

Return type

nil or str

utils.tcp_socket_source(socket)

Use a luasocket api conforming table as a source via the ltn12 api

the function returned will attempt to call the receive method on the provided socket

Parameters

socket (luasocket.tcp) – A tcp socket

Returns

(pat:string|integer|nil):string,string

Return type

function

utils.next_line(chunk)

Get the first line from a chunk, discarding the new line characters, returning

the line followed by the remainder of the chunk after that line

Parameters

chunk (str) –

Returns

If not nil, the line found, if nil no new line character was found

Return type

str

Return type

str

utils.extract_len(chunk)

Get the first line from a chunk, discarding the new line characters, returning

the line followed by the remainder of the chunk after that line

Parameters

chunk (str) –

Returns

If not nil, the line found, if nil no new line character was found

Return type

str

Return type

str

utils.udp_socket_source(socket)

wrap a luasocket udp socket in an ltn12 source function, this will handle finding new line

characters. This will call receive on the provided socket repeatedly until a new line is found

Parameters

socket (luasocket.udp) –

Returns

():string,string

Return type

function