【问题标题】:GiMP (Scheme) Script-fu error "illegal function"GiMP (Scheme) Script-fu 错误“非法函数”
【发布时间】:2016-12-22 00:45:00
【问题描述】:

我正忙于 Script-fu 并不断收到“错误 (: 1) 非法函数”。我不是 Scheme/Lisp 专家,我只是想自动化一些摄影任务。文档很少——要么 GiMP 只写了他们自己的内部操作,而不是 Script-fu 中的 Scheme 语法,要么我找到了 GiMP v1.0 的“提示”(即过时的它们没用)。

我查看了 GiMP 提供的一堆脚本,试图了解更多并弄清楚这一点,但无济于事。我在这里寻求帮助以消除错误,not缩进布局或Python-fu存在的事实等。

然后,代码(简化为功能框架):

;;
;; license, author, blah blah
;; FOR ILLUSTRATION PURPOSES
;; GiMP 2.8 LinuxMint 18.1
;; does the work, but then blows up saying "Error ( : 1) illegal function"
;;

(define (script-fu-ScriptFails InImage InLayer pickd mrge)
  (let* (
      (CopyLayer (car (gimp-layer-copy InLayer TRUE)) )
    )
    (gimp-image-undo-group-start InImage)
    (gimp-image-add-layer InImage CopyLayer -1)
    (gimp-drawable-set-visible CopyLayer TRUE)
    ;; Perform CHOSEN action on CopyLayer
    (if (equal? pickd 0) (   ;; keep just the RED
      (plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE  1.0 0 0  0 0 0  0 0 0)
      (gimp-drawable-set-name CopyLayer "RED")
    ))
    (if (equal? pickd 1) (   ;; keep just the GREEN
      (plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE  0 0 0  0 1.0 0  0 0 0)
      (gimp-drawable-set-name CopyLayer "GRN")
    ))
    (if (equal? pickd 2) (   ;; keep just the BLUE
      (plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE  0 0 0  0 0 0  0 0 1.0)
      (gimp-drawable-set-name CopyLayer "BLU")
    ))
    (if (equal? mrge #t) (   ;; to merge or not to merge
      (gimp-layers-flatten InImage)
    ))
    (gimp-image-undo-group-end InImage)
    (gimp-display-flush)
  )
)

(script-fu-register "script-fu-ScriptFails"
  _"<Image>/Script-Fu/ScriptFails..."
  "Runs but fails at the end. Why? Please help!"
  "JK"
  "(pop-zip,G-N-U)"
  "2016.12"
  "RGB*"
  SF-IMAGE       "The Image"    0
  SF-DRAWABLE    "The Layer"    0
  ;; other variables:
  SF-OPTION      "Effect"  '("R_ed" "G_rn" "B_lu")
  SF-TOGGLE      "Merge Layers" FALSE
)

【问题讨论】:

    标签: scheme gimp script-fu


    【解决方案1】:

    看起来您使用括号作为块。例如:

    (if (equal? pickd 2) (   ;; keep just the BLUE
          (plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE  0 0 0  0 0 0  0 0 1.0)
          (gimp-drawable-set-name CopyLayer "BLU")
        ))
    

    你看到关于保持蓝色的评论之前的开头括号了吗?那么这意味着你正在这样做:

    ((plu-in....) (gimp-drawable...))
    

    当然,第一个函数需要返回一个有效的 Scheme 函数,而第二个函数的返回值将是提供的参数。如果你想因为它们的副作用而做两个表达式,那么你应该使用一个块。就像 C 方言块中的花括号是 Scheme 中以 begin 开头的形式:

    (begin
      (plu-in....)
      (gimp-drawable...))
    

    因此,这将对表达式求值,如果最后一个表达式也是函数的尾部,则它的结果就是结果。

    同样,if 也只有一个结果,并且没有其他选择,使用 when 会给你一个开始:

    (when (equal? pickd 2) ;; keep just the BLUE (and no extra parens)
      (plug-in-colors-channel-mixer TRUE InImage CopyLayer FALSE  0 0 0  0 0 0  0 0 1.0)
      (gimp-drawable-set-name CopyLayer "BLU"))
    

    【讨论】:

    • 非常感谢,西尔韦斯特。您对“开始”的解释完全有道理——我在尝试学习一些方案时忽略了这一点。我看了这么多不同的例子和其他脚本,我开始被催眠了。使用 when 将其更改为正确的语法使一切正常。我让我的传统 C 脑试图为这两条指令创建一个块。计划,另一个小故事。有趣的学习。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2018-08-02
    • 2018-08-02
    • 1970-01-01
    相关资源
    最近更新 更多