
CHAPTER 7: Integrating External Libraries Defining entry points for indirect access 206
Defining entry points for indirect access
The C-client object interface for external libraries allows your C or C++ shared-library code to define,
create, use, and manage JavaScript objects.
The following entry points are required if you wish to use the object interface:
Shared-library function API
Your shared-library C/C++ code defines its interface to JavaScript in two sets of functions, collected in
SoServerInterface
and SoObjectInterface function-pointer structures.
Return values from most functions are integer constants. The error code
kESErrOK == 0 indicates success.
ESClientInterface()
int ESClientInterface (SoCClient_e kReason, SoServerInterface* pServer,
SoHServer hServer)
kReason
The reason for this call, one of these constants:
X kSoCClient_init: The function is being called for initialization upon load.
X kSoCClient_term.: The function is being called for termination upon unload.
pServer
A pointer to an SoServerInterface containing function pointers for the entry points,
which enable the shared-library code to call into JavaScript to create and access
JavaScript classes and objects.
The shared-library code is responsible for storing this structure between the
initialization and termination call, and retrieving it to access the functions.
hServer
An SoHServer reference for this shared library. The server is an object factory that
creates and manages SoHObject
objects.
The shared-library code is responsible for storing this structure between the
initialization and termination calls. You must pass it to taggedDataInit()
and
taggedDataFree()
.
Your library must define this global function in order to use the object interface to JavaScript. The
function is called twice in each session, immediately upon loading the library, and again when
unloading it.
Returns an error code,
kESErrOK on success.
ESMallocMem()
void * ESMallocMem ( size_t nbytes)
nbytes
The number of bytes to allocate.
Provides a memory allocation routine to be used by JavaScript for managing memory associated
with the library’s objects.
Returns a pointer to the allocated block of memory.
Comentarios a estos manuales