Skip to main content

LuaCommandProcessor

Struct LuaCommandProcessor 

Source
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

Source

pub fn commands(&self) -> HashMap<String, String>

Lists the custom commands registered by scripts through LuaCommandProcessor.

Source

pub fn game_commands(&self) -> HashMap<String, String>

Lists the built-in commands of the core game. The wiki has an overview of these.

Source

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.

Source

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"`).
Source

pub fn remove_command(&self, name: &str) -> bool

Remove a custom console command.

Trait Implementations§

Source§

impl Clone for LuaCommandProcessor

Source§

fn clone(&self) -> LuaCommandProcessor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaCommandProcessor

Source§

impl Debug for LuaCommandProcessor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaCommandProcessor

Source§

fn default() -> LuaCommandProcessor

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaCommandProcessor

Source§

impl From<LuaCommandProcessor> for LuaAny

Source§

fn from(_: LuaCommandProcessor) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaCommandProcessor

Source§

impl PartialEq for LuaCommandProcessor

Source§

fn eq(&self, other: &LuaCommandProcessor) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaCommandProcessor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.