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.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.script; 24 import godot.resource; 25 import godot.reference; 26 /** 27 A script implemented in the GDScript programming language. 28 29 The script exends the functionality of all objects that instance it. 30 $(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. 31 */ 32 @GodotBaseClass struct GDScript 33 { 34 enum string _GODOT_internal_name = "GDScript"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; Script _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("new") GodotMethod!(GodotObject, GodotVarArgs) _new; 45 @GodotName("get_as_byte_code") GodotMethod!(PoolByteArray) getAsByteCode; 46 } 47 bool opEquals(in GDScript other) const { return _godot_object.ptr is other._godot_object.ptr; } 48 GDScript opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 49 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 50 mixin baseCasts; 51 static GDScript _new() 52 { 53 static godot_class_constructor constructor; 54 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GDScript"); 55 if(constructor is null) return typeof(this).init; 56 return cast(GDScript)(constructor()); 57 } 58 @disable new(size_t s); 59 /** 60 Returns a new instance of the script. 61 For example: 62 63 64 var MyClass = load("myclass.gd") 65 var instance = MyClass.new() 66 assert(instance.get_script() == MyClass) 67 68 69 */ 70 GodotObject _new(VarArgs...)(VarArgs varArgs) 71 { 72 Array _GODOT_args = Array.empty_array; 73 foreach(vai, VA; VarArgs) 74 { 75 _GODOT_args.append(varArgs[vai]); 76 } 77 String _GODOT_method_name = String("new"); 78 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!GodotObject); 79 } 80 /** 81 Returns byte code for the script source code. 82 */ 83 PoolByteArray getAsByteCode() const 84 { 85 checkClassBinding!(typeof(this))(); 86 return ptrcall!(PoolByteArray)(_classBinding.getAsByteCode, _godot_object); 87 } 88 }