pwgl-users: PWGLdef code to have two outlets...

View: New views
2 Messages — Rating Filter:   Alert me  

pwgl-users: PWGLdef code to have two outlets...

by padovani-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I'm working on a library for PWGL and in some functions/boxes I would
like to have two or more outlets...
I have seem that it can be done with OMPW define-box, but didn't found
any code in PWGL library folder that make that without OMPW...

thanks for any tips,
josé

--
http://www.padovani.googlepages.com


Re: pwgl-users: PWGLdef code to have two outlets...

by Mikael Laurson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Try this:

(defpackage :mypackage)
(in-package :mypackage)

;; Case 1 For special box behavior with 2 or more outputs:

; ; normally for multi output case define a subclass of PWGL-box:
(defclass my-out-test (ccl::PWGL-box) ())

;; return different outputs, this overrides the normal box evaluation:
(defmethod ccl::patch-value :around ((self my-out-test) output)
   (multiout-patch-value self (position output (ccl::pwgl-outputs  
self))))

(defmethod multiout-patch-value ((self my-out-test) (outnum (eql 0)))
   (ccl::nth-patch-value self 0))

(defmethod multiout-patch-value ((self my-out-test) (outnum (eql 1)))
   (1+ (ccl::nth-patch-value self 0)))

;; define the box:
(ccl::PWGLDef out-test ((a 0))
     "out test"
     (:class 'my-out-test :outputs 2)
   ())


;; Case 2 If you are using a function that returns several results  
using the Lisp 'values'  function
;; such as 'truncate', you can use directly the kernel 'ccl::PWGL-
values-box class:

(ccl::PWGLDef pwgl-trunc ((val 0) (y 1))
     "pwgl-trunc"
     (:class 'ccl::PWGL-values-box :outputs 2)
   (truncate val y))

You can find more examples in the
  'documentation/programming/box examples' folder.

Mikael

On Apr 9, 2009, at 5:26 PM, padovani wrote:

> Hi,
> I'm working on a library for PWGL and in some functions/boxes I  
> would like to have two or more outlets...
> I have seem that it can be done with OMPW define-box, but didn't  
> found any code in PWGL library folder that make that without OMPW...
>
> thanks for any tips,
> josé
>
> --
> http://www.padovani.googlepages.com
>