How to save a class instance ?

Monkey Forums/Monkey Programming/How to save a class instance ?

semar(Posted 2012) [#1]
All,

you know in Java you can make a class serializable, and you can save/restore it to/from a file.

Would that possible in Monkey too ?

I ask this, because I need to save a set of data, which could conveniently be "stored" in a class.

I've seen that Diddy has a serialization class, but there's no method to save it to a file, for instance.

Any take ?

Regards,
Sergio.


ziggy(Posted 2012) [#2]
I don't think Monkey supports saving anything to a file other than SaveState, wich saves a String to "somewhere". And that somewhere deppends on the targetted platform


Samah(Posted 2012) [#3]
The serialization stuff in Diddy is quite out of date. Wait for me to do the reflection-based rewrite. :-)


ziggy(Posted 2012) [#4]
@Samah: Does diddy add any kind of addition way to write data "output" other than SaveState?


slenkar(Posted 2012) [#5]
this should work
http://monkeycoder.co.nz/Community/posts.php?topic=2487


semar(Posted 2012) [#6]
Thanks folksf for the answers so far.

I've played a bit with Diddys Filesystem, and I find it quite useful; you can "save" different "files" (it uses obviously SaveState and LoadState) and retrieve it easily.

The number of records - or better said: elements - of each file is also readable if you split the LoadState string it saves with chr(9) (tab character) and point to the next element after the file name. You have to convert (cast) the value using Integer(valueRetrieved).

Sure, it does not store any class instance in it, instead a raw binary sequence of data, but if you organize the data with a known pattern, and retrieve the data again using the same pattern, you are fine.

The serialization stuff in Diddy is quite out of date. Wait for me to do the reflection-based rewrite. :-)

Can't wait further :)
By the way, Diddy seems really good and stable - kudos to you, Samah, and please keep on the (very) good work :)

Sergio.