Module: localFunctions

JavaScript functions that override functions in commonHost.js for a Ptolemy II (Nashorn) accessor host.

This file is read by JavaScript.java and evaluates the accessor in the context that includes the overrides. See also the comment in capeCodeHost.js.

Version:
  • $$Id$$
Since:
  • Ptolemy II 11.0
Author:
  • Edward A. Lee, Contributor: Christopher Brooks, Chris Shaver
Source:

Methods

(inner) convertFromToken(value, isJSON)

Convert the specified argument from a Ptolemy II Token to a JavaScript type if there is a lossless conversion. Otherwise, just return the value. A nil token results in returning null. This is a utility function, not intended for script writers to use.

Parameters:
Name Type Description
value

The token to convert.

isJSON

True if the token being converted comes from a source with type JSON, in which case, if the value is a string, the string will be parsed.

Source:

(inner) convertToJSArray(array)

Convert the specified object to a native JavaScript array. This is useful when you have constructed an Object[] in Java and you wish to pass it to the JavaScript world and have it treated as an array. Without this function, it will be treated as an ordinary object that happens to have fields '0', '1', etc.

Parameters:
Name Type Description
array

The array to convert.

Source:

(inner) convertToToken(value, isJSON)

Convert the specified argument to a Ptolemy II Token. This is a utility function, not intended for script writers to use.

Parameters:
Name Type Description
value

The JavaScript value to convert.

isJSON

If the destination type is JSON, then return a StringToken containing the results of JSON.stringify().

Source:

(inner) evaluateCode(accessorName, code, accessorClass)

Evaluate the specified code in the current context.

Parameters:
Name Type Description
accessorName

The name to give to the accessor.

code

The code to evaluate.

accessorClass

The accessor class, if known.

Source:

(inner) getParameter(name)

Get data from a parameter.

Parameters:
Name Type Description
name

The name of the parameter (a string).

Source:
Returns:

The value of the parameter, or null if it has no value.

(inner) getResource(uri, timeout)

Get a resource, which may be a file name or a URL, and return the value of the resource as a string. If this instance of JavaScript is restricted (e.g., it is an accessor), then restrict relative file names to be in the same directory where the model is located or in a subdirectory, or if the resource begins with "$CLASSPATH/", to the classpath of the current Java process. If the accessor is not restricted, the $KEYSTORE is resolved to $HOME/.ptKeystore.

Parameters:
Name Type Description
uri

A specification for the resource.

timeout

The timeout in milliseconds.

Source:

(inner) getTopLevelAccessors()

Get the top-level accessors in the model containing this actor.

Source:
Returns:

An array of instances of Accessor.

(inner) getTopLevelAccessorsNotSupported()

Throw an error indicating that getTopLevelAccessors is not supported.

Source:

(inner) hostStackTrace(exception)

If the stack of exception is undefined, the try to return the underlying Java stack trace, otherwise return the stack of the JavaScript exception.

Parameters:
Name Type Description
exception

The JavaScript exception.

Source:
Returns:

If stack is undefined, then try to return the underlying Java stack trace as a string. If not undefined, then return the JavaScript stack from the exception

(inner) input(name, options)

Specify an input for the accessor. The name argument is a required string, recommended to be camelCase with a leading lower-case character). The options argument can have the following fields:

  • options: An array of possible values for this input.
  • type: The data type of the input (a string). If this is not specified, then any valid JavaScript value may be provided as an input. If it is specified, it must be one of the valid data types.
  • value: A default value for the input.
  • visibility: A hint to restrict the visibility that a user has of the input This can have one of the values "none" (no visibility), "expert" (expert visibility), "noteditable" (full visibility, but not modifiable), or "full" (full visibility, the default).
Parameters:
Name Type Description
name

The name of the input.

options

The options, or null or omitted to accept the defaults.

Source:

(inner) output(name, options)

Specify an output for the accessor. The name argument is a required string, recommended to be camelCase with a leading lower-case character). The options argument can have the following fields:

  • type: The data type of the output (a string). If this is not specified, then any valid JavaScript value may be sent as an output. If it is specified, it must be one of the valid data types.
Parameters:
Name Type Description
name

The name of the output.

options

The options, or null or omitted to accept the defaults.

Source:

(inner) parameter(name, options)

Specify a parameter for the accessor. The name argument is a required string, recommended to be camelCase with a leading lower-case character). The options argument can have the following fields:

  • options: An array of possible values for this input.
  • type: The data type of the parameter (a string). If this is not specified, then any valid JavaScript value may be provided for the value. If it is specified, it must be one of the valid data types.
  • value: A default value for the parameter.
  • visibility: A hint to limit the visibility that a user has of this parameter. This can be one of "full" (the default), "expert", "noteditable", or "none", meaning full visibility, expert visibility, full visibility but without being able to change the value, and no visibility.
Parameters:
Name Type Description
name

The name of the parameter.

options

The options, or null or omitted to accept the defaults.

Source:

(inner) send(name, value, channel)

Send data to an output or an input. If the type of the output or input is JSON, then the value is converted to a JSON string using JSON.stringify(value) before sending. If you are sending to an input, the value of that input will not be changed immediately, but instead, after conclusion of the function calling send(), any input handlers registered with that input and any fire() method defined will be invoked.

Parameters:
Name Type Description
name

The name of the output or input (a string).

value

The value to send.

channel

The (optional) channel number, where null is equivalent to 0.

Source:

(inner) set(parameter, value)

Set the value of a parameter. Note that this can also be used to set the value of an input that has a default value, instead of using send(), but no input handler will be triggered.

Parameters:
Name Type Description
parameter

The parameter name (a string).

value

The value to set.

Deprecated:
  • Use setParameter() or setDefault().
Source:

(inner) setDefault(input, value)

Set the default value of an input. Note that unlike using send(), no input handler will be triggered. Also, unlike send(), the provided value will be persistent, in that once it is set, the host will store the new value along with the model.

Parameters:
Name Type Description
input

The input name (a string).

value

The value to set.

Source:

(inner) setParameter(parameter, value)

Set the value of a parameter.

Parameters:
Name Type Description
parameter

The parameter name (a string).

value

The value to set.

Source:

(inner) superSend(name, value, channel)

Invoke send() of the commonHost accessor prototype to ensure that latestOutput() works. This is a separate function so that the proxy can invoke it at the same time that it actually sends the data via the port. If the port is an input, then do nothing.

Parameters:
Name Type Description
name

The name of the output (a string).

value

The value to send.

channel

The (optional) channel number, where null is equivalent to 0.

Source: