LS2:Module

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

A Module is an extension to LavishScript 2, which may provide and consume types and events, register and execute scripts, and other functions which are available through the LavishScript 2 Module API for C++.

How is a LavishScript or LavishScript 2 Module different from an Inner Space Extension?
  • An Inner Space extension is a superset of LavishScript Module functionality.
  • Aside from the LavishScript API, an Inner Space Extension also consumes other API, such as Services or LavishGUI, which are not available to a pure module.

Getting Started with a sample Module

First, you will need the LS2Module SDK. The SDK is built for Visual Studio 2010, so if you do not have Visual Studio 2010 you will need to get it. Visual Studio 2012 is not sufficient, as libraries are currently only provided for Visual Studio 2010. Visual Studio 2012 support is pending Windows XP support (Visual Studio 2012 released without Windows XP targeting support).

Building LS2M-Foo

Open the LS2M-Foo.vcxproj (LS2Module\sdk1\samples\LS2M-Foo\LS2M-Foo.vcxproj) project file in Visual Studio.

The LS2M-Foo sample is designed to compile "out of the box", but you may need to configure the path to the LS2Module SDK for the project. To do so, right click the project and select Properties. In the Configuration Properties under VC++ Directories, set the Include Directories to include your LS2Module\sdk1\include folder, and Library Directories to include your LS2Module\sdk1\lib\vs10 folder.

Loading LS2M-Foo from C#

An example of loading the module in C#, which can be compiled by ls2csc
try
{
  LavishScript2.Module myModule = LavishScript2.Module.Register("Foo",@"c:\path\to\LS2M-Foo.dll");
  myModule.Start();
}
catch(Exception e)
{
  // exception thrown starting the module!
  System.Console.WriteLine(e.ToString());
  throw;
}

Loading LS2M-Foo from C++

An example of loading the module in C++ via the LavishScript 2 Module SDK

Obviously, this would be done by something already loaded, not by LS2M-Foo!

LavishScript2::ILS2StandardEnvironment::s_pInstance->RegisterModule(L"Foo",L"c:\\path\\to\\LS2M-Foo.dll");
LavishScript2::LS2SmartRef<LavishScript2::ILS2AvailableModule> pModule;
LavishScript2::ILS2StandardEnvironment::s_pInstance->GetModule(L"Foo",pModule);
LavishScript2::LS2SmartRef<LavishScript2::LS2Exception> pException;
if (!pModule->Start(0,pException))
{
  // LS2 exception thrown! 
  LavishScript2::LS2SmartRef<LavishScript2::ILS2String> pMessage;
  if (pException->GetString(pMessage))
  {
     // pMessage->c_str()
  }
}
else
{
  // module started!
}

See Also