preprocessing idea

Monkey Forums/Monkey Programming/preprocessing idea

slenkar(Posted 2011) [#1]
How about when you create a Class the monkey preprocessor automatically creates a method called 'save' that converts the object to a string formatted as xml?

Would that be difficult to implement?


Samah(Posted 2011) [#2]
This is called serialisation, and is not as easy as it sounds. In order to serialise an object, every member of the class must also be serialisable. This becomes very messy when you start to use generics and other complicated class hierarchies. It really needs to be implemented specifically for your classes.

If automatic serialisation is added to the language, we need to be able to flag which fields should be serialised. In Java, everything is serialised unless it has the "transient" keyword. This is useful because some things may not make sense to serialise. For example, if your class has a reference to the App class, how would you serialise it? You wouldn't want to.

There are many more intricacies with serialisation, but for now I think that might be a fairly elegant solution. Mark needs to introduce a new keyword for this though, and a framework to perform the serialisation.

I agree that it's a good idea, though.


Sledge(Posted 2011) [#3]
Yeah the first time I saw SaveState() I was kinda hoping it meant that Monkey was managed/reflective enough to serialise (and restore) a running app automagically but no such luck :) Back to parsing the LoadState string...


Soap(Posted 2011) [#4]
I thought so too, which is why I converted my YAML classes to work with Load/Save States. It basically allows you to create a hierarchy of data inside the string for complex data. But if you don't have all that much data to save then a simple breaking of commas and what not would be fine.

I would love to hear Mark talk about if he plans to give Monkey reflection, that'll allow usage of Lua and other meta-possibilities. But seeing as Monkey is focused on Mobile platforms, at least for now, I doubt it'll be an official priority unless a lot of people ask for it.


slenkar(Posted 2011) [#5]
I had a look at yaml, I need something that can handle lists,arrays and stacks though.