Command Guide
LeviLamina provides an easy-to-use command registration system, divided into compile-time and runtime registration. This guide only introduces the compile-time command registration system. If you want to implement your own scripting engine, runtime command registration might be useful for you. Before this guide includes a section on runtime command registration, you can refer to the implementation of LegacyScriptEngine or the CommandTest in LeviLamina. Additionally, LegacyScriptEngine is a scripting engine that has existed since LiteLoaderBDS v1, and many of its approaches are now outdated.
Usage
- Include the necessary header files:
C++ 1 2
#include "ll/api/command/CommandHandle.h" #include "ll/api/command/CommandRegistrar.h" - Call the
CommandRegistrar::getInstance().getOrCreateCommandmethod to obtain or create a command and assign it toauto& command. - Call
command.overloadto overload the command. If you don't need a command that accepts parameters, you can omit the template parameters, for example:command.overload(). - Use the
requiredmethod to add a mandatory parameter. This method and theoptionalmethod require passing the variable names from the corresponding structure. Use theoptionalmethod to add an optional parameter, but ensure to check whether the user has provided it. Calltextto add a subcommand. Other methods can be referenced inll/api/command/Overload.hand through Intellisense. - Call
executeto pass in the command's callback function. The callback function parameters can be referenced in the example below.
Example
| C++ | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
In this example, we define a structure named NewCommand, which stores the command parameters. Using the
getOrCreateCommand method, we create a command named new. Through overload method, we overload a subcommand
named text,
along with an enumeration, a string, and an integer parameter. The in-game usage appears as follows:
| Text Only | |
|---|---|
1 | |