LS2Module:Building a LavishScript 2 Module from ISXDK

From dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods
Jump to: navigation, search

This guide follows case study in updating an existing Inner Space extension with LavishScript 1 bindings, to also provide LavishScript 2 bindings: isxSQLite code changes for LavishScript 2 implementation

Include and link to LS2Module

First, set the paths in your Visual Studio project settings for the include and library files from the LS2Module SDK. At the moment these are under LS2Module\sdk1\include and LS2Module\sdk1\lib\vs10.

Then, in one source file, you can include this #pragma to link to ls2module.

#pragma comment(lib, "ls2module.lib")

And in any file which you need to reference the SDK, include ls2module.h.

#include <ls2module.h>

Retrieve and Attach the LavishScript 2 Environment

In the extension's Initialize method, before using any LS2Module SDK functionality you will need to attach the environment, by first calling ISInterface::GetLavishScript2Environment (from ISXDK), and then calling LavishScript2::ILS2Module::AttachEnvironment (from LS2Module SDK).

LavishScript2::ILS2StandardEnvironment *pLS2Environment = 0;
if (pISInterface->GetLavishScript2Environment(LS2MODULE_API_VERSION,(void**)&pLS2Environment))

  // Register our own LavishScript 2 data types!

Register your LavishScript 2 Data Types

Consume the LavishScript 2 API, in the same way as any LS2Module does. See Building data types.

Extension Shutdown

In the extension's Shutdown method, you should unregister any members you added to existing data types, and your unregister your custom data types.

Unregistering Methods and Properties will cause an exception thrown into LavishScript 2-land if one those members is already bound and then accessed.

Notable things to note for LavishScript 1 developers

  • Strings in LavishScript 2 are UTF-16, and strings in LavishScript 1 are usually UTF-8. See String Conversion for help with that.
  • Types and objects from LavishScript 1 will probably be refactored when updated for LavishScript 2 due to major design changes.
    • For example, Top-Level Objects don't exist in LavishScript 2, in favor of static Type members (which don't exist in LavishScript 1).
    • LavishScript 2 objects are also reference counted, making it easy to build collections of existing objects, pass objects by reference, and a host of other extremely useful things that drive the design of your Methods and Properties

See Also