summaryrefslogtreecommitdiff
path: root/runtime/lua/core/commands.lua
diff options
context:
space:
mode:
authorCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-05-11 15:07:55 -0500
committerCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-05-11 15:07:55 -0500
commitcebb280fe546190e55e071b6adbf37cd47950f34 (patch)
tree6e7a7605f8832b1c1bd7e467884a8792a5e1fab4 /runtime/lua/core/commands.lua
initial commit
Diffstat (limited to 'runtime/lua/core/commands.lua')
-rw-r--r--runtime/lua/core/commands.lua41
1 files changed, 41 insertions, 0 deletions
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