1

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

我查看了 GiMP 提供的一堆脚本,试图了解更多并弄清楚这一点,但无济于事。我在这里寻求帮助以消除错误,而不是缩进布局或 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
)
4

1 回答 1

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...))

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

(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"))
于 2016-12-22T13:18:03.840 回答