Save / Load RubyObject to File

Post any examples or modules that you want to share here
Post Reply
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Save / Load RubyObject to File

Post by chackl »

Hello!

I did some simple save and load modules for ruby objects.
My Problem was that i got realy big objects and this module kees it easier to save object to a binary file.

WARNING: Binay files are no TEXT Files!!! - Never open and save them with a text Editor!!!

If you want to save a text to the object use an object-Array.

Regards
C.Hackl
Attachments
save_load ruby.fsm
Save & Load Ruby Objects to Files
(2.71 KiB) Downloaded 1329 times
Last edited by chackl on Wed Oct 02, 2013 7:01 am, edited 1 time in total.
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Save / Load RubyObject

Post by billv »

Thanks for sharing..... :) .
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject

Post by chackl »

u'r welcome ;)

Please NOTE:
Custom classes Need some extras to get it working:
http://ruby-doc.org/core-2.0.0/Marshal.html

Not working with Bitmap objects - needs a Workaround. - I'll be on this.

Regards
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Save / Load RubyObject

Post by billv »

chackl wrote:Custom classes Need some extras

Yeh i got caught out....trying to make it work...went inside module
and saw 'marshal'....who's that..??...never heard of him... :lol: :lol:

Had planned to try my first 'class' maybe next week....
In over my head again
chackl wrote:I'll be on this.

thanks...i can watch and learn... :D .
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Save / Load RubyObject to File

Post by trogluddite »

'Marshal' is a special class that used for 'serialising' objects - taking a Ruby object and converting it into a stream of binary numbers, so that the object can be saved and then re-created when loaded.
But it only works for Ruby classes that have special methods defined to say how the conversion should be done. Most of the standard Ruby classes have the 'marshal' methods, but many FS specific classes don't.
Behind the scenes, the FS 'loadState' and 'saveState' methods, and storing the input/output values, will be using 'Marshal' - which is why there are some objects (e.g. bitmaps, graphics paths, brushes) that can't be stored between sessions.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject to File

Post by chackl »

i think it will be easy to restore Brushes and so on.... I'm just saving the input variables for Brush class and calculate it again afer load.
For Bitmaps.... difficult. I'm working now with the FloStone primitive get pixel and save it to a 2 dimensional color array within ruby. And this is slow.... Getting back a bitmap is also tricky - Also a Primitive again View to bitmap and i draw every pixel as a recktangle in ruby (But this is much faster)

If you use it you have to get all classes ready for it otherwise there will be loads of lost data.

Regards
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
imi90
Posts: 1
Joined: Tue Nov 05, 2013 12:00 pm

Re: Save / Load RubyObject to File

Post by imi90 »

Is there someone out there who knows how to 'capture' the 'ZeroDivisionError' in the Flowstone Ruby interpreter and rectify the code below?
erum
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject to File

Post by chackl »

imi90 wrote:Is there someone out there who knows how to 'capture' the 'ZeroDivisionError' in the Flowstone Ruby interpreter and rectify the code below?

Could you please open a new topic if it is not belonging to save/load Ruby Objects?
Thanks
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
Post Reply