SketchyPhysicsWiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 24: Line 24:
 
puts 'hello'
 
puts 'hello'
 
when 2
 
when 2
puts 'goodbye'
+
puts puts 'goodbye'
 
end
 
end
   
Line 33: Line 33:
 
* Bad (.key works in SU2014 only)
 
* Bad (.key works in SU2014 only)
 
count = my_hash.key('hello')
 
count = my_hash.key('hello')
* Good (works in both versions)
+
* Good (Works in both versions)
 
if RUBY_VERSION =~ /1.8/
 
if RUBY_VERSION =~ /1.8/
 
count = my_hash.index('hello')
 
count = my_hash.index('hello')
Line 39: Line 39:
 
count = my_hash.key('hello')
 
count = my_hash.key('hello')
 
end
 
end
* Also good (one liner):
+
* Also good (One liner):
 
count = RUBY_VERSION =~ /1.8/ ? my_hash.index('hello') : my_hash.key('hello')
 
count = RUBY_VERSION =~ /1.8/ ? my_hash.index('hello') : my_hash.key('hello')
   
 
==Making LazyScript Compatible==
 
==Making LazyScript Compatible==
For some advanced scripted models that use LazyScript making their code compatible for SU2014 is not enough because (1) LazyScript itself needs to be updated with Ruby changes, and (2) LazyScript needs to ensure that it is using Fiddle for Ruby 2.0 and DL for Ruby 1.8. In Ruby 2.0.0 Ruby DL was deprecated and replaced with Fiddle. Change body pointer creators to use DL or Fiddle, depending on Ruby version:
+
For some advanced scripted models that use LazyScript making their code compatible for SU2014 is not enough because (1) LazyScript itself needs to be updated with Ruby changes, and (2) needs to ensure that it is using Fiddle in 2.0 and Ruby DL for Ruby 1.8. In Ruby 2.0.0 Ruby DL was deprecated and replaced with Fiddle. Here is a snippet of code to replace in LazyScript: Change body pointer creators to use DL and Fiddle, depending on Ruby version.
 
* From this
 
* From this
 
body_ptr = DL::PtrData.new(address)
 
body_ptr = DL::PtrData.new(address)

Please note that all contributions to the SketchyPhysicsWiki are considered to be released under the CC-BY-SA

Cancel Editing help (opens in new window)