I want to write an AI for an old game, in Rust. AI's for this game are libraries, in its Linux port it's just an .so
file exporting:
extern "C" void client(int Command, int Player, void *Data);
void *Data
can be either struct (depends on Command
) or this function:
typedef int TServerCall(int Command, int Player, int Subject, void *Data);
In C++, AI code casts it depending on command, to a struct of known size or callback, like:
typedef int __stdcall TServerCall(int Command, int Player, int Subject, void *Data);
or to struct:
// where G is a extern TNewGameData G;
G = *(TNewGameData *) Data;
And then I can access fields of G
or other structs, or arrays.
Question:
How do I cast data in form of void *
to struct or function in Rust?