Oolite
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
26#import "OOScript.h"
27
28static NSString* const kLocalManifestProperty = @"oolite_manifest_identifier";
29
31@private
32 JSObject* _jsSelf;
33
34 NSString* name;
35 NSString* description;
36 NSString* version;
37 NSString* filePath;
38
40}
41
42+ (id)scriptWithPath:(NSString*)path properties:(NSDictionary*)properties;
43
44- (id)initWithPath:(NSString*)path properties:(NSDictionary*)properties;
45
46+ (OOJSScript*)currentlyRunningScript;
47+ (NSArray*)scriptStack;
48
49/* External manipulation of acrtive script stack. Used, for instance, by
50 timers. Failing to balance these will crash!
51 Passing a nil script is valid for cases where JS is used which is not
52 attached to a specific script.
53*/
54+ (void)pushScript:(OOJSScript*)script;
55+ (void)popScript:(OOJSScript*)script;
56
57/* Call a method.
58 Requires a request on context.
59 outResult may be NULL.
60*/
61- (BOOL)callMethod:(jsid)methodID
62 inContext:(JSContext*)context
63 withArguments:(jsval*)argv
64 count:(intN)argc
65 result:(jsval*)outResult;
66
67- (id)propertyWithID:(jsid)propID inContext:(JSContext*)context;
68// Set a property which can be modified or deleted by the script.
69- (BOOL)setProperty:(id)value withID:(jsid)propID inContext:(JSContext*)context;
70// Set a special property which cannot be modified or deleted by the script.
71- (BOOL)defineProperty:(id)value withID:(jsid)propID inContext:(JSContext*)context;
72
73- (id)propertyNamed:(NSString*)name;
74- (BOOL)setProperty:(id)value named:(NSString*)name;
75- (BOOL)defineProperty:(id)value named:(NSString*)name;
76
77@end
78
79@interface OOScript (JavaScriptEvents)
80
81// For simplicity, calling methods on non-JS scripts works but does nothing.
82- (BOOL)callMethod:(jsid)methodID
83 inContext:(JSContext*)context
84 withArguments:(jsval*)argv
85 count:(intN)argc
86 result:(jsval*)outResult;
87
88@end
89
90void InitOOJSScript(JSContext* context, JSObject* global);
static NSString *const kLocalManifestProperty
Definition OOJSScript.h:28
void InitOOJSScript(JSContext *context, JSValueConst global)
Definition OOJSScript.m:613
OOWeakReference * weakSelf
Definition OOJSScript.h:39
NSString * version
Definition OOJSScript.m:113
NSString * filePath
Definition OOJSScript.h:37
NSString * description
Definition OOJSScript.h:35
JSObject * _jsSelf
Definition OOJSScript.h:32
NSString * name
Definition OOJSScript.m:108