01-30-2013, 05:44 AM
I don't quite like how command handling is done in plugins currently. I'd like to propose a change to the API that would make it easier to use, more consistent and possibly extensible to other languages.
(Sorry for the weird formatting, it's taken out from my notes text file and the forum doesn't seem to support tabs )
Current state:
==============
cPlugin handles command "adding": cPlugin:AddCommand(Command, Description, Permission)
-- used for listing commands using "/help"
cLuaCommandBinder handles command binding via cPlugin:BindCommand(Command, Permission, Function)
-- used for actual command handling
Problems:
-- Binding and Adding aren't too related - plugin can add command without binding it and bind command without adding it -> mess
-- List of commands is fragmented across cPlugin instances
Proposed solution:
==================
cPlugin won't take care of anything command-related within the API. All command-handling functions will be exported on the cPluginManager object. Therefore if we ever support another language, it will make things easier.
New API functions:
-- cPluginManager:BindCommand(Command, Permission, Function, Description)
---- Binds the command, maintains one global list of commands; knows which plugin to bind to using either the LuaState ptr or a global variable within the LuaState
-- cPluginManager:ForEachCommand(Callback)
---- Calls the callback for each command in the list, thus allowing enumeration, inspection etc.
---- function Callback(Command, Permission, Description[, PluginName?]);
-- cPluginManager:IsCommandBound(Command)
---- Returns true if a command with this name has been bound (to any plugin)
-- cPluginManager:GetCommandPermission(Command)
---- Returns the permission needed for executing the command
-- cPluginManager:ExecuteCommand(Player, Command, Parameters)
---- Executes the command, as if it was requested by the player. Checks permissions first.
-- cPluginManager:ForceExecuteCommand(Player, Command, Parameters)
---- Executes the command, as if it was requested by the player. Doesn't check permissions!
So, what do you think?
(Sorry for the weird formatting, it's taken out from my notes text file and the forum doesn't seem to support tabs )
Current state:
==============
cPlugin handles command "adding": cPlugin:AddCommand(Command, Description, Permission)
-- used for listing commands using "/help"
cLuaCommandBinder handles command binding via cPlugin:BindCommand(Command, Permission, Function)
-- used for actual command handling
Problems:
-- Binding and Adding aren't too related - plugin can add command without binding it and bind command without adding it -> mess
-- List of commands is fragmented across cPlugin instances
Proposed solution:
==================
cPlugin won't take care of anything command-related within the API. All command-handling functions will be exported on the cPluginManager object. Therefore if we ever support another language, it will make things easier.
New API functions:
-- cPluginManager:BindCommand(Command, Permission, Function, Description)
---- Binds the command, maintains one global list of commands; knows which plugin to bind to using either the LuaState ptr or a global variable within the LuaState
-- cPluginManager:ForEachCommand(Callback)
---- Calls the callback for each command in the list, thus allowing enumeration, inspection etc.
---- function Callback(Command, Permission, Description[, PluginName?]);
-- cPluginManager:IsCommandBound(Command)
---- Returns true if a command with this name has been bound (to any plugin)
-- cPluginManager:GetCommandPermission(Command)
---- Returns the permission needed for executing the command
-- cPluginManager:ExecuteCommand(Player, Command, Parameters)
---- Executes the command, as if it was requested by the player. Checks permissions first.
-- cPluginManager:ForceExecuteCommand(Player, Command, Parameters)
---- Executes the command, as if it was requested by the player. Doesn't check permissions!
So, what do you think?