Oolite 1.91.0.7644-241112-7f5034b
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
29#import "OOCocoa.h"
30#include <jsapi.h>
31
32
33@interface OOJSFunction: NSObject
34{
35@private
36 JSFunction *_function;
37 NSString *_name;
38}
39
40- (id) initWithFunction:(JSFunction *)function context:(JSContext *)context;
41- (id) initWithName:(NSString *)name
42 scope:(JSObject *)scope // may be NULL, in which case global object is used.
43 code:(NSString *)code // full JS code for function, including function declaration.
44 argumentCount:(NSUInteger)argCount
45 argumentNames:(const char **)argNames
46 fileName:(NSString *)fileName
47 lineNumber:(NSUInteger)lineNumber
48 context:(JSContext *)context; // may be NULL. If not null, must be in a request.
49
50- (NSString *) name;
51- (JSFunction *) function;
52- (jsval) functionValue;
53
54// Raw evaluation. Context may not be NULL and must be in a request.
55- (BOOL) evaluateWithContext:(JSContext *)context
56 scope:(JSObject *)jsThis
57 argc:(uintN)argc
58 argv:(jsval *)argv
59 result:(jsval *)result;
60
61// Object-wrapper evaluation.
62- (id) evaluateWithContext:(JSContext *)context
63 scope:(id)jsThis
64 arguments:(NSArray *)arguments;
65
66// As above, but converts result to a boolean.
67- (BOOL) evaluatePredicateWithContext:(JSContext *)context
68 scope:(id)jsThis
69 arguments:(NSArray *)arguments;
70
71@end
JSFunction * _function
NSString * _name