Oolite
Loading...
Searching...
No Matches
OOJSFunction.h
Go to the documentation of this file.
1/*
2
3OOJSFunction.h
4
5Object encapsulating a runnable JavaScript function.
6
7
8JavaScript support for Oolite
9Copyright (C) 2007-2013 David Taylor and Jens Ayton.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24MA 02110-1301, USA.
25
26*/
27
28#import "OOFoundation.h"
29#include <jsapi.h>
30
31@interface OOJSFunction : NSObject {
32@private
33 JSFunction* _function;
34 NSString* _name;
35}
36
37- (id)initWithFunction:(JSFunction*)function context:(JSContext*)context;
38- (id)initWithName:(NSString*)name
39 scope:(JSObject*)scope // may be NULL, in which case global object is used.
40 code:(NSString*)code // full JS code for function, including function declaration.
41 argumentCount:(NSUInteger)argCount
42 argumentNames:(const char**)argNames
43 fileName:(NSString*)fileName
44 lineNumber:(NSUInteger)lineNumber
45 context:(JSContext*)context; // may be NULL. If not null, must be in a request.
46
47- (NSString*)name;
48- (JSFunction*)function;
49- (jsval)functionValue;
50
51// Raw evaluation. Context may not be NULL and must be in a request.
52- (BOOL)evaluateWithContext:(JSContext*)context
53 scope:(JSObject*)jsThis
54 argc:(uintN)argc
55 argv:(jsval*)argv
56 result:(jsval*)result;
57
58// Object-wrapper evaluation.
59- (id)evaluateWithContext:(JSContext*)context
60 scope:(id)jsThis
61 arguments:(NSArray*)arguments;
62
63// As above, but converts result to a boolean.
64- (BOOL)evaluatePredicateWithContext:(JSContext*)context
65 scope:(id)jsThis
66 arguments:(NSArray*)arguments;
67
68@end
NSString * _name
JSFunction * _function