Reflection for procedures

Hi there,

is there any way to get the parameters expected by a procedure during compilation or runtime?

So I am looking for something like this:

nice_proc :: proc(a: i32, b: f32, c: string){
   ...
}

id := typeid_of(nice_proc)
names := reflect.proc_arg_names(id)
types := reflect.proc_arg_types(id)

I’d like to use it for a nice binding system to a scripting language.

Compile-time:
https://pkg.odin-lang.org/base/intrinsics/#type_proc_parameter_count
https://pkg.odin-lang.org/base/intrinsics/#type_proc_parameter_type
https://pkg.odin-lang.org/base/intrinsics/#type_proc_return_count
https://pkg.odin-lang.org/base/intrinsics/#type_proc_return_type

At run-time, there don’t appear to be any helper functions in reflect but theType_Info_Procedure struct has all of this information. You can get it by type-asserting the variant field of the Type_Info for a proc.

1 Like