Disclaimer, english is not my primary language.
Let me explain this better to see if i am not understanding or i am explaining it wrong.
I am starting from the idea that i can’t import a module if i don’t want to initialize any global variables
within that module
There is this one usecase that bugs me [1]:
I have two modules, lets say one is platform
and the other is game
the platform
is compiled as an executable and game
as a dll
My hot reloading code requires a struct with the function definitions like
// game module
update :: proc(^Game_State) -> bool { /*[...]*/ }
// platform module
Lib :: struct {
update : proc(rawptr) -> bool,
start_game : proc(),
deinit : proc(),
// [...]
}
and that is fine, but here there is a problem, i can’t properly enforce the type because
the game
module have the definitions
this is more apparent whith this snippet (i haven’t tested this part)
// game module
File_Info :: struct { /*[...]*/ }
platform_get_file_info_handle : proc(string) -> File_Info
// platform module
Lib :: struct {
// [...]
platform_get_file_info_handle: rawptr
}
Duplicated_File_Info :: struct { /*[...]*/ }
platform_get_file_info :: proc(file: string) -> Duplicated_File_Info { /*[...]*/ }
main :: proc() {
// [...] when the lib is initialized
// Edit: i think this is wrong and will not work,
// it would be necessary a `load_platform_functions` function in the game module
// and call this function here, but it will complicate this example
lib.platform_get_file_info_handle = platform_get_file_info
}
it is much easier to do something like
// game module
Get_File_Info_Fn :: proc(string) -> File_Info
platform_get_file_info_handle : Get_File_Info_Fn
// platform module
// if you hypothetically import only the type definitions of the game module
import "game"
// idk if type_of(game.platform_get_file_info_handle) works
platform_get_file_info : game.Get_File_Info_Fn :
proc(file: string)
-> game.File_Info { /*[...]*/ }
I know what you are wanting, which is the old macro trick
I think is this trick you are mentioning:
#define X_INPUT_SET_STATE(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration)
typedef X_INPUT_SET_STATE(x_input_set_state);
X_INPUT_SET_STATE(XInputSetStateStub) {
return ERROR_DEVICE_NOT_CONNECTED;
}
static x_input_set_state *XInputSetState_ = XInputSetStateStub;
#define XInputSetState XInputSetState_
I like this, but i know it is not necessary in odin, and i like not having to do this
As for not having a way to get the types and procedure definitions is kind of the point of NOT requiring header files.
I didn’t understand this part
Again, i don’t know if i am not understanding or i am explaining it wrong.
[1] sorry that i only have one use case, but i didn’t want to forget to write this comment