On Wed, Aug 18, 2004 at 09:11:17AM +0200, Leopold Toetsch wrote:
> You've mixed up the function parameters.
> 
> >   P0 = global "Gtk::gtk_window_new"
> >   null I5
> >   invoke
> 
> >   P15 = P5
> 
> I presume that's "instance" ...
actually shouldnt the callback is for the button

> >   # -- function sig is "'lptpPi', then we have:
> >   #    P5 is the button
> >   #    P6 the callback
> >   #    P7 data we may to pass through.
> >   #    S5 "clicked"
> >   #    I5 is 0
> 
> ... and the button is the "gobject". I did:
> 
>     set P6, P5        # the callback
>     set P5, P15 # instance
>     set S5, "clicked"
>     set P7, P11       # button = object
> 
> And got a clickable button labeled "Parrot".
do you mean the callback worked? as I dont get it to on my system
(ie if I activate the callback the it seg faults).

> You might start using PIR code and named variables so that it gets
> simpler to call such functions.

Ok I have changed this a bit and should be more readable.
Mainly attached is the C version of this small example, and the parrot
version is just about a conversion to it line be line.

(its simply a slightly modified of the Gtk tutorial "hello world",
where instead of using the #defined g_signal_connect it uses the
g_signal_connect_object function)

Unless Im overlooking something the parrot version mimics exactly
whats the C version does.  Just still cant get it to work out the
callback.

> leo
Thanks always,
Stephane

/*
 * Compile this with:
 *
 *   gcc hello.c -o hello `pkg-config --cflags --libs gtk+-2.0`
 */
#include <gtk/gtk.h>

static void hello( GtkWidget *widget,
                   gpointer   data )
{
    g_print ("Hello\n");
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button;
    
    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    button = gtk_button_new_with_label ("Parrot");
    
    g_signal_connect_object (G_OBJECT (button), "clicked",
                             G_CALLBACK (hello), NULL, 0);
    
    gtk_container_add (GTK_CONTAINER (window), button);
    
    gtk_widget_show (button);
    
    gtk_widget_show (window);
    
    gtk_main ();
    
    return 0;
}
# -- Gtk Button Example.

.sub _gtkcallback
  print "Hello\n"
.end

.sub _main @MAIN
  .include "gtk.pasm"

  .local pmc window
  .local pmc button
  .local pmc callback
  .local pmc userdata

  P0 = global "Gtk::gtk_init"
  I5 = 0
  invoke

  # -- create the window
  P0 = global "Gtk::gtk_window_new"
  null I5
  invoke
  window = P5

  # -- create the button
  P0 = global "Gtk::gtk_button_new_with_label"
  S5 = "Parrot"
  invoke
  button = P5


  # -- install callback?
  newsub P6, .Sub, _gtkcallback
  new P7, .Integer  # -- just give it something even if dont care
  set P7, 42
  userdata = P7

  new_callback P5, P6, P7, "Ut"

  callback = P5

  # -- function sig is "'lptpPi', then we have:
  #    P5 is the button
  #    P6 the callback
  #    P7 data we may to pass through.
  #    S5 "clicked"
  #    I5 is 0
  # -- Uncomment this section to actually install the callback
  # -- (this segfaulst on my system)
#  P0 = global "Gtk::g_signal_connect_object"
#  P5 = button
#  S5 = "clicked"
#  P6 = callback
#  P7 = userdata
#  I5 = 0
#  invoke
  # -- .

  # -- Set the container.
  P5 = window
  P6 = button
  P0 = global "Gtk::gtk_container_add"
  invoke

  # -- show button
  P5 = button
  P0 = global "Gtk::gtk_widget_show"
  invoke

  # -- show window
  P5 = window
  P0 = global "Gtk::gtk_widget_show"
  invoke

  P0 = global "Gtk::gtk_main"
  invoke

  end
.end
saveall
loadlib P1, 'libgtk-x11-2.0'
dlfunc P2, P1, 'gtk_init', 'vii'
store_global 'Gtk::gtk_init', P2
dlfunc P2, P1, 'gtk_main', 'vv'
store_global 'Gtk::gtk_main', P2
dlfunc P2, P1, 'gtk_widget_show', 'vp'
store_global 'Gtk::gtk_widget_show', P2
dlfunc P2, P1, 'gtk_container_add', 'vpp'
store_global 'Gtk::gtk_container_add', P2
dlfunc P2, P1, 'gtk_button_new_with_label', 'pt'
store_global 'Gtk::gtk_button_new_with_label', P2
dlfunc P2, P1, 'gtk_window_new', 'pi'
store_global 'Gtk::gtk_window_new', P2
dlfunc P2, P1, 'g_signal_connect_object', 'lptpPi'
store_global 'Gtk::g_signal_connect_object', P2
restoreall

Reply via email to