oniksan / godobuf

A Google Protobuf implementation for Godot / GDScript
BSD 3-Clause "New" or "Revised" License
248 stars 34 forks source link

Generate typed return values for repeated fields. #41

Closed rcorre closed 7 months ago

rcorre commented 8 months ago

Fixes #38.

Given:

message Foo {
    repeated int32 i = 1;
    repeated string s = 2;
    repeated Bar b = 3;
}

Previously godobuf would generate:

get_i() -> Array
get_s() -> Array
get_b() -> Array

Now it generates:

get_i() -> Array[int]
get_s() -> Array[string]
get_b() -> Array[Bar]

To do this, we must assign a typed array when constructing the PBField. Godot does not currently have a typed array constructor: https://github.com/godotengine/godot/issues/72627#issuecomment-1414516463 To work around this, we create a local typed variable, like so:

class Test1:
    func _init():
        var __rf_double_default: Array[float] = []
        __rf_double = PBField.new("rf_double", PB_DATA_TYPE.DOUBLE, PB_RULE.REPEATED, 23, true, __rf_double_default)
...
    func get_rf_double() -> Array[float]:
        return __rf_double.value
rcorre commented 8 months ago

Based on #37