Re: mixed language coding

Paolo Molaro wrote:

On 06/19/01 Jim Edwards wrote:

1.  Write all the gui in c and call the perl code from within callback
wrappers written in c.
    This seems like it would involve a lot of interface writing.

Uhm, I don't know if this makes sense: if the non-ui part is already
written in C and you write also the GUI in C, where does perl fit?

There is existing non-ui perl code which is not part of the gui, there is
also a good deal of non-ui c code.

2.  Write the part of the gui for the perl in perl and  the rest in c -
I think i would then need many fewer calls from c to perl
      possibly only two - one to setup the interface and another to
invoke the dialog.

Does anyone know of an example that does this and what kind of problems
i might encounter?

It depends what kind of graphical interface you need or how complex is the
interface to the C code. Basically:

1) if the C interface is complex, just maintain the C program and
embed a perl interpreter that will be invoked to do the GUI stuff
(this is the way I did the perl bindings for AbiWord). perlembed
is the manpage you're looking for to do this.

2) the C interface is simple: wrap it in an XS module and use that module
in your GUI program written in perl (you will need the perlxs and perlguts
manpages for this item). This is a solution that allows for more
flexibility: it may be worth it even if the C interface is complex
(for example creating the XS module for the Gtk+ library surely was
worth it:-).

The first solution may be more simple if you don't know (or don't want
to know:-) how XS works.

I've got lots of painful experience in XS.  I really was hoping to find
someone who had already tried this.

I think that the route I am considering at this point is as follows:

1. Rewrite the perl/Tk to Gtk-Perl using glade

2.  Write the gtk+ interface to the c in c using glade

3.  Write new XS to call the c interface routines from perl.  I shouldn´t
need more than a few of these calls.

4.  Run the mainloop from perl.

    So my question really is that I intend to assign some callbacks to c code
and others to perl code -  If I stick to assigning callbacks to perl from the
perl side and callbacks to c from the c side, should it be doable or does
someone out there know of a problem I will encounter.  What if I want to
assign a callback to c from the perl side - or one to perl from the c side?
I assume I would need to assign the callback to the same language and write a
wrapper to the other...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]