Registering a file::write() script method
Hi all,
I would like to register a standard write file script method with a prototype like this :
size_t file::write( void* ptr, size_t size ); such as you could write any kind of data in the file.
How guys would you manage to register it (if possible) ?
Another way would be to register dedicated write methods for each possible types (like WriteInt8, WriteInt16, etc.), but just wondered if it was possible to stay near to the standard C way to be more flexible, for example if user wants to declare a structure in its script and then write it out in a binary file (without serializing process).
PS: same for file::read() of course :)
Thanks in advance,
Regards,
Lbas
Lbas
I don't think this is directly possible atm.
The easyest way would be do define a "cast" function, like "serializable cast(classxy ∈)". You the define a class serializable that holds a pointer to the real object to be serialized. This way you have to only overload one function and you could then do "file::write(cast(classxy), size)".
The easyest way would be do define a "cast" function, like "serializable cast(classxy ∈)". You the define a class serializable that holds a pointer to the real object to be serialized. This way you have to only overload one function and you could then do "file::write(cast(classxy), size)".
Or you could just use function overloading.
void write(int,etc)
void write(float,etc)
etc.
void write(int,etc)
void write(float,etc)
etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement