an experimental irc client

lua: add channel:insert_text

rockorager.dev 948b4338 888d39f4

verified
+22
+17
src/lua.zig
··· 459 459 fn initTable(lua: *Lua, channel: *irc.Channel) void { 460 460 const fns = [_]ziglua.FnReg{ 461 461 .{ .name = "send_msg", .func = ziglua.wrap(Channel.sendMsg) }, 462 + .{ .name = "insert_text", .func = ziglua.wrap(Channel.insertText) }, 462 463 .{ .name = "name", .func = ziglua.wrap(Channel.name) }, 463 464 .{ .name = "mark_read", .func = ziglua.wrap(Channel.markRead) }, 464 465 }; ··· 493 494 .{ channel.name, msg }, 494 495 ) catch lua.raiseErrorStr("out of memory", .{}); 495 496 channel.client.queueWrite(msg_final) catch lua.raiseErrorStr("out of memory", .{}); 497 + return 0; 498 + } 499 + 500 + fn insertText(lua: *Lua) i32 { 501 + lua.argCheck(lua.isTable(1), 1, "expected a table"); // [table] 502 + lua.argCheck(lua.isString(2), 2, "expected a string"); // [table,string] 503 + const msg = lua.toString(2) catch unreachable; 504 + lua.pop(1); // [table] 505 + const lua_type = lua.getField(1, "_ptr"); // [table, lightuserdata] 506 + lua.argCheck(lua_type == .light_userdata, 2, "expected lightuserdata"); 507 + const channel = lua.toUserdata(irc.Channel, 2) catch unreachable; 508 + lua.pop(1); // [] 509 + 510 + channel.text_field.insertSliceAtCursor(msg) catch { 511 + lua.raiseErrorStr("couldn't insert text", .{}); 512 + }; 496 513 return 0; 497 514 } 498 515