Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Save / Load RubyObject to File

Post any examples or modules that you want to share here

Save / Load RubyObject to File

Postby chackl » Tue Oct 01, 2013 9:13 pm

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 1235 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.
User avatar
chackl
 
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject

Postby billv » Tue Oct 01, 2013 9:33 pm

Thanks for sharing..... :) .
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: Save / Load RubyObject

Postby chackl » Tue Oct 01, 2013 9:56 pm

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.
User avatar
chackl
 
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject

Postby billv » Tue Oct 01, 2013 11:25 pm

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 .
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: Save / Load RubyObject to File

Postby trogluddite » Wed Oct 02, 2013 8:56 am

'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
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Save / Load RubyObject to File

Postby chackl » Wed Oct 02, 2013 9:13 am

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.
User avatar
chackl
 
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Save / Load RubyObject to File

Postby imi90 » Tue Nov 05, 2013 12:04 pm

Is there someone out there who knows how to 'capture' the 'ZeroDivisionError' in the Flowstone Ruby interpreter and rectify the code below?
erum
imi90
 
Posts: 1
Joined: Tue Nov 05, 2013 12:00 pm

Re: Save / Load RubyObject to File

Postby chackl » Tue Nov 05, 2013 1:23 pm

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.
User avatar
chackl
 
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg


Return to User Examples

Who is online

Users browsing this forum: Google [Bot] and 75 guests