Navigation:  Programing model >

Advanced script

Previous pageReturn to chapter overviewNext page

Introduced with INM 3.4 the advanced script model gives the script author new powerful tools to control parameters giving as arguments to the script. This makes it possible to make Lua scripts that have the same look and feel like native monitor types.

Reserved function names

There are two reserved function names, used by INM to query information. These function names can not be used for any other purpose.

OnConfigure

This function is called by INM to have the script populate a LuaScriptConfigurator class instance. The information is then used to create a user interface for the script. The name of the instance must be "Config" (note that casing) so INM may find it in the Lua stack when the function returns.

OnEnumerate

Each field in the user interface can be enumerated, INM calls the OnEnumerate function to have the script populate a data strcture, LuaScriptEnumResult, with values the user can select. The OnEnumerate have one parameter, sFieldToEnum, that is used by the script to determin which field/argument to provide enumeration results for. The returned instance must be named "Enum" (note the casing).

The entry point

The advanced script model requires the OnConfigure function to set the name of the entry point function. This function is called by INM to start the execution of the script. The name of the entry point is by default "main" but can be set by the programmer to any name except the reserved function names.

Example

 

-- This function is called by INM when enumerating a field

 

function OnEnumerate(sFieldToEnum)

 

 -- The variable returned must be called "Config" so INM can find it.

 Enum = LuaScriptEnumResult()

 

 -- Second argument

 if sFieldToEnum == "Argument 2" then

         Enum:Add("First value")

         Enum:Add("Second value")

         Enum:Add("Third value")

 end

 

 return Enum

end

 

-- This function is called by INM to retrieve a script configuration

 

function OnConfigure()

 

 -- The variable returned must be called "Config" so INM can find it.

 Config = LuaScriptConfigurator()

 

 -- Author.

 Config:SetAuthor("My name")

 

 -- Description.

 Config:SetDescription("Description of the script, including usage, parameters etc")

 

 -- Minimum build version of INM, set to zero for if no specific build version is required.

 Config:SetMinBuildVersion(0)

 

 -- Script version (major/minor)

 Config:SetScriptVersion(1,0)

 

 -- A parameter configuration, add them in the order the script is extracting them.

 Config:AddArgument("Argument 1","This is the description of the first argument",LuaScriptConfigurator.CHECK_NOT_EMPTY)

 

 -- Add another parameter, a select box with 3 values.

 Config:AddArgument("Argument 2","This is the description of the second argument",LuaScriptConfigurator.CHECK_NOT_EMPTY+LuaScriptConfigurator.ENUM_AVAIL)

 

 

 -- Set the entry point, this is the function called by INM

 Config:SetEntryPoint("main")

 

 -- Done with configuration, return the object

 return Config

end

 

-- This is the entry point

 

function main()

 

 sFirstArgument = GetArgument(0)

 sSecondArgument = GetArgument(1)

 

 SetExitStatus("OK",true)

 

end