Knowledge Base - Importing Public Members

iCanScript supports invoking a custom installer to add all public fields, properties and functions of an object definition into the iCanScript library.

This method of populating the iCanScript library is ideal if:

  • you are not in control of the source code (i.e. using a vendor library) or;
  • you want to add all public fields, properties and functions of your classes without tagging your source code with iCanScript custom attributes.

Understanding the Custom Installer

On every script recompile, iCanScript seeks for and invokes the void PopulateDataBase() static function of the iCS_CustomInstaller static class to populate it library.

Note: iCanScript uses runtime binding to avoid generating compilation errors if the custom installer is not present.

The signature of the iCanScript library custom installer is:

// iCanScript library custom installer class
public static class iCS_CustomInstaller {
    // Function invoked to populate the iCanScript library.
    public static void PopulateDataBase() {
        // ==> INSTALL YOUR NODES HERE <==
        ...
    }
}

The iCanScript distribution comes with a custom installer template to be use as a base for your custom installer. It is located in the editor section of the iCanScript package as show in the following diagram.

Figure 1. Extending Library with Custom Installer.
Figure 1. Extending Library with Custom Installer.

The iCS_CustomInstaller file should be used as a starting point to create your own installer. You will need to move this file into your package and modify it to specify the types to be included in the iCanScript library.

The files iCS_NETClasses and iCS_UnityClasses install all of the .NET and Unity types that come with the iCanScript distribution. Browsing those files will give you a better understanding on what needs to be done when creating your custom installer.

Modifying the Custom Installer Template

Important: It is important that you move the custom installer template file outside of the iCanScript package before you modify it. This will avoid losing your changes on subsequent iCanScript package upgrades.

Their is five sections of interest in the custom installer template, four of which you will need to modify. The following provide the details:

Figure 2. Custom Installer Template File.
Figure 2. Custom Installer Template File.

The template file that comes in the distribution is disabled. This avoids conflicts with your own custom installer on subsequent product upgrades. To activate your custom installer, you need to uncomment the definition of iCS_USE_CUSTOM_INSTALLER.

The template includes the helper function PopulateWithType(…) that fills-in the default company name, package name, and icon if they are not specified. The default values are taken from kDefaultCompanyNam e, kDefaultPackageName, and kDefaultIcon constants. Change the value of those defaults to reflect your situation.

This is were the bulk of your installer will be coded. You need to invoke the helper function PopulateWithType(…) for every type you include in the iCanScript library. Only the type information is mandatory but it is suggested that you also fill-in the description and install an icon that depicts the type. Package name and company name can also be provided if the default values do not suffice.

By default, the iCanScript custom installation template displays a message when it is invoked. This is useful to determine if the installer is properly activated. You can remove or comment out this log message once you know your installer is invoked.

The iCS_Reflection.DecodeClassInfo(…) is the main programatic interface for populating the iCanScript library. For your convenience, it is wrapped by the function PopulateWithType(…).

Details

Created : 2015-03-16 20:40:47, Last Modified : 2015-03-16 20:44:53

User Comments

Add a Comment

Search Articles

Member Login