diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-05 22:04:16 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-05 22:04:16 +0200 |
| commit | 4902288a5a7885d348cdf04ac33768783db08e31 (patch) | |
| tree | 3f7171deff02413468c5f1948fcdb14621c3f9e1 /src/llvm_backend_proc.cpp | |
| parent | 7c3461b0df6020ab20017d0eaca990a60fc9e8b1 (diff) | |
Add `reflect.struct_field_count` that returns the number of fields in a struct type
Example:
```odin
package struct_count_example
import "core:fmt"
import "core:reflect"
import "core:dynlib"
Foo :: struct{
one: int,
two: f32,
}
Bar :: struct {
three: int,
four: bool,
five: f64,
}
Game_Api :: struct {
init: proc(api: ^Game_Api),
update: proc(api: ^Game_Api),
using foo: Foo,
bar: Bar,
// Private stuff
reload_count: int,
__handle: rawptr,
}
API_PRIVATE_COUNT :: 2
game_api: Game_Api
main :: proc() {
fmt.printfln("Game_Api, .Top: %v", reflect.struct_field_count(Game_Api)) // 6
fmt.printfln("Game_Api, .Using: %v", reflect.struct_field_count(Game_Api, .Using)) // 8
fmt.printfln("Game_Api, .Recursive: %v", reflect.struct_field_count(Game_Api, .Recursive)) // 11
symbols_loaded, _ := dynlib.initialize_symbols(&game_api, "game.dll")
symbols_expected := reflect.struct_field_count(Game_Api) - API_PRIVATE_COUNT
if symbols_loaded == -1 {
fmt.eprintln("Couldn't load game.dll")
return
} else if symbols_loaded != symbols_expected {
fmt.eprintfln("Expected %v symbols, got %v", symbols_expected, symbols_loaded)
return
}
}
```
Diffstat (limited to 'src/llvm_backend_proc.cpp')
0 files changed, 0 insertions, 0 deletions