Oolite
Loading...
Searching...
No Matches
OOJSScript.h
Go to the documentation of this file.
1/*
2
3OOJSScript.h (QuickJS-ng)
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 JSValue _jsSelf; // Owned.
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
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 outResult may be NULL; if not, it is owned by the caller.
59*/
60- (BOOL)callMethod:(JSAtom)methodID
61 inContext:(JSContext*)context
62 withArguments:(JSValueConst*)argv
63 count:(int)argc
64 result:(JSValue*)outResult;
65
66- (id)propertyWithID:(JSAtom)propID inContext:(JSContext*)context;
67// Set a property which can be modified or deleted by the script.
68- (BOOL)setProperty:(id)value withID:(JSAtom)propID inContext:(JSContext*)context;
69// Set a special property which cannot be modified or deleted by the script.
70- (BOOL)defineProperty:(id)value withID:(JSAtom)propID inContext:(JSContext*)context;
71
72- (id)propertyNamed:(NSString*)name;
73- (BOOL)setProperty:(id)value named:(NSString*)name;
74- (BOOL)defineProperty:(id)value named:(NSString*)name;
75
76@end
77
78@interface OOScript (JavaScriptEvents)
79
80// For simplicity, calling methods on non-JS scripts works but does nothing.
81- (BOOL)callMethod:(JSAtom)methodID
82 inContext:(JSContext*)context
83 withArguments:(JSValueConst*)argv
84 count:(int)argc
85 result:(JSValue*)outResult;
86
87@end
88
89void InitOOJSScript(JSContext* context, JSValueConst global);
90
91// Frees the compiled scripts kept for reuse. Call before destroying the context.
92void OOJSScriptDestroyCompiledScripts(JSContext* context);
static NSString *const kLocalManifestProperty
Definition OOJSScript.h:28
void OOJSScriptDestroyCompiledScripts(JSContext *context)
Definition OOJSScript.m:637
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
NSArray * scriptStack()
Definition OOJSScript.m:283
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101
NSString * description
Definition OOJSScript.h:35
JSObject * _jsSelf
Definition OOJSScript.h:32
NSString * name
Definition OOJSScript.m:108