It is currently Fri Mar 29, 2024 5:17 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 12:01 pm  (#21) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
Script-Fu Console - Interactive Scheme Development

> round
#<CLOSURE>
> (get-closure-code round)
(lambda (num) (let* ((result 0) (absolut (trunc num)) (decimal (- num absolut))) (if (> decimal 0) (if (< decimal 0.5) (set! result absolut) (set! result (+ absolut 1))) (set! result absolut))))

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 12:06 pm  (#22) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Aha! Where the hell did that come from?!


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 12:11 pm  (#23) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
@Odin
There are 4 special files in your system scripts folder which affect Script-Fu operation:
- script-fu.init
- script-fu-compat.init
- script-fu-util.scm
- plug-in-compat.init
Can you zip these files and attach here so we can check them.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 12:15 pm  (#24) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Excellent!

One way to search for the script that is redefining 'round' would be with grep. From a shell terminal, try the following two commands:

grep 'absolut\s' ~/.gimp-2.8/scripts/*.scm

grep 'absolut\s' /usr/share/gimp/2.0/scripts/*

One of them should return a file (or files) that include the 'absolut' variable.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 1:08 pm  (#25) 
Offline
GimpChat Member
User avatar

Joined: Jan 31, 2015
Posts: 146
Gimp 2.14 / Puppy Linux Lighthouse 64 / x86_64:

Image


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 1:18 pm  (#26) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
jontait2 wrote:
@Odin
There are 4 special files in your system scripts folder which affect Script-Fu operation:
- script-fu.init
- script-fu-compat.init
- script-fu-util.scm
- plug-in-compat.init
Can you zip these files and attach here so we can check them.
Attached.

saulgoode:
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (absolut (trunc num)) ;absolut digites of the real
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (set! result (+ absolut 1))


Attachments:
File comment: Script-Fu operation files
obc-init.7z [8.42 KiB]
Downloaded 69 times

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)
Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 1:37 pm  (#27) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Odin's special files are clean - just the standard issue with Gimp2.8

It certainly looks like that file "images-grid-layout.scm" is the culprit.
It also defines several other functions that could be troublesome:
;FUNCTIONS
(define (round num) ;returns rounded number
   (let* (
        (result 0)
        (absolut (trunc num)) ;absolut digites of the real
        (decimal (- num absolut)) ;decimal digites of the real
        )
        (if (> decimal 0)
         (if (< decimal 0.5)
            (set! result absolut)
            (set! result (+ absolut 1))
         )
         (set! result absolut)
        )       
   )
)

(define (div a b) ;returns
   (trunc(/ a b))
)

(define (less a b) ;returns less number
   (let* ((return 0))
       (if (< a b)
         (set! return a)
         (set! return b)
       )
   ) 
)

(define (scale img draw new_width new_height)
   (let* (
      (width)
      (height)
   )
      (gimp-image-undo-group-start img)
      (gimp-image-flatten img)
      ; first pass
      (set! width  (/ (car (gimp-image-width  img)) 2))
      (set! height (/ (car (gimp-image-height img)) 2))
      (gimp-selection-sharpen img)
      (gimp-image-scale img width height)      
      ; second pass
      (set! width  (/ (car (gimp-image-width  img)) 2))
      (set! height (/ (car (gimp-image-height img)) 2))
      (gimp-selection-sharpen img)
      (gimp-image-scale img width height)
      (set! draw (car (gimp-image-get-active-drawable img)))
      ; unsharp
      (plug-in-unsharp-mask 1 img draw 0.3 0.8 0)      
      (gimp-image-undo-group-end img)
      (gimp-displays-flush)
   )
)


@Saul:
What I don't understand is how defines in one user script can affect the operation of other scripts - they're supposed to be independent, aren't they?


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 1:46 pm  (#28) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Odinbc, if you obtained the images-grid-layout.scm script from https://github.com/KamilSvoboda/IGLO/bl ... layout.scm, there are four function defined on lines 45 though 99, just before where the main script gets defined. These four functions -- round, div, less, and scale -- should be moved into the main procedure's definition, just after line 100 (where 'script-fu-images-grid-layout' is defined) and before line 101 (the start of the 'let*' bindings).

By moving them into the procedure, the functions will be available for his script, but will not interfere with other scripts.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 1:56 pm  (#29) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
Thanks so much for the great detective work, everyone . :cool

If a coder is going to write global functions, using functions names which don't conflict with existing functions, might be a good idea. :hehe

Looks like the mystery is solved. :bigthup

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:14 pm  (#30) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
saulgoode wrote:
Odinbc, if you obtained the images-grid-layout.scm script from https://github.com/KamilSvoboda/IGLO/bl ... layout.scm, there are four function defined on lines 45 though 99, just before where the main script gets defined. These four functions -- round, div, less, and scale -- should be moved into the main procedure's definition, just after line 100 (where 'script-fu-images-grid-layout' is defined) and before line 101 (the start of the 'let*' bindings).

By moving them into the procedure, the functions will be available for his script, but will not interfere with other scripts.
After moving functions.
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (absolut (trunc num)) ;absolut digites of the real
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (set! result (+ absolut 1))


Attachments:
File comment: Edited copy
images-grid-layout.scm [22.13 KiB]
Downloaded 84 times

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)
Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:14 pm  (#31) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
jontait2 wrote:
@Saul:
What I don't understand is how defines in one user script can affect the operation of other scripts - they're supposed to be independent, aren't they?

There is no distinction/separation between top-level definitions in different files; the result would be the same if all of the .scm files in the scripts directories were merged into one massive file.

One can easily localize any variables or functions, but the procedures that get registered with PDB (e.g., script-fu-images-grid-layout) have to be defined at the top-level.

It is generally a poor idea to define anything but the registered procedure as a top-level, global definition. It is far better to place unregistered procedures within the definition of the main procedure that is using it (as I suggested in my previous post). At a minimum, any "utility" procedures should be named so as to avoid conflict with other functions (certainly globally re-defining a native procedure such as 'round' is not a good idea).

If some utility procedures are needed by more than one global procedure, they can be placed within their own environment, effectively creating "modules" or "packages" which isolate the procedures; but this is typically only beneficial if the file is registering several PDB commands that share some common utility functions (the Layer FX script would be a good candidate for this approach).

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:20 pm  (#32) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Odinbc wrote:
After moving functions.
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (absolut (trunc num)) ;absolut digites of the real
/home/odinbc/.gimp-2.8/scripts/images-grid-layout.scm: (set! result (+ absolut 1))

It appears that you modified the file correctly. Now, if you run GNUtux's test-calc.scm command (or run the 'round' command in the Script-fu console), the results should be correct.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:26 pm  (#33) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
Script-Fu Console - Interactive Scheme Development

> round
#<round PROCEDURE 66>

Test Calc Warning
Angle(0) horz: 1.0 vert: 0.0

Test Calc Warning
Angle(45) horz: 1.0 vert: 1.0

Test Calc Warning
Angle(90) horz: 0.0 vert: 1.0

Test Calc Warning
Angle(135) horz: -1.0 vert: 1.0

Test Calc Warning
Angle(180) horz: -1.0 vert: 0.0

Test Calc Warning
Angle(225) horz: -1.0 vert: -1.0

Test Calc Warning
Angle(270) horz: -0.0 vert: -1.0

Test Calc Warning
Angle(315) horz: 1.0 vert: -1.0

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:29 pm  (#34) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
saulgoode wrote:
jontait2 wrote:
@Saul:
What I don't understand is how defines in one user script can affect the operation of other scripts - they're supposed to be independent, aren't they?

There is no distinction/separation between top-level definitions in different files; the result would be the same if all of the .scm files in the scripts directories were merged into one massive file.

Thank you for that Saul.
I think this must be something not generally well recognised or even known about, even amongst script coders. I'm sure I've seen many scripts which do make global defintions and I've never heard mention of this fact before.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:48 pm  (#35) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
ofnuts wrote:
But really, nothing wrong with something like

I like your alternate method. I'm sure it would work fine unless someone comes along and globally redefines the modulo function. :mrgreen:

Someone needs to contact KamilSvoboda and alert him of this issue. It's not like I'm the only one who expects the round function to return correct results in script-fu/scheme. :smiley2

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 2:53 pm  (#36) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
GnuTux wrote:
Looks like the mystery is solved. :bigthup


If only.. as far as I'm concerned this is more a case of taking the lid off a can of worms!
If it really is true that every user script on a system inherits all the global defines of every other script registered at Gimp start-up there could be any number of hideous clashes still waiting to be discovered.


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 3:10 pm  (#37) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
Well, this particular mystery is solved, but you make a good point regarding globally defined functions. There might be other nasty scripts floating around out there, doing all sorts untoward things and I might have written a few of them. :lol

Proper coding practice directs that if a function is to be used locally, it should be declared as being local. If the function actually needs to be global, the coder needs to ensure the function name is unique.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 3:15 pm  (#38) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
GnuTux wrote:
...Someone needs to contact KamilSvoboda and alert him of this issue. It's not like I'm the only one who expects the round function to return correct results in script-fu/scheme. :smiley2

I have emailed Kamil Svoboda (IGLO author) with a link to this thread.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 3:19 pm  (#39) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 12978
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
GnuTux wrote:
Well, this particular mystery is solved, but you make a good point regarding globally defined functions. There might be other nasty scripts floating around out there, doing all sorts untoward things and I might have written a few of them. :lol

Proper coding practice directs that if a function is to be used locally, it should be declared as being local. If the function actually needs to be global, the coder needs to ensure the function name is unique.

This seems to have opened a big can of worms.
Would it be advantageous for me to run this test script and post it's results?
Also... Should I post my system specks along with the test results, if I post at all?

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Need Help Testing A Simple Script
PostPosted: Sun Mar 15, 2015 3:35 pm  (#40) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
Odinbc wrote:
GnuTux wrote:
...Someone needs to contact KamilSvoboda and alert him of this issue. It's not like I'm the only one who expects the round function to return correct results in script-fu/scheme. :smiley2

I have emailed Kamil Svoboda (IGLO author) with a link to this thread.

Excellent. :bigthup

Wallace wrote:
This seems to have opened a big can of worms.
Would it be advantageous for me to run this test script and post it's results?
Also... Should I post my system specks along with the test results, if I post at all?

You should be OK, Wallace. The test-calc script was just a quick tool help solve the mystery of why some users were getting incorrect results when using 3D-Extrusion.

As it turns out, someone has released a script which globally redefines several standard math functions, including the round function. GIMP users who have images-grid-layout.scm installed are potentially going to have problems with any other script that makes use these functions (i.e. 3D Extrusion).

At this point, the solution is to remove or better yet, use the updated version of images-grid-layout.scm, which SaulGoode and Odin have corrected and attached to this post.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) My Experiments On GMIC Testing filters: Simple Graphics (now 14)

1046

No new posts Attachment(s) Amazing what can be found under testing

30

No new posts Attachment(s) questions about testing with DIEGO_Render_FillingPlus

13

No new posts Testing Gmic-Qt Standalone 3.1

4

No new posts Attachment(s) New layer modes in LayerFX-2.10 for testing.

9



* Login  



Powered by phpBB3 © phpBB Group