winccoa-manager
    Preparing search index...

    Class WinccoaCtrlScriptCache

    Helper class for caching multiple instances of a CTRL script (initialized for different users if necessary). This helps improving performance when the same CTRL script is called multiple times by the same or different users.

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Constructor.

      Parameters

      • manager: WinccoaManager

        Manager instance which is used for two things:

        Note that this instance only keeps a weak reference to manager which can become invalid if manager gets freed by the garbage collector (see isValid).

      • ctrlCode: string

        CTRL code of the scripts that will be returned by getScript.

      • Optionalname: string

        Optional name for the script that will be shown in error messages.

      • Optionalcallback: WinccoaCtrlCallback

        If given, this function can be called from the CTRL script by using the CTRL function callbackToJavaScript(). See WinccoaCtrlCallback for details and examples.

      Returns WinccoaCtrlScriptCache

      import {
      WinccoaCtrlScriptCache,
      WinccoaCtrlType,
      WinccoaManager,
      } from 'winccoa-manager';
      const winccoa = new WinccoaManager();

      async function scriptCacheTest() {
      // store the script in a cache for repeated use
      const cache = new WinccoaCtrlScriptCache(
      winccoa,
      `double simpleArgs(int x, double y, string s)
      {
      return (x * y) + s.length();
      }`,
      'simple args cache example'
      );

      for (let i = 1; i <= 20; i++) {
      const result = (await cache
      .getScript()
      .start(
      'simpleArgs',
      [i, 34.56, 'some text'],
      [WinccoaCtrlType.int, WinccoaCtrlType.double, WinccoaCtrlType.string],
      )) as number;
      console.log(result);
      }
      }

      void scriptCacheTest();

    Properties

    ctrlCode: string

    CTRL code of the scripts that will be returned by getScript.

    name?: string

    Optional name for the script that will be shown in error messages.

    Methods

    • Indicates whether this instance is valid (that is, whether the weak reference to its manager is still valid).

      Returns boolean

    • Creates an instance of WinccoaCtrlScriptCache containing CTRL code loaded from a file.

      Parameters

      • manager: WinccoaManager

        Manager instance which is used for two things:

        Note that this instance only keeps a weak reference to manager which can become invalid if manager gets freed by the garbage collector (see isValid).

      • fileName: string

        Name of the CTRL file to load. If this is a relative path, fileName is searched in all script directories in the usual order. If this is an absolute path, it is used unchanged. The content of the CTRL file must be encoded using UTF-8. If fileName has no extension, .ctl will be appended.

        Note that the CTRL code must not be encyrpted (files with extension .ctc cannot be loaded).

      • Optionalname: string

        Optional name for the script that will be shown in error messages. If not given, fileName is used in error messages.

      • Optionalcallback: WinccoaCtrlCallback

        If given, this function can be called from the CTRL script by using the CTRL function callbackToJavaScript(). See WinccoaCtrlCallback for details and examples.

      Returns Promise<WinccoaCtrlScriptCache>

      Instance containing the CTRL code loaded from fileName.

      • WinccoaError when manager is not the correct type or ctrlCode contains a syntax error.
      • Errors from node:fs when fileName cannot be found or opened.
      import { WinccoaCtrlScriptCache, WinccoaManager } from 'winccoa-manager';
      const winccoa = new WinccoaManager();

      async function loadScriptTest() {
      const script = await WinccoaCtrlScriptCache.fromFile(
      winccoa,
      'myScript' // CTRL file myScript.ctl must exist in a script directory
      );
      ...
      }