Stop processing rest of file?
-
So far I am trying my best to NOT touch or override either
requireorloadthemselves. -
have a separate loader.rb that checks if LIB exists and has functions required.
if yes, require/load rest of your code, if not ... -
Having to have yet ANOTHER file for each and every library or plugin package, is not what I am aiming at...
... besides that does not solve the idiot situation, trying to force a plugin to load, using
load(), whenrequiredoes not work.
I'm not sure there is a solution to the idiot syndrome anyway. I (personally,) would not give any support, or waste any time responding, to an idiot who does not let the plugin load the way it's supposed to. -
ThomThom, for now do something like:
module TT_FancyUtil # move require dependancy calls inside namespace require('TT/TT_Lib2') rescue raise(LoadError,'TT_Lib2') require('TT/TT_GUI') rescue raise(LoadError,'TT_GUI') # the rest of the module's code # way down the bottom of the namespace block; rescue LoadError => e case e.message when 'TT_Lib2' puts("LoadError; TT_Lib2 file is not present. .. blah blah blah...") when 'TT_GUI' puts("LoadError; TT_GUI file is not present. .. blah blah blah...") else puts("Error; #<#{e.class.name}; #{e.message}>") puts e.backtrace end end # module -
@unknownuser said:
have a separate loader.rb that checks if LIB exists and has functions required.
if yes, require/load rest of your code, if not ...Really don't want to use another file. Many of my plugins are self contained in a single file - apart from that they require TT_Lib. And I don't want to split it up just for this check.
-
Found a way:
<span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /></span><span class="syntaxdefault">begin<br /> require </span><span class="syntaxstring">'TT_Lib2/core.rb'<br /></span><span class="syntaxdefault">rescue LoadError </span><span class="syntaxkeyword">=></span><span class="syntaxdefault"> e<br /> </span><span class="syntaxcomment"># meh!<br /></span><span class="syntaxdefault">end<br /><br />module MagicPlugin<br /> </span><span class="syntaxcomment"># Voodoo<br /></span><span class="syntaxdefault">end if defined</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> TT</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Lib </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span> -
interesting!
Hmm ... I see
rescuemodifiers do not work withrequire(), for some reason ?You could also do (if you did not want any module defined) ...
require 'sketchup.rb' begin require 'TT_Lib2/core.rb' rescue LoadError => e # meh! else module MagicPlugin # Voodoo end end# begin -
@dan rathbun said:
Hmm ... I see rescue modifiers do not work with require(), for some reason ?
What you mean? What modifiers?
-
statement modifiers = conditional statements onto the end of a normal statement
` name = first_name + last_name rescue "John Doe"
John Doe # if first_name and last_name are not defined`
-
@thomthom said:
@dan rathbun said:
Hmm ... I see rescue modifiers do not work with require(), for some reason ?
What you mean? What modifiers?
The conditional keywords
ifandunlesscan be used in block position:
[if|unless] (expression)
statements
endor modifier position:
statement[if|unless] (expression)**rescue**can also be used in modifier poistion, but ... my attempt at this:
require('booboo.rb') rescue nil
... does NOT trap theLoadError(becauseLoadError < ScriptError < Exception, andrescueonly trapsRuntimeErrorand subclasses by default.)For a one-liner, we must use semi-colons:
begin require('booboo.rb'); rescue Exception; nil; end
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement