sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Rbs weird behaviour on modules

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 70 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      SR20VET
      last edited by

      Today I ran into this weird behaviour when scrambling my scripts into an rbs.

      Lets say I have the folowing script:

      module MyModule1
        def self.load_second_script
          Sketchup;;require 'second_script'
        end#def
      end#module
      

      in seconds_script.rb(s) i have:

      module MyModule1
        module MyModule2
      
        end#module
      end#module
      

      next, I do:

      MyModule1.load_second_script
      

      While testing with rb, this eventually gives

      MyModule1;;MyModule2
      

      as a valid module.
      With rbs this results in

      MyModule1;;MyModule1;;MyModule2
      

      Has anyone noticed this before?

      Regards

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @sr20vet said:

        Has anyone noticed this before?

        YES. ThomThom first noticed this, and has filed a bug report.

        The error is within the Sketchup::require() method.

        To workaround, you will need to force the evaluation to occur within the TOPLEVEL_BINDING, thus:

        module MyModule1
          def self.load_second_script
            eval("Sketchup;;require('second_script')",TOPLEVEL_BINDING,'second_script.rbs',1)
          end#def
        end#module
        

        💭

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          It also happens with SketchupExtension classes - where you cannot bypass the Sketchup::require call and I had to create a proxy .rb file to load the actual .rbs file.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • S Offline
            SR20VET
            last edited by

            Ok, thanks for the workaround. You should expect that no mather you use rb's or rbs's, they behave the same way...

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement