(Added compatibility page.)
Tag: Visual edit
(Minor changes)
Tag: Visual edit
Line 52: Line 52:
* To this
* To this
body_ptr = RUBY_VERSION =~ /1.8/ ? :
body_ptr = RUBY_VERSION =~ /1.8/ ? :
Thats about it ;)

Revision as of 01:14, 15 September 2014

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 (1,2,3)
  • Good,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'
  • Good
 case count
 when 1; puts 'hello'
 when 2; puts 'goodbye'
  • Also good
 case count
 when 1
   puts 'hello'
 when 2
   puts puts 'goodbye'

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')
   count = my_hash.key('hello')
  • 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:

Upgrade script for compatibility using new Ruby scripting rules.

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

  • From this
 body_ptr =
  • To this
 body_ptr = RUBY_VERSION =~ /1.8/ ? :