Implement support for typed arrays.

This commit is contained in:
bruvzg
2022-09-15 10:33:07 +03:00
parent 8670305589
commit c001d0e5c7
7 changed files with 2396 additions and 1541 deletions

View File

@@ -45,7 +45,10 @@ func _ready():
prints("Array and Dictionary")
prints(" test array", $Example.test_array())
prints(" test tarray", $Example.test_tarray())
prints(" test dictionary", $Example.test_dictionary())
var array: Array[int] = [1, 2, 3]
$Example.test_tarray_arg(array)
prints("Properties")
prints(" custom position is", $Example.group_subgroup_custom_position)

View File

@@ -103,6 +103,8 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("extended_ref_checks"), &Example::extended_ref_checks);
ClassDB::bind_method(D_METHOD("test_array"), &Example::test_array);
ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &Example::test_tarray_arg);
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("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200));
@@ -223,6 +225,22 @@ Array Example::test_array() const {
return arr;
}
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]);
}
}
TypedArray<Vector2> Example::test_tarray() const {
TypedArray<Vector2> arr;
arr.resize(2);
arr[0] = Vector2(1, 2);
arr[1] = Vector2(2, 3);
return arr;
}
Dictionary Example::test_dictionary() const {
Dictionary dict;

View File

@@ -88,6 +88,8 @@ public:
int def_args(int p_a = 100, int p_b = 200);
Array test_array() const;
void test_tarray_arg(const TypedArray<int64_t> &p_array);
TypedArray<Vector2> test_tarray() const;
Dictionary test_dictionary() const;
// Property.