Initializing The Javascript Engine; Defining External Library Functions - Adobe GoLive CS2 Programmer's Manual

Hide thumbs Also See for GoLive CS2:
Table of Contents

Advertisement

SDK Programmer's Guide
For Windows, structure alignment is 8 bytes.

Initializing the JavaScript engine

To determine whether a binary library is intended for access from JavaScript, GoLive checks for the
presence of the JSAEntry function. This function is defined by the
once in your library's implementation.
The JSAEntry function sets an environment pointer containing a number of function references, then
calls the JSAMain function. Your implementation of the JSAMain function registers your external library
functions with GoLive and performs any initialization tasks your extension requires.
// Call once - initializes environment and executes the JSAMain() fn.
JSA_INIT

Defining external library functions

When defining your external library's functions, use the
header file) to exchange data with the JavaScript environment. Every external C function must accept
these arguments in this order:
argc
argv
result
These arguments define a parameter block the external C function uses to exchange data with GoLive.
When GoLive calls an external function, it creates the parameter block specified by the function's
arguments and passes it to the function. The function can index elements of the argv array to retrieve
individual arguments. The function returns its result by placing it in the result pointer GoLive passes as
an argument to the external function.
When an extension calls an external library function, GoLive encapsulates the arguments passed from
JavaScript as C-language data structures. To extract its arguments from the C-language data structures
that encapsulate them, the called function must use the
details, see the GoLive CS2 SDK Programmer's Reference.
Math function example
This is a typical implementation of a mathematical function:
#include "JSA.h"
#include <math.h>
JSA_INIT;
// This function returns argv[0]E+argv[1]
static void power(int argc, JSValue *argv, JSValue returnValue)
{
double a, b, c;
a = JSAValueToDouble(argv[0]);
b = JSAValueToDouble(argv[1]);
c = pow (a, b);
JSADoubleToValue(returnValue, c);
Number of arguments in the
Array of
pointers GoLive passes as arguments to this function.
JSValue
A
pointer this function uses to return its result.
JSValue
Adobe GoLive CS2 SDK
JSValue pointer
array. (Number of arguments the function accepts.)
argv
Accessor
Using External Libraries
macro, which must appear
JSA_INIT
type (defined in the JSA.h
Functions. For a complete list and syntax
182

Advertisement

Table of Contents
loading

Table of Contents