(defmodule ##extension-name##-BINDER
    (import BINDER deftemplate unbound-table-instance watchable-table-instance parameter)
    (import BINDER deffunction table-new modeler-new modeler-bind-input modeler-weak-bind-input modeler-bind-output table-set-property)
)

(defglobal ?*current-modeler* = nil)

(deffunction set-modeler-instance-to (?instance)
    (bind ?*current-modeler* ?instance)
)

(deffunction create-modeler-instance ()
    (set-modeler-instance-to (modeler-new ##extension-name##))
    ?*current-modeler*
)

(deffunction bind-input-table (?schema $?attributes)
    (if (neq (validate-table-spec ?schema ##extension-name##) 0) then 
        (bind ?new-table (table-new ?schema read))
        (bind ?chunk (create$))
        (loop-for-count (?n 1 (length$ ?attributes)) do
            (bind ?element (nth$ ?n ?attributes))
            (if (eq ?element ":attr:") 
                then 
                    (table-set-property ?new-table (expand$ ?chunk))
                    (bind ?chunk (create$))
                else
                    (bind ?chunk (create$ ?chunk ?element))
            )
        )
        (modeler-bind-input ?*current-modeler* ?new-table)
    )
)

(deffunction watch-table (?table-id)
    (modeler-weak-bind-input ?*current-modeler* ?table-id)
)

(deffunction bind-output-table (?output)
    (modeler-bind-output ?*current-modeler* ?output)
)

(deffunction attribute ($?val)
    (create$ $?val ":attr:")
)
 
 (deffunction runtime-param (?name)
     (do-for-fact ((?p parameter)) (eq ?p:name ?name) (return ?p:value))
     (return FALSE)
 )
 
(deffunction has-runtime-param (?name)
    (any-factp ((?p parameter)) (eq ?p:name ?name))
)

