1 /**
2 State of a function call after yielding.
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.gdscriptfunctionstate;
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.reference;
24 /**
25 State of a function call after yielding.
26 
27 Calling $(D @GDScript.yield) within a function will cause that function to yield and return its current state as an object of this type. The yielded function call can then be resumed later by calling $(D resume) on this state object.
28 */
29 @GodotBaseClass struct GDScriptFunctionState
30 {
31 	package(godot) enum string _GODOT_internal_name = "GDScriptFunctionState";
32 public:
33 @nogc nothrow:
34 	union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct GDNativeClassBinding
39 	{
40 		__gshared:
41 		@GodotName("_signal_callback") GodotMethod!(Variant, GodotVarArgs) _signalCallback;
42 		@GodotName("is_valid") GodotMethod!(bool, bool) isValid;
43 		@GodotName("resume") GodotMethod!(Variant, Variant) resume;
44 	}
45 	/// 
46 	pragma(inline, true) bool opEquals(in GDScriptFunctionState other) const
47 	{ return _godot_object.ptr is other._godot_object.ptr; }
48 	/// 
49 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
50 	{ _godot_object.ptr = n; return null; }
51 	/// 
52 	pragma(inline, true) bool opEquals(typeof(null) n) const
53 	{ return _godot_object.ptr is n; }
54 	/// 
55 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
56 	mixin baseCasts;
57 	/// Construct a new instance of GDScriptFunctionState.
58 	/// Note: use `memnew!GDScriptFunctionState` instead.
59 	static GDScriptFunctionState _new()
60 	{
61 		static godot_class_constructor constructor;
62 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GDScriptFunctionState");
63 		if(constructor is null) return typeof(this).init;
64 		return cast(GDScriptFunctionState)(constructor());
65 	}
66 	@disable new(size_t s);
67 	/**
68 	
69 	*/
70 	Variant _signalCallback(VarArgs...)(VarArgs varArgs)
71 	{
72 		Array _GODOT_args = Array.make();
73 		foreach(vai, VA; VarArgs)
74 		{
75 			_GODOT_args.append(varArgs[vai]);
76 		}
77 		String _GODOT_method_name = String("_signal_callback");
78 		return this.callv(_GODOT_method_name, _GODOT_args);
79 	}
80 	/**
81 	Check whether the function call may be resumed. This is not the case if the function state was already resumed.
82 	If `extended_check` is enabled, it also checks if the associated script and object still exist. The extended check is done in debug mode as part of $(D GDScriptFunctionState.resume), but you can use this if you know you may be trying to resume without knowing for sure the object and/or script have survived up to that point.
83 	*/
84 	bool isValid(in bool extended_check = false) const
85 	{
86 		checkClassBinding!(typeof(this))();
87 		return ptrcall!(bool)(GDNativeClassBinding.isValid, _godot_object, extended_check);
88 	}
89 	/**
90 	Resume execution of the yielded function call.
91 	If handed an argument, return the argument from the $(D @GDScript.yield) call in the yielded function call. You can pass e.g. an $(D Array) to hand multiple arguments.
92 	This function returns what the resumed function call returns, possibly another function state if yielded again.
93 	*/
94 	Variant resume(VariantArg0)(in VariantArg0 arg = Variant.nil)
95 	{
96 		checkClassBinding!(typeof(this))();
97 		return ptrcall!(Variant)(GDNativeClassBinding.resume, _godot_object, arg);
98 	}
99 }