pub struct LuaCommandProcessor;Expand description
Allows for the registration of custom console commands through the global object named commands. Similarly to event subscriptions, these don’t persist through a save-and-load cycle.
Implementations§
Source§impl LuaCommandProcessor
impl LuaCommandProcessor
Sourcepub fn commands(&self) -> HashMap<String, String>
pub fn commands(&self) -> HashMap<String, String>
Lists the custom commands registered by scripts through LuaCommandProcessor.
Sourcepub fn game_commands(&self) -> HashMap<String, String>
pub fn game_commands(&self) -> HashMap<String, String>
Lists the built-in commands of the core game. The wiki has an overview of these.
Sourcepub fn object_name(&self) -> &str
pub fn object_name(&self) -> &str
The class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
Sourcepub fn add_command(&self, function: LuaAny, help: &str, name: &str)
pub fn add_command(&self, function: LuaAny, help: &str, name: &str)
Add a custom console command.
Trying to add a command with the name of a game command or the name of a custom command that is already in use will result in an error.
This example command will register a custom event called print_tick that prints the current tick to either the player issuing the command or to everyone on the server, depending on the command parameter:
commands.add_command("print_tick", nil, function(command)
if command.player_index ~= nil and command.parameter == "me" then
game.get_player(command.player_index).print(command.tick)
else
game.print(command.tick)
end
end)
```text
This shows the usage of the table that gets passed to any function handling a custom command. This specific example makes use of the `tick` and the optional `player_index` and `parameter` fields. The user is supposed to either call it without any parameter (`"/print_tick"`) or with the `"me"` parameter (`"/print_tick me"`).Sourcepub fn remove_command(&self, name: &str) -> bool
pub fn remove_command(&self, name: &str) -> bool
Remove a custom console command.
Trait Implementations§
Source§impl Clone for LuaCommandProcessor
impl Clone for LuaCommandProcessor
Source§fn clone(&self) -> LuaCommandProcessor
fn clone(&self) -> LuaCommandProcessor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more