Hi all,
I'm thinking about adding some configurable default attributes to a
newly placed pin.
I thought about two options:
  - Option 1: Load a list with name,values of attributes to be added
from the file gschemrc.
  - Option 2: Write an add-pin-hook function and do it in scheme.

By now I like option 2, but my knowledge about C interfacing to scheme
is limited, so I have some doubts...

At the end of o_pin_end function I added:

  if (scm_hook_empty_p(add_pin_hook) == SCM_BOOL_F &&
      o_current != NULL) {
    scm_run_hook(add_pin_hook,
                 scm_cons(g_make_attrib_smob_list(w_current, o_current),
                          SCM_EOL));
  }

so the new hook is run. As I understand, the first two parameters are
w_current and o_current.

The new hook is run, and if I put into gschemrc the following:

(define (print-all-attributes attribute-list)
  (for-each (lambda (attribute) (display attribute)) attribute-list))

(add-hook! add-pin-hook print-all-attributes)

I get nothing printed: the attribute list is empty. This isn't
surprising because by default, a pin has no attributes.

Now I wrote a very basic (and untested) scheme function which calls to
o_attrib_add_attrib:

SCM
g_add_attrib(SCM scm_wcurrent, SCM scm_object, SCM scm_newtext, 
             SCM scm_vis, SCM scm_show)
{
  TOPLEVEL *w_current = (TOPLEVEL *) SCM_SMOB_DATA(scm_wcurrent);
  OBJECT *object = (OBJECT *) SCM_SMOB_DATA (scm_object);
  int vis, show;
  gchar *newtext=SCM_STRING_CHARS(scm_newtext);

  vis = SCM_INUM(scm_vis);
  show = SCM_INUM(scm_show);

  o_attrib_add_attrib (w_current, newtext, vis, show, object);

  return SCM_BOOL_T;

}

This function is registered in g_register.nw as:
  scm_c_define_gsubr ("add-attribute-to-object", 5, 0, 0, g_add_attrib);


I expect to be able to call this function inside the add-pin-hook
function, just adding the new parameters. The problem is: how can I do
it? if I try to print all the arguments to the add-pin-hook function, I
get an empty list.
Even if I do:
(define (print-all-attributes attribute-list)
  (display "Parameter List length: ")
  (display (length attribute-list))
  (display ".\n")
  (for-each (lambda (attribute) (display attribute)) attribute-list))
(add-hook! add-pin-hook print-all-attributes)

It reports a 0 elements list. Where have w_current and o_current gone?

Any ideas?. Thanks,

Carlos

Reply via email to