diff options
| author | t <t@tjp.lol> | 2026-06-01 08:21:00 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-06-01 11:20:56 -0600 |
| commit | 1beefefc69beee214430eb5bd2528a4f5692d2a8 (patch) | |
| tree | a459dbde5da17babe7d872999341d2006ebfe02e /src/lua_runtime.zig | |
| parent | 5c016cfdbcb122e2b4f0496ef946642d68953c4b (diff) | |
Rename system extension layer to base for clarity
Replace all references to the "system" layer with "base" to better reflect
its role as the foundational extension/tool layer in panto's hierarchy.
The layer hierarchy now consistently uses: project > user > base.
Includes:
- Update agent README and build.zig documentation
- Refactor tool registry and config module to support layered lookups
- Add TestHarness abstraction for cleaner test setup
- Improve JSON serialization with wire-encoded tool names
- Add glob pattern matching for tool/extension discovery
Diffstat (limited to 'src/lua_runtime.zig')
| -rw-r--r-- | src/lua_runtime.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lua_runtime.zig b/src/lua_runtime.zig index 5efadaa..fed56a8 100644 --- a/src/lua_runtime.zig +++ b/src/lua_runtime.zig @@ -354,6 +354,38 @@ pub const LuaRuntime = struct { pub fn toolCount(self: *const LuaRuntime) usize { return self.decls.items.len; } + + /// Drop every declared tool whose registered name is rejected by + /// `permits`. The handler ref is unref'd and the decl removed. + /// Returns the number of tools dropped. + /// + /// String storage for a dropped tool's name/description/schema is + /// left in `self.strings` (freed at `deinit`); only the decl entry + /// and the Lua handler ref are reclaimed eagerly. This keeps the + /// filter simple — we never need to find-and-free individual + /// strings out of the shared pool. + pub fn filterTools( + self: *LuaRuntime, + ctx: anytype, + comptime permits: fn (@TypeOf(ctx), []const u8) bool, + ) usize { + var dropped: usize = 0; + var i: usize = 0; + while (i < self.decls.items.len) { + const name = self.decls.items[i].name; + if (permits(ctx, name)) { + i += 1; + continue; + } + // Unref the handler, if present. + if (self.handlers.fetchRemove(name)) |kv| { + c.luaL_unref(self.L, lua_bridge.LUA_REGISTRYINDEX, kv.value); + } + _ = self.decls.orderedRemove(i); + dropped += 1; + } + return dropped; + } }; const source_vtable: panto.ToolSource.VTable = .{ |
