Oolite
Loading...
Searching...
No Matches
OOJSScript.h
Go to the documentation of this file.
1/*
2
3OOJSScript.h (QuickJS-ng proof of concept)
4
5Minimal JavaScript script loader: enough to load a world script and call its
6event handlers. The full OOJSScript (manifest properties, script caching,
7OOScript subclassing) is ported in a later phase.
8
9Oolite
10Copyright (C) 2004-2013 Giles C Williams and contributors
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25MA 02110-1301, USA.
26
27*/
28
29#import "OOJavaScriptEngine.h"
30
31@interface OOJSScript : NSObject {
32@private
33 JSValue _jsSelf; // Owned; freed in -dealloc.
34 NSString* _name;
35 NSString* _version;
36 NSString* _path;
37}
38
39// Returns nil (after logging) if the script cannot be loaded or its top level throws.
40+ (id)scriptWithPath:(NSString*)path;
41- (id)initWithPath:(NSString*)path;
42
44
45- (NSString*)name;
46- (NSString*)version;
47- (NSString*)displayName;
48
49- (JSValueConst)scriptObject;
50
51/* Call a method of the script object with the script as this, as
52 -[OOJSScript callMethod:...] did. Returns NO if the method does not exist
53 or throws. *outResult, if requested, is owned by the caller.
54*/
55- (BOOL)callMethodNamed:(NSString*)methodName
56 withArguments:(JSValueConst*)argv
57 count:(int)argc
58 result:(JSValue*)outResult;
59
60@end
61
62void InitOOJSScript(JSContext* context, JSValueConst global);
void InitOOJSScript(JSContext *context, JSValueConst global)
Definition OOJSScript.m:613
NSString * _path
Definition OOJSScript.h:36
NSString * version
Definition OOJSScript.m:113
NSString * displayName()
Definition OOJSScript.m:118
NSString * _version
Definition OOJSScript.h:35
JSValueConst scriptObject()
Definition OOJSScript.m:125
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101
JSObject * _jsSelf
Definition OOJSScript.h:32
NSString * name
Definition OOJSScript.m:108
NSString * _name
Definition OOJSScript.h:34