forked from BlueMountainsIO/OnsetLuaScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleFunctions_c.lua
More file actions
37 lines (35 loc) · 795 Bytes
/
ConsoleFunctions_c.lua
File metadata and controls
37 lines (35 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local commandMap = {}
local helpMap = {}
function AddConsoleCommand(name, help_or_callback, callback)
if name == nil or help_or_callback == nil then
return false
end
if type(help_or_callback) == "string" then
if type(callback) ~= "function" then
return false
end
helpMap[name] = help_or_callback
commandMap[name] = callback
else
commandMap[name] = help_or_callback
end
return true
end
AddFunctionExport("AddConsoleCommand", AddConsoleCommand)
AddEvent("OnConsoleInput", function(input)
local cmd
local args = {}
for word in input:gmatch("%w+") do
if cmd == nil then
cmd = word
else
table.insert(args, word)
end
end
if commandMap[cmd] ~= nil then
commandMap[cmd](table.unpack(args))
return true
else
print("Command '"..cmd.."' not found")
end
end)