How to write an assert in Script-Fu/Tiny-Fu?!?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hello,

I am new to scripting in the Gimp 2.4 but I have managed to pick up the basics due to some good tutorials.  What I didn't come across is a way to create an assert function in script-fu/tiny-fu and I'm wondering how to do that.  To give you an idea of what I mean here's how I use it in other languages like C:

assert( BuildingHeight > 0 );

Since I know for example the height of the building must be higher then zero I can assert that fact.  In C/Perl/Java or whatever other language I'm asserting if BuildingHeight is less then zero it will halt the program and print an error.  

Internally the assert looks like this say in Perl:

sub MyAssert($)
   {
   if ($_[0])
      {
      #do nothing assertion is true
      }
   else
      {
        $Carp::CarpLevel = 1;
      print "\nAssertion failed Terminating Program\n";
      confess("Assertion failed");
      }
   }

Where here confess prints a stack trace in Perl.  Now I know that we probably can't print stack traces but I already know that I can print errors to console using:

   (gimp-message-set-handler 1)
   (gimp-message ErrorToDisplay )

However I'm wondering how to call a function and pass in a conditional output.  I'm guessing how it might look is something like this:

( define
   (
   MyAssert
      Conditional
   )
   ( if ( Conditional )
      (begin
      ;do nothing assertion is true
      )
     ;else
      (begin
      (gimp-message-set-handler 1)
      (gimp-message ErrorToDisplay )
      ( HALT the script somehow!? )
       )
   );endif
)


Though I'm still really new at Script fu.  Can someone please tell me is there a way to pass a conditional to a routine or the output of a conditional rather?  Since calling Assert will look something like this I imagine:

( assert ( > BuildingHeight 0 ) )

Also how do you halt a script?  Any other tips or ideas?  In other languages printing the stack trace as well as the file and line number that the assertion failed upon is very useful.  Though I'm not sure if this is possible in Script-fu.  These are just my basic ideas and I'm really new to Script-Fu.  But I'd really like to be able to use assert in script-fu as I do in all other languages to protect against nasty bugs.

I also posted this message to the Gimp-User mailing list though I thought this might be an appropriate (or more appropriate?) form as well. 

Thanks.
       
---------------------------------
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

[Non-text portions of this message have been removed]


Photo 4 Less

[Gimp Developers]     [Gimp Users]     [Photos]     [Yosemite News]     [Yosemite Photos]    [Epson Inkjet]     [Scanner]     [Gimp's Home]     [Steve's Art]

Add to Google Powered by Linux