Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
OOJSScript.h
Go to the documentation of this file.
1/*
2
3OOJSScript.h
4
5JavaScript support for Oolite
6Copyright (C) 2007-2013 David Taylor and Jens Ayton.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25
26#import "OOScript.h"
28
29static NSString * const kLocalManifestProperty = @"oolite_manifest_identifier";
30
32{
33@private
34 JSObject *_jsSelf;
36 NSString *name;
37 NSString *description;
38 NSString *version;
39 NSString *filePath;
43
44+ (id) scriptWithPath:(NSString *)path properties:(NSDictionary *)properties;
45
46- (id) initWithPath:(NSString *)path properties:(NSDictionary *)properties;
47
48+ (OOJSScript *) currentlyRunningScript;
49+ (NSArray *) scriptStack;
50
51/* External manipulation of acrtive script stack. Used, for instance, by
52 timers. Failing to balance these will crash!
53 Passing a nil script is valid for cases where JS is used which is not
54 attached to a specific script.
55*/
56+ (void) pushScript:(OOJSScript *)script;
57+ (void) popScript:(OOJSScript *)script;
58
59/* Call a method.
60 Requires a request on context.
61 outResult may be NULL.
62*/
63- (BOOL) callMethod:(jsid)methodID
64 inContext:(JSContext *)context
65 withArguments:(jsval *)argv count:(intN)argc
66 result:(jsval *)outResult;
67
68- (id) propertyWithID:(jsid)propID inContext:(JSContext *)context;
69// Set a property which can be modified or deleted by the script.
70- (BOOL) setProperty:(id)value withID:(jsid)propID inContext:(JSContext *)context;
71// Set a special property which cannot be modified or deleted by the script.
72- (BOOL) defineProperty:(id)value withID:(jsid)propID inContext:(JSContext *)context;
73
74- (id) propertyNamed:(NSString *)name;
75- (BOOL) setProperty:(id)value named:(NSString *)name;
76- (BOOL) defineProperty:(id)value named:(NSString *)name;
77
78@end
79
80
81@interface OOScript (JavaScriptEvents)
83// For simplicity, calling methods on non-JS scripts works but does nothing.
84- (BOOL) callMethod:(jsid)methodID
85 inContext:(JSContext *)context
86 withArguments:(jsval *)argv count:(intN)argc
87 result:(jsval *)outResult;
88
89@end
90
91
92void InitOOJSScript(JSContext *context, JSObject *global);
93
void InitOOJSScript(JSContext *context, JSObject *global)
Definition OOJSScript.m:663
static NSString *const kLocalManifestProperty
Definition OOJSScript.h:29
NSString * version
Definition OOJSScript.h:39
NSString * description
Definition OOJSScript.h:38
JSObject * _jsSelf
Definition OOJSScript.h:35
OOWeakReference * weakSelf
Definition OOJSScript.h:42
NSString * filePath
Definition OOJSScript.h:40
NSString * name
Definition OOJSScript.h:37