Difference between revisions of "ISXDK:Adding a Command"
Line 9: | Line 9: | ||
} | } | ||
==Removing a command== | ==Removing a command== | ||
− | Removing a command is basically just like adding a command. When an extension gets unloaded Inner Space calls the function '''Shutdown''' that is a required part of each extension. In our test extension we call the function '''UnRegisterCommands()''' inside of '''Shutdown'''. The function to remove a command is [[ISInterface:RemoveCommand|RemoveCommand(char *Command)]]. | + | Removing a command is basically just like adding a command. When an extension gets unloaded Inner Space calls the function '''Shutdown''' that is a required part of each extension. In our test extension we call the function '''UnRegisterCommands()''' inside of '''Shutdown'''. The function to remove a command is [[ISInterface:RemoveCommand|pISInterface->RemoveCommand(char *Command)]]. |
===Example=== | ===Example=== | ||
void ISXTest::UnRegisterCommands() | void ISXTest::UnRegisterCommands() |
Latest revision as of 01:03, 5 September 2005
Contents
Summary
This tutorial is to help explain the basics of adding a command into your custom extension. A command is the same as a console program for Windows or Linux.
Adding a command
When an extension is loaded Inner Space calls the Initialize function inside of it. In our test extension we have ISXTest::Initialize call the function RegisterCommands() to load all the commands into LavishScript. Inside RegisterCommands() we use pISInterface->AddCommand(char *Command, fLSCommand Function, bool Parse=true, bool Hidden=false) to load each command.
Example
void ISXTest::RegisterCommands() { pISInterface->AddCommand("ISXTest",CMD_ISXTest,true,false); }
Removing a command
Removing a command is basically just like adding a command. When an extension gets unloaded Inner Space calls the function Shutdown that is a required part of each extension. In our test extension we call the function UnRegisterCommands() inside of Shutdown. The function to remove a command is pISInterface->RemoveCommand(char *Command).
Example
void ISXTest::UnRegisterCommands() { pISInterface->RemoveCommand("ISXTest"); }
Creating a command function
A command's function is where you tell a command what to do when it is called and what to do with any arguments it is given. Lets look at the example below and see what each part of the command is.
- int
- This is the functions return type
- __cdecl
- This is the calling convention for LavishScript command functions
- CMD_ISXTest
- This is the name for our command function. We use CMD_ prefix for command functions as a standard convention, ISXTest is the name of the command
- (int argc, char *argv[])
- int argc is the number of arguments given
- char *argv[] is all the arguments given, where argv[0] will always be the name of the command
- printf("ISXTest Sample Command");
- This is the main action our command function, its purpose is to display "ISXTest Sample Command" to the InnerSpace session console
- return 0;
- This ends our function and returns 0 to anything looking for its return value
Example
int __cdecl CMD_ISXTest(int argc, char *argv[]) { printf("ISXTest Sample Command"); return 0; }