1 /**
2 A class that stores an expression you can execute.
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.expression;
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.reference;
25 /**
26 A class that stores an expression you can execute.
27 
28 An expression can be made of any arithmetic operation, built-in math function call, method call of a passed instance, or built-in type construction call.
29 An example expression text using the built-in math functions could be `sqrt(pow(3,2) + pow(4,2))`.
30 In the following example we use a $(D LineEdit) node to write our expression and show the result.
31 
32 
33 onready var expression = Expression.new()
34 
35 func _ready():
36     $LineEdit.connect("text_entered", self, "_on_text_entered")
37 
38 func _on_text_entered(command):
39     var error = expression.parse(command, [])
40     if error != OK:
41         print(expression.get_error_text())
42         return
43     var result = expression.execute([], null, true)
44     if not expression.has_execute_failed():
45         $LineEdit.text = str(result)
46 
47 
48 */
49 @GodotBaseClass struct Expression
50 {
51 	package(godot) enum string _GODOT_internal_name = "Expression";
52 public:
53 @nogc nothrow:
54 	union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; }
55 	alias _GODOT_base this;
56 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
57 	package(godot) __gshared bool _classBindingInitialized = false;
58 	package(godot) static struct GDNativeClassBinding
59 	{
60 		__gshared:
61 		@GodotName("execute") GodotMethod!(Variant, Array, GodotObject, bool) execute;
62 		@GodotName("get_error_text") GodotMethod!(String) getErrorText;
63 		@GodotName("has_execute_failed") GodotMethod!(bool) hasExecuteFailed;
64 		@GodotName("parse") GodotMethod!(GodotError, String, PoolStringArray) parse;
65 	}
66 	/// 
67 	pragma(inline, true) bool opEquals(in Expression other) const
68 	{ return _godot_object.ptr is other._godot_object.ptr; }
69 	/// 
70 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
71 	{ _godot_object.ptr = n; return null; }
72 	/// 
73 	pragma(inline, true) bool opEquals(typeof(null) n) const
74 	{ return _godot_object.ptr is n; }
75 	/// 
76 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
77 	mixin baseCasts;
78 	/// Construct a new instance of Expression.
79 	/// Note: use `memnew!Expression` instead.
80 	static Expression _new()
81 	{
82 		static godot_class_constructor constructor;
83 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Expression");
84 		if(constructor is null) return typeof(this).init;
85 		return cast(Expression)(constructor());
86 	}
87 	@disable new(size_t s);
88 	/**
89 	Executes the expression that was previously parsed by $(D parse) and returns the result. Before you use the returned object, you should check if the method failed by calling $(D hasExecuteFailed).
90 	If you defined input variables in $(D parse), you can specify their values in the inputs array, in the same order.
91 	*/
92 	Variant execute(in Array inputs = Array.make(), GodotObject base_instance = GodotObject.init, in bool show_error = true)
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(Variant)(GDNativeClassBinding.execute, _godot_object, inputs, base_instance, show_error);
96 	}
97 	/**
98 	Returns the error text if $(D parse) has failed.
99 	*/
100 	String getErrorText() const
101 	{
102 		checkClassBinding!(typeof(this))();
103 		return ptrcall!(String)(GDNativeClassBinding.getErrorText, _godot_object);
104 	}
105 	/**
106 	Returns `true` if $(D execute) has failed.
107 	*/
108 	bool hasExecuteFailed() const
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(bool)(GDNativeClassBinding.hasExecuteFailed, _godot_object);
112 	}
113 	/**
114 	Parses the expression and returns an $(D error) code.
115 	You can optionally specify names of variables that may appear in the expression with `input_names`, so that you can bind them when it gets executed.
116 	*/
117 	GodotError parse(in String expression, in PoolStringArray input_names = PoolStringArray.init)
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(GodotError)(GDNativeClassBinding.parse, _godot_object, expression, input_names);
121 	}
122 }