Server API Available to Scripts

Only a limited part of the Server API is available to Script functions. This API allows you to build simple applications. If you need to access a more powerful API, you have to switch to a standard C++ implementation.

Script can access the entire Server model through the API defined in the server model interpreter. Moreover, dynamic objects call certain callbacks that can be implemented in an Script function. See the API of the Script class IlsDynObject.

Example

function Node_beginEdition(node, status)

{

if (node.locked && (MvServer.interactor != node.locker)) {

MvServer.ReplyMessage("Cannot edit node " + node.name + ": you don’t have the lock");

return false;

}

return true;

}

The running dynamic view server is represented by a global Script variable, named MvServer, which allows you to:

  • declare some objects to the dynamic view server;

  • open a dynamic view;

  • access the current interacting user;

  • access instances stored in dictionaries.

Example

var network = new Network("TheNetwork");

MvServer.DeclObjectLabel(network, network.identifier);

Through the MvServer object, you can also call global functions declared in the application. Such functions are automatically declared as member functions of the Script class IlsMvServer.

Example

  • C++ code

ILS_GLOBAL_FUNCTION1(IlsBoolean,PrintWelcomeMessage,IlsString)

  • Script code

MvServer.PrintWelcomeMessage("Welcome");

Through the MvServer object, you can also declare new global functions (accessible from the client and the dynamic views) that are given an Script implementation. In the following example, we declare a new global function, named MyGlobalCallback, which is given an Script implementation.

Example

function MyGlobalCallback() {

...

}

 

 

function OnLoad(args)

{

MvServer.DeclGlobalCallback("MyGlobalCallback", "boolean", 0);

}

The scripts used in the context of the Script integration of Server can also access the timers API. See "Script for the Server Side" of the Reference Manual and, more specifically, the Script class IlsTimer.