SketchyPhysicsWiki
Advertisement

If you haven't noticed a lot of scripted models will operate in SU 2013 and below only. Thats because SU2013 and SU2014 use different Ruby versions. SU2013 and lower use Ruby 1.8.x, while SU2014 uses Ruby 2.0.0. There were Ruby implementation changes since 1.8.x. Follow steps below for upgrading instructions:

Ruby Changes

Prohibited use of spaces between method name and the parentheses

  • Bad
 Geom::Point3d.new (1,2,3)
  • Good
 Geom::Point3d.new(1,2,3)

Prohibited use of colons (:) in case-when statement. Use semicolons (;) or new line.

  • Bad
 case count
 when 1: puts 'hello'
 when 2: puts 'goodbye'
 end
  • Good
 case count
 when 1; puts 'hello'
 when 2; puts 'goodbye'
 end
  • Also good
 case count
 when 1
   puts 'hello'
 when 2
   puts puts 'goodbye'
 end

Replaced Hash.#index with Hash.#key

 my_hash = { 1 => 'hello', 2 => 'goodbye' }
  • Bad (.index works in SU2013 and below only)
 count = my_hash.index('hello')
  • Bad (.key works in SU2014 only)
 count = my_hash.key('hello')
  • Good (Works in both versions)
 if RUBY_VERSION =~ /1.8/
   count = my_hash.index('hello')
 else
   count = my_hash.key('hello')
 end
  • Also good (One liner):
 count = RUBY_VERSION =~ /1.8/ ? my_hash.index('hello') : my_hash.key('hello')

Making LazyScript Compatible

For some advanced scripted models that use LazyScript making their code compatible is not enough because (1) LazyScript needs to be made compatible too, and (2) LazyScript uses Ruby DL which is only available in Ruby 1.8.x categories. In Ruby 2.0.0 Ruby DL was deprecated and replaced with Fiddle.

Here is a brief summary of what to change for compatibility:

1. Upgrade script for compatibility with Ruby 2.0.0 (see ruby changes).

2. Change body pointer creators to use DL and Fiddle, depending on Ruby version.

  • From this
 body_ptr = DL::PtrData.new(address)
  • To this
 body_ptr = RUBY_VERSION =~ /1.8/ ? DL::PtrData.new(address) : Fiddle::Pointer.new(address)

That's about it ;)

Advertisement