Skip to main content
gamedev.net
🔒 Locked

Registering a file::write() script method

Started by Lbas 2 replies 1.6k views
Original Post
Lbas
Lbas
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
Maddi
Maddi
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)".
Deyja
Deyja
Or you could just use function overloading.

void write(int,etc)
void write(float,etc)

etc.
Lbas
Lbas
Ok thanks,
That's what I done but I innocently hoped there's a more flexible way to do it (by flexible I mean being able to read/write untyped datas so that you can save non registered types, like in C...).
Hurriedly the pointer support :)
Lbas
Lbas

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.