Registering External Functions; Implementing Optional Termination Code; Calling C Library Functions From Javascript - Adobe GoLive CS2 Programmer's Manual

Hide thumbs Also See for GoLive CS2:
Table of Contents

Advertisement

SDK Programmer's Guide
}

Registering external functions

All external binaries must implement the JSAMain function as described here. Your implementation of
this function must register each of your external library functions with GoLive. To do so, it passes each
function's JavaScript and C-language names to the JSARegisterFunction function. For example:
void JSAEXPORT JSAMain(void)
{
JSARegisterFunction("power",power);
JSARegisterFunction("drawOval",drawOval);
}
The first argument is the name under which the function is to appear in JavaScript. The second is the name
of the function's C implementation. Both functions this example registers happen to have identical names
in JavaScript and in C, but these names do not need to match.
When the JSAMain function completes, all of the functions it registered can be called from JavaScript by
any ExtendScript extension. The functions are made accessible as the properties of an object named for
the binary module. Thus, if both of the functions in the preceding example were built into a library named
JSASample.dll (or just JSASample on Mac OS) they could be called from JavaScript as follows:
result = JSASample.power(2,4)
function drawControl(control,draw) {
if (control.name == "custom")
}

Implementing optional termination code

When a module is unloaded, GoLive calls the
performs any housekeeping tasks necessary to terminate the extension, such as setting references to
null and deallocating memory used by your external C code.

Calling C library functions from JavaScript

The name of the compiled external library file is a module name in GoLive. It is accessible as a global
variable, from the modules array, and from the module list in the JavaScript Debugger window, like any
other extension module.
For example, if the power function is part of the file Utils.dll (Windows) or Utils (Mac OS), this
function would be called from JavaScript as follows:
a = Utils.power (2,5);
Any extension can call the functions defined in an external binary. The external library is loaded on
demand the first time it is called. Subsequently, it remains in memory until the module is unloaded. The
module is unloaded when:
GoLive quits.
The user chooses the Reload Scripts palette menu item.
JSASample.drawOval (draw.getDrawInfo());
Adobe GoLive CS2 SDK
function. Your implementation of this function
JSAExit
Using External Libraries
184

Advertisement

Table of Contents
loading

Table of Contents