diff options
| author | t <t@tjp.lol> | 2026-06-07 21:56:51 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-06-07 21:56:57 -0600 |
| commit | 75dedacfbeab1fea281d1bce124b920dcf878844 (patch) | |
| tree | be1f46a59979d7cafeb12fef7865c6603bcc639d /src/lua_bridge.zig | |
| parent | eb4179f9958deeae408a0a06b1f8ae6437e089db (diff) | |
further libpanto public API name cleanup
Diffstat (limited to 'src/lua_bridge.zig')
| -rw-r--r-- | src/lua_bridge.zig | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lua_bridge.zig b/src/lua_bridge.zig index 444cedc..9276e1d 100644 --- a/src/lua_bridge.zig +++ b/src/lua_bridge.zig @@ -262,7 +262,7 @@ pub fn pushJsonAsLua( } /// Read a tool handler's return value at `idx` and convert it into an -/// owned `[]panto.ResultPart`. Two accepted shapes: +/// owned `panto.ResultParts`. Two accepted shapes: /// /// * a plain string -> one `.text` part; /// * a table `{ text = "...", attachments = { { media_type = "...", @@ -275,14 +275,14 @@ pub fn readHandlerResult( L: *c.lua_State, idx: c_int, allocator: Allocator, -) BridgeError![]panto.ResultPart { +) BridgeError!panto.ResultParts { const ty = c.lua_type(L, idx); if (ty == T_STRING) { var len: usize = 0; const ptr = c.lua_tolstring(L, idx, &len); if (ptr == null) return BridgeError.BadHandlerReturn; - return ((panto.ResultParts.fromText(allocator, ptr[0..len]) catch - return BridgeError.OutOfMemory).items); + return panto.ResultParts.fromText(allocator, ptr[0..len]) catch + return BridgeError.OutOfMemory; } if (ty != T_TABLE) return BridgeError.BadHandlerReturn; return readHandlerResultTable(L, idx, allocator); @@ -315,7 +315,7 @@ fn readHandlerResultTable( L: *c.lua_State, idx: c_int, allocator: Allocator, -) BridgeError![]panto.ResultPart { +) BridgeError!panto.ResultParts { var parts: std.ArrayList(panto.ResultPart) = .empty; errdefer { for (parts.items) |p| p.deinit(allocator); @@ -372,7 +372,8 @@ fn readHandlerResultTable( } } - return parts.toOwnedSlice(allocator) catch BridgeError.OutOfMemory; + const items = parts.toOwnedSlice(allocator) catch return BridgeError.OutOfMemory; + return .{ .items = items }; } // --------------------------------------------------------------------------- @@ -796,9 +797,9 @@ test "handler invocation: input parsed, result captured" { } const result = try readHandlerResult(L, -1, std.testing.allocator); - defer (panto.ResultParts{ .items = result }).deinit(std.testing.allocator); - try std.testing.expectEqual(@as(usize, 1), result.len); - try std.testing.expectEqualStrings("got: hello", result[0].text); + defer result.deinit(std.testing.allocator); + try std.testing.expectEqual(@as(usize, 1), result.items.len); + try std.testing.expectEqualStrings("got: hello", result.items[0].text); } test "readHandlerResult: table with text and attachments" { @@ -821,13 +822,13 @@ test "readHandlerResult: table with text and attachments" { } const result = try readHandlerResult(L, -1, std.testing.allocator); - defer (panto.ResultParts{ .items = result }).deinit(std.testing.allocator); - try std.testing.expectEqual(@as(usize, 3), result.len); - try std.testing.expectEqualStrings("see image", result[0].text); - try std.testing.expectEqualStrings("image/png", result[1].media.media_type.?); - try std.testing.expectEqualStrings("AAA=", result[1].media.data); - try std.testing.expectEqualStrings("application/pdf", result[2].media.media_type.?); - try std.testing.expectEqualStrings("BBB=", result[2].media.data); + defer result.deinit(std.testing.allocator); + try std.testing.expectEqual(@as(usize, 3), result.items.len); + try std.testing.expectEqualStrings("see image", result.items[0].text); + try std.testing.expectEqualStrings("image/png", result.items[1].media.media_type.?); + try std.testing.expectEqualStrings("AAA=", result.items[1].media.data); + try std.testing.expectEqualStrings("application/pdf", result.items[2].media.media_type.?); + try std.testing.expectEqualStrings("BBB=", result.items[2].media.data); } test "handler crash: error message surfaces via xpcall traceback hook" { |
