EMILUA(3em)

πŸ“¦ version 0.12.1, in nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

okay bestie, welcome to EMILUA(3em) from the Emilua reference β€” this page is all about Emilua - Lua execution engine. That’s the whole name vibe. 🫢

✨ SYNOPSIS ✨

local ip = require "ip"
ip.connect(sock, resolve_results: table[, condition: function]) -> ip.address, integer

yes, that’s the whole spell β€” copy it exactly, no freestyling πŸ’…

πŸ’… DESCRIPTION πŸ’…

So this one attempts to connect a socket to one of a sequence of endpoints. It does this by repeated calls to the socket’s connect member function β€” once for each endpoint in the sequence β€” until a connection is successfully established. no cap, it’s giving β€œtry the next one until one says yes” energy. 🌈

🌸 PARAMETERS 🌸

πŸ¦‹ sock

The socket to be connected. If the socket is already open, it will be closed. heads up: closed-closed, so read that twice bestie 🫢

πŸ“ resolve_results

The return from the function get_address_info(). If the sequence is empty, the error not_found will be raised. πŸ’€

🧚 condition

A function that is called prior to each connection attempt. The signature of the function object must be:

function condition(last_error, next_address, next_port) -> boolean

The last_error parameter contains the result from the most recent connect operation. Before the first connection attempt, last_error is nil. The next parameters together specify the next endpoint to be tried. The closure should return true if the next endpoint should be tried, and false if it should be skipped. πŸŽ€

🌈 EXAMPLE 🌈

look at her go ✨

local addr, port = ip.connect(
    sock, ip.tcp.get_address_info("www.example.com", "http"),
    function(last_error, next_addr, next_port)
        if last_error then
            print("Error: " .. tostring(last_error))
        end
        print("Trying: " .. ip.tostring(next_addr, next_port))
        return true
    end
)
print("Connected to: " .. ip.tostring(addr, port))

xoxo, this page came from the Emilua 0.12.1-nixpkgs1 source/version, dated 1980-01-01. slay, go connect some sockets responsibly πŸ’œ

πŸ“¦ where this page comes from