···3939 configuration. The table has the following required fields:
40404141 - *server*: string, the server URL
4242- - *user*: string, username used in SASL
4342 - *nick*: string, nickname to identify as
4443 - *password*: string, password to use in SASL
4545- - *real_name*: string, user's real name
46444745 The following optional fields are available:
48464947 - *port*: uint16 (default=6697 (tls) or 6667), port to use for
5048 connection
4949+ - *real_name*: string, user's real name
5150 - *tls*: boolean (default=true), when true, use an encrypted connection
5151+ - *user*: string, username used in SASL
52525353*comlink.log*
5454 Accepts a string and inserts a log statement into the comlink
+2-2
docs/comlink.lua
···1818---@class ConnectionConfiguration
1919---
2020---@field server string The server to connect to, eg "chat.sr.ht"
2121----@field user string Username for server connection
2121+---@field user? string Username for server connection
2222---@field nick string Nick to use when connecting via SASL to IRC
2323---@field password string Password for server
2424----@field real_name string Real name of user
2424+---@field real_name? string Real name of user
2525---@field tls? boolean Whether to encrypt connections
2626---@field port? number Optional port to use for server connection. Defaults to 6697 for TLS connections and 6667 for plaintext connections
2727
+27-9
src/lua.zig
···315315 lua.argCheck(lua.isTable(1), 1, "expected a table");
316316317317 // [table]
318318- var lua_type = lua.getField(1, "user"); // [table,string]
319319- lua.argCheck(lua_type == .string, 1, "expected a string for field 'user'");
320320- const user = lua.toString(-1) catch unreachable;
321321- lua.pop(1); // [table]
322322-323323- lua_type = lua.getField(1, "nick"); // [table,string]
318318+ var lua_type = lua.getField(1, "nick"); // [table,string]
324319 lua.argCheck(lua_type == .string, 1, "expected a string for field 'nick'");
325320 const nick = lua.toString(-1) catch unreachable;
326321 lua.pop(1); // [table]
327322323323+ lua_type = lua.getField(1, "user"); // [table,string]
324324+ const user: []const u8 = switch (lua_type) {
325325+ .nil => blk: {
326326+ lua.pop(1); // [table]
327327+ break :blk nick;
328328+ },
329329+ .string => blk: {
330330+ const val = lua.toString(-1) catch "";
331331+ lua.pop(1); // [table]
332332+ break :blk val;
333333+ },
334334+ else => lua.raiseErrorStr("expected a string for field 'user'", .{}),
335335+ };
336336+328337 lua_type = lua.getField(1, "password"); // [table, string]
329338 lua.argCheck(lua_type == .string, 1, "expected a string for field 'password'");
330339 const password = lua.toString(-1) catch unreachable;
331340 lua.pop(1); // [table]
332341333342 lua_type = lua.getField(1, "real_name"); // [table, string]
334334- lua.argCheck(lua_type == .string, 1, "expected a string for field 'real_name'");
335335- const real_name = lua.toString(-1) catch unreachable;
336336- lua.pop(1); // [table]
343343+ const real_name: []const u8 = switch (lua_type) {
344344+ .nil => blk: {
345345+ lua.pop(1); // [table]
346346+ break :blk nick;
347347+ },
348348+ .string => blk: {
349349+ const val = lua.toString(-1) catch "";
350350+ lua.pop(1); // [table]
351351+ break :blk val;
352352+ },
353353+ else => lua.raiseErrorStr("expected a string for field 'real_name'", .{}),
354354+ };
337355338356 lua_type = lua.getField(1, "server"); // [table, string]
339357 lua.argCheck(lua_type == .string, 1, "expected a string for field 'server'");