[TOC] [Prev] [Next]

ITKJSInterp

Inherits From:
ITKInterp : NSObject

Conforms To:
NSObject (NSObject)
NSCoding (ITKInterp)

Declared in: itkJavaScript/ITKJSInterp.h

Class Description

ITKJSInterp provides the functionality of an extended JavaScript interpreter to Objective-C programs. Most of its methods are inherited from the abstract superclass ITKInterp which is defined by the itkRuntime framework.

The generic methods for evaluating scripts and accessing variables use the class ITKJSVal for wrapping JavaScript values as Objective-C objects. In some situations this generic, ITKValue-based API can be overkill, e.g. when you are running in JavaScript and just want to evaluate a script in another ITKJSInterp instance. In this case, it is easiest (and most efficient) to use a method like eval:, which avoids any conversion overhead by simply passing raw JavaScript values between interpreters.

Class Methods

mainInterp

+(ITKInterp *)mainInterp

Returns the first instance of ITKJSInterp created by the application, creating one if none exists.

Instance Methods

eval:

- (JSVal)eval:(JSVal)script

Evaluates script in the currently executing scope of the receiving interpreter and returns the result. Raises an exception if an error occurs. This method is most conveniently called from JavaScript rather than from Objective-C.

globEval:

- (JSVal)globEval:(JSVal)script

Evaluates script in the global scope of the receiving interpreter and returns the result. Raises an exception if an error occurs. This method is most conveniently called from JavaScript rather than from Objective-C.

nativeInterp

- (void *)nativeInterp

Returns the JSContext * representing the interpreter for use with the low-level JavaScript API exported by jsapi.h. The Objective-C API should be sufficient for almost every purpose, though.

unsetVariable:global:

- (void)unsetVariable:(NSString *)variable global:(BOOL)global

Deletes the variable variable from the interpreter's name space, analogous to the JavaScript delete operator. If global is YES, looks for variable in the global scope, otherwise in the currently executing scope.



[TOC] [Prev] [Next]

Copyright © 1999, AAA+ Software. All rights reserved.