Expose some low level functions and String operators.

This commit is contained in:
bruvzg
2022-11-28 14:47:55 +02:00
parent 69b525494b
commit abca497b72
11 changed files with 623 additions and 1049 deletions

View File

@@ -54,6 +54,15 @@ func _ready():
var array: Array[int] = [1, 2, 3]
$Example.test_tarray_arg(array)
prints("String += operator")
prints(" test string +=", $Example.test_string_ops())
prints("WorkerThreadPool")
prints(" test worker_thread_pool", $Example.test_workpool_ops())
prints("PackedArray iterators")
prints(" test packed array iterators", $Example.test_vector_ops())
prints("Properties")
prints(" custom position is", $Example.group_subgroup_custom_position)
$Example.group_subgroup_custom_position = Vector2(50, 50)

View File

@@ -123,6 +123,8 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray);
ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary);
ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument);
ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops);
ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops);
ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200));
@@ -255,6 +257,28 @@ Array Example::test_array() const {
return arr;
}
String Example::test_string_ops() const {
String s = String("A");
s += "B";
s += "C";
s += char32_t(0x010E);
s = s + "E";
return s;
}
int Example::test_vector_ops() const {
PackedInt32Array arr;
arr.push_back(10);
arr.push_back(20);
arr.push_back(30);
arr.push_back(45);
int ret = 0;
for (const int32_t &E : arr) {
ret += E;
}
return ret;
}
void Example::test_tarray_arg(const TypedArray<int64_t> &p_array) {
for (int i = 0; i < p_array.size(); i++) {
UtilityFunctions::print(p_array[i]);

View File

@@ -101,6 +101,8 @@ public:
TypedArray<Vector2> test_tarray() const;
Dictionary test_dictionary() const;
Example *test_node_argument(Example *p_node) const;
String test_string_ops() const;
int test_vector_ops() const;
// Property.
void set_custom_position(const Vector2 &pos);