I submitted a plugin (bim.bon) to SU’s Extension Warehouse. The code I submitted works fine in all supported SU versions, from SU8 to SU16. The code was reviewed and accepted and, as requested, is available in scrambled format.
Here’s the problem: the scrambled version only works in SU14, SU15 and SU16. In SU8 and SU13 the plugin available in the Extension Warehouse returns the following error and doesn’t load:
Error Loading File bimbon.rb
undefined method `dlg' for SketchupExtension::Bimbon::Bimbon:Module
Have you guys/girls seen this before? Any idea what I could do to avoid this kind of error once the plugin is scrambled? Since it runs fine in unscrambled format I feel the problem is not in my code but in some change done by the scrambler.
dlg method:
# encoding: utf-8
module Bimbon
...
def self.dlg
@_dlg ||= begin
dlg = UI::WebDialog.new("bim.bon", true, "bimbon", 365, 710, 150, 150, true)
dlg.set_url(REMOTE+"/start.html")
dlg.min_width = 365
dlg.min_height = 360
dlg
end
end
...
end
Yes, it is an old error in the Sketchup::require() method when evaluating scrambled files.
You must have all your require and Sketchup::require() calls outside any module at the toplevel evaluating within TOPLEVEL_BINDING, or else call them like:
module Bimbon::Bimbon
Sketchup::require('Bimbon/Bimbon_core')
Sketchup::require('Bimbon/Bimbon_lib')
Sketchup::require('Bimbon/Bimbon_menu')
# etc., etc.
end
Sometimes I create an array of files to load and use a loop, if I’m doing it inside a module in a scrambled loader file:
scripts = ['Bimbon_core','Bimbon_lib','Bimbon_menu']
for script in scripts
eval(
"Sketchup::require('Bimbon/#{script}')"),
TOPLEVEL_BINDING,
"#{File.join(Sketchup.find_support_file("Plugins"),Bimbon,script)}.rbs",
1
)
end
But I no londger support old Ruby 1.8 SketchUp, (pre v2014) so I do not use workarounds any more.
There are also old bugs where __FILE__ and __LINE__ are not evaluated correctly inside scrambled rubies pre 2014.