From cebb280fe546190e55e071b6adbf37cd47950f34 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Mon, 11 May 2026 15:07:55 -0500 Subject: initial commit --- runtime/lua/core/commands.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 runtime/lua/core/commands.lua (limited to 'runtime/lua/core/commands.lua') diff --git a/runtime/lua/core/commands.lua b/runtime/lua/core/commands.lua new file mode 100644 index 0000000..2aa484d --- /dev/null +++ b/runtime/lua/core/commands.lua @@ -0,0 +1,41 @@ +local M = {} + +function M.define(state, name, fn) + state.commands[name] = fn +end + +function M.bind(state, key, command_name) + state.keymap[key] = command_name +end + +function M.call(state, name, ...) + local fn = state.commands[name] + if not fn then + return false, "Unknown command: " .. tostring(name) + end + + local ok, err = pcall(fn, ...) + if not ok then + return false, tostring(err) + end + + return true +end + +function M.bind_fn(state, key, fn) + if type(key) ~= "string" or key == "" then + return false, "key must be a non-empty string" + end + if type(fn) ~= "function" then + return false, "bind_fn requires a function" + end + + local name = string.format("anon:%d", state.next_anon_command_id) + state.next_anon_command_id = state.next_anon_command_id + 1 + + state.commands[name] = fn + state.keymap[key] = name + return true +end + +return M -- cgit v1.3.1