[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
another problem interfacing prolog and C
From: |
Erick Alphonse |
Subject: |
another problem interfacing prolog and C |
Date: |
Sun, 05 Dec 2004 22:37:57 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 |
Hello,
Still playing with the interface, I would like to call C from prolog and
then from this C function call prolog back. Unfortunately, I can't get
it working.
% examp.pl
:- initialization(top).
:- foreign(call_c(+term,-term)).
top :-
call_c(a,_L).
% examp_c.c
#include <string.h>
#include "gprolog.h"
Bool
call_c(PlTerm In,PlTerm* Out)
{
Pl_Query_Begin(TRUE);
Pl_Query_Call(Find_Atom("write"),1,&In);
Pl_Query_End(PL_RECOVER);
*Out = Mk_Atom(atom_nil);
return PL_SUCCESS;
}
And I get :
874# gplc examp.pl examp_c.c
875# ./examp
warning: /home/alphonse/tmp/bug-prolog/examp.pl:1: user directive failed
a
GNU Prolog 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
| ?-
That is, the variable _L in top/0 cannot be unified at the exit of
call_c, like if the inner query was messing with the stack. If I comment
the inner query, it works of course. Could someone help me out and tell
me if, first, what I try to do is possible with the gprolog interface
and how to do it properly? I can't figure it out myself as I guess I
exhausted all the examples in the doc.
Thanks in advance for your help, hopefully I could get back to work.
Erick.