|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
How to not lose all your money in the 'slot machine'Section 21.6 in the YUM states (sic) ...
long int YAP_NewSlots(int NumberOfSlots) Allocate NumberOfSlots from the stack and return an handle to the last one. Th eother hand can be obtained by decrementing the handle. ... so I implemented ... long int sl = YAP_NewSlots(2); YAP_PutInSlot(sl,YAP_ARG5); YAP_PutInSlot(sl-1,YAP_ARG4); // handle decremented as documented ...do prolog callback... YAP_Term x4 = YAP_GetFromSlot(sl-1); // handle decremented as documented YAP_Term x5 = YAP_GetFromSlot(sl); YAP_RecoverSlots(2); ... and all hell broke loose ... The 'sl-1' slot never had a valid value and after swapping the arguments I had an 'aha moment' when it was still the 'sl-1' slot that was wrong. Changed 'sl-1' to 'sl+1' and it's now ok. Regards, Tony, Durban, South Africa PS I will soon be releasing 'tinka' (initially x86 only) - an open source glue framework for using Yap (and later others) with any shared library api, including callbacks. Hope this whets a few appetites and nobody considers it spam. Example of GTK+2 Tutorial 'Hello World' example in tinka_for_yap (original C at end): destroy(_,_) :- gtk_main_quit. delete_event(_,_,_,1) :- g_print('delete event occurred\n'). hello(_,_) :- g_print('Hello World\n'). :- % GTK tut Hello World argCVAddress(AC,AV), gtk_init(AC,AV), gtk_window_new( topLevel,W), g_signal_connect(W,delete_event,delete_event/3+1,null), % % for example the individually loadable definitions for the above API call are: % % api(g_signal_connect_data,'libgobject-2.0.so', % [gPointer,pStr,cDecl(gCallback),gPointer,gClosureNotify,in=gConnect], % gULong,[]/*return code check - default to fail on null*/). % g_signal_connect(A,B,C,D) :- % g_signal_connect_data(A,B,C,D,0,0). % gConnect( after, 1). % gConnect( swapped, 2). % ... various gXxx type definitions % % all the rest is dynamic at execution time as traced below % (Note that 'git' refers to 'gist in time'; not git the best revision control system) % % % git - g_signal_connect/4 % % found gist - g_signal_connect/4 % g_signal_connect(A,B,C,D) :- % g_signal_connect_data(A,B,C,D,0,0). % % git - g_signal_connect_data/6 % % found api - g_signal_connect_data % :- assertz(dll_(g_signal_connect_data,'libgobject-2.0.so',[iaciiivz,iaiiiivz])). % g_signal_connect_data(A,B,C,D,E,F) :- % g_signal_connect_data(A,B,C,D,E,F,_). % g_signal_connect_data(A,B,C,D,E,F,G) :- % lookup(gConnect,F,H), % dllCall(g_signal_connect_data,(A,B,C,D,E,H),G). % % git - gConnect/2 % % found gist - gConnect/2 % gConnect(after,1). % gConnect(swapped,2). % % api(g_signal_connect_data,(135690240,delete_event,delete_event/3+1,null,0,0),_2906). % % apiIn(iaciiivz). % % apiOut(iaciiivz,(135690240,delete_event,delete_event/3+1,null,0,0),6). % g_signal_connect(W,destroy,destroy/2,null), gtk_container_set_border_width(W,10), gtk_button_new_with_label('Hello World',B), g_signal_connect(B,clicked,hello/2,null), g_signal_connect_swapped(B,clicked,gtk_widget_destroy/1,W), gtk_container_add(W,B), gtk_widget_show(B), gtk_widget_show(W), gtk_main. /* #include <gtk/gtk.h> static void hello( GtkWidget *widget, gpointer data ) { g_print ("Hello World\n"); } static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { g_print ("delete event occurred\n"); return TRUE; } static void destroy( GtkWidget *widget, gpointer data ) { gtk_main_quit (); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); button = gtk_button_new_with_label ("Hello World"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (hello), NULL); g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (window)); gtk_container_add (GTK_CONTAINER (window), button); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return 0; } */ ------------------------------------------------------------------------------ Check out the new SourceForge.net Marketplace. It is the best place to buy or sell services for just about anything Open Source. http://p.sf.net/sfu/Xq1LFB _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
| Free embeddable forum powered by Nabble | Forum Help |