1 /** 2 A script implemented in the GDScript programming language. 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.gdscript; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.script; 25 /** 26 A script implemented in the GDScript programming language. 27 28 The script extends the functionality of all objects that instance it. 29 $(D _new) creates a new instance of the script. $(D GodotObject.setScript) extends an existing object, if that object's class matches one of the script's base classes. 30 */ 31 @GodotBaseClass struct GDScript 32 { 33 package(godot) enum string _GODOT_internal_name = "GDScript"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ Script _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("get_as_byte_code") GodotMethod!(PoolByteArray) getAsByteCode; 44 @GodotName("new") GodotMethod!(Variant, GodotVarArgs) _new; 45 } 46 /// 47 pragma(inline, true) bool opEquals(in GDScript other) const 48 { return _godot_object.ptr is other._godot_object.ptr; } 49 /// 50 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 51 { _godot_object.ptr = n; return null; } 52 /// 53 pragma(inline, true) bool opEquals(typeof(null) n) const 54 { return _godot_object.ptr is n; } 55 /// 56 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 57 mixin baseCasts; 58 /// Construct a new instance of GDScript. 59 /// Note: use `memnew!GDScript` instead. 60 static GDScript _new() 61 { 62 static godot_class_constructor constructor; 63 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GDScript"); 64 if(constructor is null) return typeof(this).init; 65 return cast(GDScript)(constructor()); 66 } 67 @disable new(size_t s); 68 /** 69 Returns byte code for the script source code. 70 */ 71 PoolByteArray getAsByteCode() const 72 { 73 checkClassBinding!(typeof(this))(); 74 return ptrcall!(PoolByteArray)(GDNativeClassBinding.getAsByteCode, _godot_object); 75 } 76 /** 77 Returns a new instance of the script. 78 For example: 79 80 81 var MyClass = load("myclass.gd") 82 var instance = MyClass.new() 83 assert(instance.get_script() == MyClass) 84 85 86 */ 87 Variant _new(VarArgs...)(VarArgs varArgs) 88 { 89 Array _GODOT_args = Array.make(); 90 foreach(vai, VA; VarArgs) 91 { 92 _GODOT_args.append(varArgs[vai]); 93 } 94 String _GODOT_method_name = String("new"); 95 return this.callv(_GODOT_method_name, _GODOT_args); 96 } 97 }