Moderator: Jim
by Dan Rathbun » Wed Oct 28, 2009 3:34 am
. ISSUE: Request for Review and DiscussionTopic: Platform (Operating System) Constant(s) for Sketchup Embedded Ruby From: Dan Rathbun, Palm Bay, FL .. 27 OCT 2009 ... for SKX project Purpose(s): - To use fast boolean evaluation, instead of slow string comparasion in conditional statements.
- To have the determination of the client Operating System (ie, the 'PLATFORM',) occur ONCE at Sketchup startup, rather than in each and every conditional statement.
- To have the determination of the client Operating System, which in practice, is the parsing of the RUBY_PLATFORM architecture string, occur in a central library script; where any future changes to the GNU Ruby architecure strings, can be centrally handled, instead of requiring many different ruby scripts to be modified.
- To have scripts more readable (prefering 'rubyish' style.)
Implementation: - The setting of OS constants should perhaps be one of the FIRST (if not the very first,) things done.
- They should be set in the Object objectspace, so as to NOT need any module or class qualification prefix.
- The sample file should go in a library folder: (LIBRARY FILES ARE NOT PLUGINS NOR TOOLS!!)
- WIN: %ProgramFiles%/Google/Google Sketckup 7/Library
- OSX: /Users/~/Library/Application Support/Google SketchUp 7/SketchUp/library (or similar)
- Local lib path should be 1 of first 3 in $: array
("local" here means the Sketchup local ruby lib, NOT the full install ruby lib that the ENV variable RUBY_LIB points towards.) Possible Schemes: (1) skpWriter C++ style(as used in skp Writer SDK header files by @Last Software/Google.) __APPLE__ [Note! @Last Software began Sketchup in pre-OSX days.]__LINUX____WINNT__ or _WINDOWS_* No actual value or type (a Nil class with NULL value?) * they are used like this: " if (defined __APPLE__) {...codeblock...}" (2) MSWin API C style(as used in Microsoft Windows Visual C header files.) _MAC_WIN32_WINNT__WINDOWS_* No actual value or type (a Nil class with NULL value?) * ! trailing underscore is not used in uniform manner! * they are used like this: " if (defined _WINNT_) {...codeblock...}" (3) Scintilla C style(as used in Scintilla/SciTE configuration and header files.) PLAT_MACOSXPLAT_GTK [*just shown because he uses it so much; GTK+ on Linux or Win32.]PLAT_LINUX [Neil Hodgson really uses PLAT_GTK for GTK+ on Linux.]PLAT_WIN [in addition, Neil has PLAT_GTK_WIN32 when GTK+ is running on Win32.]PLAT_WX [PLAT_WX is wxWindows on any supported platform.] * Neil actually assigns values 0 or 1 to these constants * they are psuedo-boolean, & used 2 ways; as above in C header files, * and like: " if PLAT_WIN {...codeblock...}" in SciTE Code Editor properties. (4) 'Rubyish' style(A NEW style we make up to be 'Rubyish' boolean constants with "?" mark.) OS_is_MAC? [Note! Ruby GNU config uses 'MAC' to mean old MacOS pre OSX!]OS_is_WIN?OS_is_LNX?OS_is_OSX? * they would be used like: " if OS_is_WIN? {...codeblock...}" Conclusion: - It does not matter (to me,) what names for the constants are chosen, (although I prefer the 'rubyish' style for ruby;) style (1) constants have already found their way into ruby, ie: __FILE__ etc.
- I prefer these be set in a standalone script that could be loaded even before the 'sketchup.rb' script; ie: load("platform.lib.rb") command at the top of of the first script run by Sketchup, which can vary from user to user.
- [I have have a script I'm writing that is both the ABSOLUTE FIRST script to load, and also needs to take advantage of these OS constants. Which would mean actually that the OS constant setter script would be the 1st to be completed.]
- So someone take a poll, or paste this doc on the wall and throw a dart; give us a common set of OS constants.
* UPDATED *Sample script: 'platform.lib.rb' - - - - for example ONLY, not for USE ! - Changing case sensitivity global $= is now deprecated; so we'll just simplify things and downcase the RUBY_PLATFORM side of comparisons.
- OS.is? return strings simplified for conditional matching. (ie, using in a case/when block)
- Code: Select all
# Boolean OS Constants declared in the Objectspace OS_is_UNKNOWN? = false OS_is_LNX? = false # this Linux constant # is proposed to be commented out or removed
if RUBY_PLATFORM.downcase.include?( 'win32' ) OS_is_WIN? = true # also true for SU running on Linux under WINE OS_is_OSX? = false elsif RUBY_PLATFORM.downcase.include?( 'darwin' ) OS_is_OSX? = true OS_is_WIN? = false # Proposed: comment out or remove linux clause elsif RUBY_PLATFORM.downcase.include?( 'linux' ) OS_is_LNX? = true OS_is_OSX? = false OS_is_WIN? = false else OS_is_UNKNOWN? = true OS_is_OSX? = false OS_is_WIN? = false end
module OS def self.is?( param = 'query' ) # # Double-duty method returns boolean # if a param is given; # or an OS string if the param is blank # case param.to_s.downcase when 'win','wind','win32','winnt','window','windows','mswin' then OS_is_WIN? when 'mac','osx','apple' then OS_is_OSX? when 'lnx','linx','linux' then OS_is_LNX? when 'dunno','unk','unknown' then OS_is_UNKNOWN? when 'query' # simplified for conditional matching return 'WIN' if OS_is_WIN? return 'OSX' if OS_is_OSX? return 'LNX' if OS_is_LNX? return 'UNKNOWN' if OS_is_UNKNOWN? else return "No match for: #{param}!" # would returning nil cause boolean statement to eval as false? # maybe we should just raise a ArgumentError? end end # OS.is? end # module OS
# at this point we can use the OS constants to conditional load platform # specific libraries / modules, example: # if OS_is_WIN? then require('WIN32API')
# Can't put this in loaded_files array here because it hasn't been init'd yet! # IF it's neccesary, then 'sketchup.rb' can do it, by checking defined? any one # of the constants.
end script: 'platform.lib.rb' - - - - - - - - - - - - - - - - - - - - - - - -
Last edited by Dan Rathbun on Thu Nov 12, 2009 11:58 pm, edited 2 times in total.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Thu Nov 05, 2009 5:55 pm
Come on People!
Weigh in...
Do you have any preferences?
Do you 'like' or 'dislike' any of the 4 proposed constant styles?
..OR can you propose any other constant style?
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Thu Nov 05, 2009 6:10 pm
My vote goes for #4 - Ruby style.
-

thomthom
- PluginStore Author

-
- Posts: 19478
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Chris Fullmer » Thu Nov 05, 2009 6:21 pm
Ruby also for me I think. I'm not sure I quite understand all of it, but I think you are proposing a constant that holds the OS so it is easily used throughout the skx?
Chris
-

Chris Fullmer
- SketchUp Team

-
- Posts: 6929
- Joined: Wed Nov 21, 2007 3:21 am
- Location: Boulder, CO
- Name: Chris Fullmer
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by thomthom » Thu Nov 05, 2009 9:52 pm
Why is Mac (pre OSX) and Linux there anyway? Withing Sketchup's world we never experience them.
-

thomthom
- PluginStore Author

-
- Posts: 19478
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Chris Fullmer » Thu Nov 05, 2009 10:39 pm
There are a few linus users out there...though I don't know that they can use many rubies  Chris
-

Chris Fullmer
- SketchUp Team

-
- Posts: 6929
- Joined: Wed Nov 21, 2007 3:21 am
- Location: Boulder, CO
- Name: Chris Fullmer
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by thomthom » Thu Nov 05, 2009 10:46 pm
Chris Fullmer wrote:There are a few linus users out there...though I don't know that they can use many rubies  Chris
But they run under Wine, so they'd be using the Windows environment.
-

thomthom
- PluginStore Author

-
- Posts: 19478
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Fri Nov 06, 2009 12:21 am
thomthom wrote:Why is Mac (pre OSX) and Linux there anyway? Withing Sketchup's world we never experience them.
- GENERALLY: I wanted to show some variety in the OS constant examples from the styles used by other 'projects'.
- LINUX: Although Google current policy / planning is that they will probably not port a Sketchup edition to Linux anytime soon, (they cite a lack of Linux driver support by major graphics card OEMs,) it is hoped by many [including myself] that this will change.
- So defining a Linux constant leaves the door open.
- However, it's likely I would comment it out in the module (since most people would anyway.) So it (the Linux constant,) would just be 'reserving' the word for possible future use.
- MAC vs OSX: I wanted to stress the difference used in the ruby world (viz, the ruby GNU configurator,) in the use of 'MAC' for MacOS.
- But more Importantly, I have also outlined an edition of the OS module for full ruby install that has ALL of the GNU operating system constants.
- So.. I kinda want the two 'editions' to be compatible. If 'MAC' in the full edition means MacOS, then it can't mean 'any Mac' in the Sketchup version. (Besides, 'Mac' by itself, is a product line, not an OS.)
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Fri Nov 06, 2009 12:30 am
Chris Fullmer wrote:There are a few linux users out there...though I don't know that they can use many rubies 
Thomas is correct, they run Sketchup under a Win32 virtual environment, so they would get a true return for OS_is_WIN? However.. outside SU, and the WINE emulator.. in Linux they can run any rubies they wish under the full install. I have SuSe Linux 11.x (on a separate harddrive,) and it came with Ruby as part of the install package.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Fri Nov 06, 2009 12:37 am
But the SKX lib is extending the SU classes... so would there be a use for them outside the Sketchup world?
-

thomthom
- PluginStore Author

-
- Posts: 19478
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Fri Nov 06, 2009 3:37 am
thomthom wrote:But the SKX lib is extending the SU classes... so would there be a use for them outside the Sketchup world?
SU Classes... perhaps not... perhaps maybe, if the SU ruby way becomes a defacto standard for 3D model classes, much like ACAD DWG became a defacto standard. But there is also a need to determine OS constants in the outside ruby world, that is simplified and quick as well. I actually began writing the OS module before I knew what the SKX project was all about.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Skx Extension Library
|