added page

That_One_Nerd 2023-03-16 12:00:59 -04:00
parent 163af74a03
commit d1e874ed47

53
Commands.md Normal file

@ -0,0 +1,53 @@
# Overview
Commands are methods inside a [module](Modules) that the shell will execute when a command that fits its module ID (if applicable) and name ID is run. A command can have as many parameters as required and the types for those parameters vary.
## How to Use
Commands must be in a [module](Modules) to be recognized. Any commands not inside their respective modules will be ignored. Commands are declared by applying the `CommandAttribute` attribute in the namespace `SrcMod.Shell.Modules.ObjectModels` to a method. The method can be static. The return type must be `void` and all parameters must have the following types:
| Type |
|-|
| `sbyte` (`System.SByte`) |
| `byte` (`System.Byte`) |
| `short` (`System.Int16`) |
| `ushort` (`System.UInt16`) |
| `int` (`System.Int32`) |
| `uint` (`System.UInt32` |
| `long` (`System.Int64`) |
| `ulong` (`System.UInt64`) |
| `System.Int128` |
| `System.UInt128` |
| `nint` (`System.IntPtr`) |
| `nuint` (`System.UIntPtr`) |
| `System.Half` |
| `float` (`System.Single`) |
| `double` (`System.Double`) |
| `decimal` (`System.Decimal`) |
| `char` (`System.Char`) |
| `System.DateOnly` |
| `System.DateTime` |
| `System.DateTimeOffset` |
| `System.Guid` |
| `System.TimeOnly` |
| `System.TimeSpan` |
Here is an example:
```csharp
// Used for the `CommandAttribute` and `ModuleAttribute`.
using SrcMod.Shell.Modules.ObjectModels;
[Module("example")]
public static class ExampleModule
{
[Command("command")]
public static void ExampleCommand()
{
// Invoked by executing "example command"
}
}
```
As said earlier, commands can have parameters as long as they fit the earlier given types or can be implicitly or explicitly casted from them. During the parsing process, parameters are split by spaces (except if in quotations).
---
**Note: When using the `srcmod.dll` to add additional custom modules, the new modules will not be recognized due to a reflection bug. This will be fixed in the near future (see issue #2).**