CONSOLE_CMD = {}

addhook("parse","AM.Console")
function AM.Console(txt)
	local s, sp = txt:split()
	local command_name = s[1]
	local command = CONSOLE_CMD[command_name]
	if command then
		return ProtectedCall(command, txt, s, sp, #s) or 2
	end
end

function CreateConsole(name)
	return function (code)
		local f, e = loadstring("return function (txt,s,pos,args) "..code.."; end")
		if f then
			CONSOLE_CMD[name] = f()
		else
			error_get("CONSOLE CMD ERR ("..name.."): "..e)
		end
	end
end