1 /**
2 Singleton that connects the engine with the browser's JavaScript context in HTML5 export.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.javascript;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 /**
23 Singleton that connects the engine with the browser's JavaScript context in HTML5 export.
24 
25 The JavaScript singleton is implemented only in HTML5 export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs.
26 */
27 @GodotBaseClass struct JavaScriptSingleton
28 {
29 	enum string _GODOT_internal_name = "JavaScript";
30 public:
31 @nogc nothrow:
32 	union { godot_object _godot_object; GodotObject _GODOT_base; }
33 	alias _GODOT_base this;
34 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
35 	package(godot) __gshared bool _classBindingInitialized = false;
36 	package(godot) static struct _classBinding
37 	{
38 		__gshared:
39 		godot_object _singleton;
40 		immutable char* _singletonName = "JavaScript";
41 		@GodotName("eval") GodotMethod!(Variant, String, bool) eval;
42 	}
43 	bool opEquals(in JavaScriptSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; }
44 	JavaScriptSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
45 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
46 	mixin baseCasts;
47 	static JavaScriptSingleton _new()
48 	{
49 		static godot_class_constructor constructor;
50 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("JavaScript");
51 		if(constructor is null) return typeof(this).init;
52 		return cast(JavaScriptSingleton)(constructor());
53 	}
54 	@disable new(size_t s);
55 	/**
56 	Execute the string `code` as JavaScript code within the browser window. This is a call to the actual global JavaScript function `eval()`.
57 	If `use_global_execution_context` is `true`, the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment.
58 	*/
59 	Variant eval(StringArg0)(in StringArg0 code, in bool use_global_execution_context = false)
60 	{
61 		checkClassBinding!(typeof(this))();
62 		return ptrcall!(Variant)(_classBinding.eval, _godot_object, code, use_global_execution_context);
63 	}
64 }
65 /// Returns: the JavaScriptSingleton
66 @property @nogc nothrow pragma(inline, true)
67 JavaScriptSingleton JavaScript()
68 {
69 	checkClassBinding!JavaScriptSingleton();
70 	return JavaScriptSingleton(JavaScriptSingleton._classBinding._singleton);
71 }