Include Ruby executables with SU?

Might consideration be given to including Ruby executables with SU installs?

See Async download a file?. Some of the discussion got ‘off-topic general’. Main idea was about tasks that did not require use of SU objects being sent to a spawned Ruby process.

Being able to do so may allow people to use gems in the external processes, which removes the ‘shared object space’ issue when loaded within SU.

Not that familiar with macOS, but from a Windows perspective, along with making a change like this, it would be a good time to change the embedded Ruby setup:

  1. Use ‘manifested’ dlls.
  2. Connect correctly to a ‘–user-install’ gem directory.
  3. The folder layout could be changed to more closely match a normal Windows Ruby install.

@kengey and I both made use of checking pid status of the external processes. I may investigate in what ways an external Ruby process can be set up to act like a REST server…

Spawned processes need very good code controlling them, and they can certainly be improperly used. Regardless, as everything becomes more distributed, this addition might be very helpful for complex plugins.

@tt_su, any thoughts?

1 Like

I once asked the same thing privately, around the timeframe that SketchUp was updated to Ruby 2.x and was released with the Standard Library distributed in SketchUp’s application “Tools” subfolder.

I also took issue with the Lib folder structure not being like Ruby’s and so invalidating many of the paths in the “rbconfig.rb” file that ships with SketchUp.

I was “slapped down” like I was crazy, and the responsible person was adamant in that they would not be including the Ruby binaries in their distro. I don’t remember much more about the conversation. I probably just dropped the idea as a geek can install a system Ruby of the same version.

I wonder if within SketchUp’s copy of the environment, if we could set the Ruby ENV vars:
RUBYPATH, RUBYLIB, RUBYSHELL, RUBYOPT, etc. to facilitate the use of a external Ruby installation ?

I think I remember playing with changing RUBYSHELL within SketchUp to point at “Cscript.exe” or “WScript.exe” but it didn’t work. Seemed the Ruby Windows distro gets hardset to “cmd.exe”. (Did this way back trying to avoid those popup command windows that flash on the display when running shell commands from SketchUp Ruby.)

I can see some great possibilities with this. I am not sure how to make an executable that can execute ruby code. I looked at IronRuby (Since I am mostly a .net developer), but that seems to not have been updated for a few years.

Anyhow: a separate executable that would just allow a script and a single object as input and spits out a response object would be great to start with. The problem I still see and have not yet overcome myself is direct stdin and stdout in SketchUp. I always use files for this, but, that might slow things down (although, today with ssd…)

Greg (I believe) is meaning those binaries that are in a normal Ruby installation’s "bin" subfolder.
This is the path that is usually pointed to by the environment var RUBYPATH.

On Windows builds we get a binary named "rubyw.exe" that does not open a shell window like it does from within SketchUp when we use %x strings (or the global backtick method.)


BTW, all the editions of the “Pick Axe” book have a short chapter on embedding a Ruby interpreter (which is what "bin/ruby.exe" and "bin/rubyw.exe" do.)

Oh I see.
I am more seeing this as something that could behave very much the same as web workers in webdev, allowing ruby developers to craft apps that run in parallel, but, without access to the sketchup model.

(sidenote, I noticed you are also into C#, there is a possibility to launch console apps without showing the console starting from .netcore 3.0 (or was it 3.1), by changing output type from exe to winexe)

Something like the Distributed Ruby Library ?
https://ruby-doc.org/stdlib-2.5.5/libdoc/drb/rdoc/index.html

I’ve wondered if it would work from within SketchUp. If it relies on pipes SU’s console might have nixed this.

The author of the library wrote a book on it, but it’s out of print …

God was I happy the first time I got pipes working from SketchUp, only to notice that that only works if you start SketchUp from cmd, and thus never if you start SU as a user would.

I have to admit that, outside of SketchUp, I do not have enough Ruby knowledge.

According to …

… it uses marshalling and not pipes. Give it a read.

I certainly will.

Dan & Kenny,

I added ruby.exe & rubyw.exe to the folder containing SketchUp.exe, and I got a script to run in SU that spawned a process with rubyw.exe and downloaded a 10 MB file.

SU seemed responsive during the download.

Sometime soon I’ll see what might work for communication between the spawned process and SU.

DRb runs on sockets, not pipes. It can be used between two different machines…

like I was crazy

Some might call me crazy, but that’s another discussion…

2 Likes

In for another thread? :grin:

1 Like

Everything at https://msp-greg.github.io/ is done via Ruby. I have all the repos locally. Ruby script queries the GitHub REST and GraphQL API’s, determines which ones have been updated, updates the repos, generates the new docs, then pushes the changes to the GitHub.io repo. IOW, Ruby can be used for things other than Rails apps.

If you (or anyone else) wants some help re stand-alone Ruby, feel free to ask. I’m pretty familiar with Windows Ruby…

1 Like