Issues with Scrambler
-
Hello,
I have a plugin where files live in a sub-folder, and are loaded by a file in the main Plugins folder. I'd like to scramble the files in the sub-folder before distributing. However, once I scramble the files, I am getting errors.
If I use the command 'require', I get errors like this:
require 'test/test2' Error; #<LoadError; (eval);1;in `require'; no such file to load -- test/test2> (eval);1 (eval);1
If I use the command 'load', I get these errors:
load 'test/test2.rbs' Error; #<SyntaxError; (eval);1;in `load'; C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/test/test2.rbs;1; no .<digit> floating literal anymore; put 0 before dot RBS1.0 ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/test/test2.rbs;1; syntax error, unexpected tINTEGER RBS1.0 ^ C;/Program Files (x86)/Google/Google SketchUp 8/Plugins/test/test2.rbs;1; Invalid char `\010' in expression> (eval);1 (eval);1
the rbs file looked like this when it was a ruby:
UI.messagebox("test2")
any ideas? I used the scrambler found here: https://developers.google.com/sketchup/docs/utilities
Thanks.
--
Karen -
Sketchup::require != require
Thanks Dan.
-
@kwalkerman said:
Sketchup::require != require
Actually to be more precise...
Sketchup.method(:require) != method(:require)
true
If you type
method(:require)
at the console (it is equiv to calling:method(:require).inspect
,) you see:#<Method: Object(Kernel)#require>
The "#require" means it is an instance method.
The "Object(Kernel)" means it is an object ofObject
, inherited from the mixin moduleKernel
.The mixin module
Kernel
is mixed into classObject
by the Ruby Core. Since all objects are descendants ofObject
, the methods in moduleKernel
are global methods, and are inherited on down the line by all classes and modules.If you type
*AnyClass*.ancestors
you'll see the two top ancestors are always [...,Object,Kernel].This is how your custom modules and classes get these methods.. but they are inherited as private methods. Even the
Sketchup
module when it was first declared, inherited arequire
method fromKernel
viaObject
.
But the API team overrode it inside theSketchup
module (to allow it to handle rbs loading,) and then cloned it as a public module method, so we could call it from outside as a library function.If you type at the console:
Sketchup.method(:require).inspect
, you see:#<Method: Sketchup.require>
This shows it is not inherited, and is a singleton (module) method.
But since we know that a method of the same name 'require', is inherited by all class and module objects, we know it has to have been overridden.
We can verify with:Sketchup.private_methods(true).include?("require")
false
Which means it no longer contains the private method "require" it inherited fromKernel
. -
This is an old thread, But I'd just like to go on the record that Sketchup 2014 has fixed one of the issues. I have a .rbs that includes the previously mentioned FILE. It runs just fine in 2014, yet it breaks down in 2013, giving me the following error:
no .<digit> floating literal anymore; put 0 before dot
good luck fellow coders.
-
(I added a note to the above post that it has been fixed.)
-
Karen.. this is a forehead smacker (so get your hand ready.)
Standard Ruby has no idea what a scrambled rbs file is, or how to decrypt it.
So the SU development team created a module method that could open, decrypt and then evaluate them.
You need to use the
Sketchup::require()
module method.There are other issues with scrambling. The Ruby keywords
__LINE__
and__FILE__
do not currently work inside scrambled rubies. (Fixed in SketchUp 2014+ using Ruby 2.0 or higher.)I'm am glad that you have decided to use your own filespace. It's only smart.
I posted an example of doing this with scrambled rubies.
Advertisement