Continuing the discussion from Comment: # First we pull in the standard API hooks:
Opening debate on an fun old topic.
What do we tell Ruby Newbies concerning:
require "sketchup.rb"
Continuing the discussion from Comment: # First we pull in the standard API hooks:
Opening debate on an fun old topic.
What do we tell Ruby Newbies concerning:
require "sketchup.rb"
The requirement is probably meant as marker statement and not a literal requirement of the little bits that this file currently contains.
And I disagreed in the other thread. Write your comments to mean what they should mean. Most especially if it is a example or tutorial that is going to teach the knowledgeable.
I always teach what I learned from the Ruby docs and the Pick-Axe bookâŚ
Require only what you need. (Requirements are listed by YARD and other documentation generators.)
How else would you suggest to âmarkâ scripts so that they need a special environment?
How about:
exit unless $0 == "SketchUp"
I actually used this form in a plugin that I did not want to run in DoubleCAD Ruby (although I donât think I ever released it into the wild.) DoubleCAD had implemented (badly,) a clone of the SketchUp API, so it also had a Sketchup
module defined.
EDIT: Another couple might be:
exit unless defined?(Sketchup) == "constant"
or
raise(NotImplementedError,"Runs in SketchUp Ruby ONLY!") unless defined?(Sketchup)
Also if the Ruby API was implemented as a
"sketchup.rb"
that loads a C extension, would it be better?
IF âŚthis is a hypothetical situation that does not exist.
Do we teach new coders based upon possible future scenarios ? ⌠or what exists now ?
But SketchUp Ruby scripts/plugins/extensions still require a special embedded Ruby that provides these API classes. If one attempts to run them outside, they should fail (at load time and not somewhen late at runtime.)[/quote]
My first retort would be why ever run them outside of SketchUp Ruby ?Bu then you had an answer âŚ
[quote=âAerilius, post:2, topic:11365â]I sometimes drop in alternative SU API implementations (mocks) for ease of testing in the system ruby interpreter, where a
"sketchup.rb"
requirement makes sense again.
But this is YOUR workflow!
We donât tell the whole world to mimic you, if they do not have that same workflow.
Besides, I find it more likely that a mock API would be loaded via the command line, or a "load 'api'"
statement typed into the IRB shell.
That is what I would do. Iâd set up the âoutsideâ Ruby environment to be exactly like the internal one, just after SketchUp startup. And in that âmock upâ the âsketchup.rbâ file should be the very same, and implement the same functions as it does in the internal environment.
In conclusion, because you (and maybe others,) are using this statement as a âmarkerâ and in a way that it was never intended,⌠does not mean we should tell everyone else to put meaningless statement in all their files.
You donât have to comply nor agree, because you have a workflow that uses the statements in two ways.
But I am a purist. I respect yaâ Andreas, but I must disagree with yaâ.
IF, in the future, there does happen some external Ruby API, that runs outside of SketchUp,⌠then it isnât SketchUp,⌠and it shouldnât be named âsketchupâ.
It should have itâs own name, like âskpapiâ or whatever.
Theoretically, if you are using any of the 6 methods defined in sketchup.rb, you should be using the ârequireâ requestâŚ
however, as sketchup.rb is loaded from âToolsâ before any Plugins, I canât see any reason to require it later in the sequenceâŚ
john
[quote=âjohn_drivenupthewall, post:3, topic:11376â]
however, as sketchup.rb is loaded from âToolsâ before any Plugins, I canât see any reason to require it later in the sequenceâŚ
[/quote] The point is that Tools loads AFTER Plugins, so you do need to require it for a script in Plugins that is loading that needs it.
Making a file named !.rb in Plugins which included the single line require("sketchup.rb")
would remove the need for this ??
Or even easier⌠force scripts in Tools to load first !
Then no oneâd noticeâŚ
The point is that Tools loads AFTER Plugins
not on a mac, User files are loaded after the application files, so the order is Ruby.framework, Tools, User/âŚ/Gems, User/âŚ/PluginsâŚ
so, moving PC Plugins to User space would also make it redundantâŚ
john
The point is that Tools loads AFTER Plugins, âŚ
When SketchUp 14 was released with Ruby 2.0, ⌠the load order changed:
pp $LOADED_FEATURES => [
"enumerator.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/encdb.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/iso_8859_1.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/trans/transdb.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/trans/single_byte.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/rbconfig.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/compatibility.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/defaults.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/deprecate.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/errors.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/version.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/requirement.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/platform.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/specification.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/exceptions.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/defaults/operating_system.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/core_ext/kernel_gem.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/extensions.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/langhandler.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/sketchup.rb",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/utf_16le.so",
"C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/platform_specific/enc/trans/utf_16_32.so",
... # followed by user & public plugin path processing ...
]
Making a file named !.rb in Plugins which included the single line require(âsketchup.rbâ) would remove the need for this ??
It is kind of a sore issue with me, as I was preaching way back during the v7 cycle, that âsketchup.rb
â needed to become empty (and no longer needed.)
All itâs functionality is 8 years over due for being baked into the C-side of the API.
It was a quick fix for several issues, but they should never have been left in that Ruby âquick fixâ state this long.
For one thing itâs code is outside the control for the rest of the applicationâs C-side.
For another, there are still errors in it that Iâve reported that have still gone unrepaired, for years.
Whenever I work on a large extension, I purposely do not use âsketchup.rb
â.
I use fixed versions of itâs methods re-written within the plugin namespace(s).
Thanks @DanRathbun for âdisabusingâ me
I hadnât appreciated the load_order change since v2014.
I donât worry about it much eitherâŚ
So all of the issues with missing sketchup.rb methods must originate in SketchUp <= v2013âŚ