Difference between revisions of "ISXDK:Adding a Top-Level Object"
Line 10: | Line 10: | ||
==Removing a Top Level Object== | ==Removing a Top Level Object== | ||
− | Removing a | + | Removing a TLO is basically just like adding a TLO. 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 '''UnRegisterTopLevelObjects()''' inside of '''Shutdown'''. The function to remove a TLO is [[ISInterface:RemoveTopLevelObject|pISInterface->RemoveTopLevelObject(char *Name)]]. |
===Example=== | ===Example=== | ||
void ISXTest::UnRegisterTopLevelObjects() | void ISXTest::UnRegisterTopLevelObjects() |
Revision as of 07:53, 6 September 2005
Contents
Summary
This tutorial is to help explain the basics of adding a Top-Level Object
Adding a Top Level Object
When our extension is loaded Inner Space calls the Initialize function inside of it. In our test extension we have ISXTest::Initialize call the function RegisterTopLevelObjects() to load all the TLOs into LavishScript. Inside RegisterTopLevelObjects() we use pISInterface->AddTopLevelObject(char *Name, fLSTopLevelObject Function) to load each TLO.
Example
void ISXTest::RegisterTopLevelObjects() { pISInterface->AddTopLevelObject("ISXTest",TLO_ISXTest); }
Removing a Top Level Object
Removing a TLO is basically just like adding a TLO. 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 UnRegisterTopLevelObjects() inside of Shutdown. The function to remove a TLO is pISInterface->RemoveTopLevelObject(char *Name).
Example
void ISXTest::UnRegisterTopLevelObjects() { pISInterface->RemoveTopLevelObject("ISXTest"); }
Creating a Top Level Object function
A top level objects function is where you define the behavior of a TLO.Lets look at the example below and see what each part of the a TLO is.
- bool
- This is the functions return type
- __cdecl
- This is the calling convention for LavishScript TLO functions
- TLO_ISXTest
- This is the name for our TLO function. We use TLO_ prefix for TLO functions as a standard convention, ISXTest is the name of the Top Level Object
- (int argc, char *argv[], LSTYPEVAR &Dest)
- int argc is the number of arguments given
- char *argv[] is all the arguments given
- LSTYPEVAR &Dest is an object identifier structure. It uses a data portion and a type portion. Select a type to "return", and set the data to an appropriate value for that data type. For example, a string would use "Hello World" or an int would simply use an integer value. Be sure to validate the data (e.g. make sure you're not setting the data to NULL and calling it a string!).
- return true
- returning true because it successfully set Dest.Ptr and Dest.Type
Example
bool __cdecl TLO_ISXTest(int argc, char *argv[], LSTYPEVAR &Dest) { Dest.Ptr="Hello World"; Dest.Type=pStringType; return true; }