[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: foreign predicate not working
From: |
Paulo Moura |
Subject: |
Re: foreign predicate not working |
Date: |
Mon, 19 Jul 2004 15:35:00 +0100 |
On 19/jul/2004, at 15:25, Saurabh Bhatla wrote:
Hi
I am using a foreign predicate from my logtalk object. I define that
in a file receiver.lgt (attached). the definition of my predicate is in
file file_ops.c (attached). I can compile the code in gprolog and am
able to make an executable out of it too. The problem is that whenever
i
call the foreign predicate it returns false. I have some printf
statements in my C code but none of them gets printed, which mean that
the c code is not being called at all.
I tried to trace the execution and the call to my foreign predicate
simply fails without checking anything. My C program works fine when
executed alone.
Your definition of the Logtalk object receiver seams to be wrong. The
code you sent us is:
:- foreign(get_event_ob(+string,-string)).
:-object(receiver).
:-public(receive/1).
:-public(validate/1).
:-public(get_event_ob/2).
receive(Event).
validate(Event):-
self(Self),
Self::get_event_ob(Event,Object),
write(Object),
write('<-object found for event->'),
write(Event),nl.
validate(Event):-
write('No object found for event->'),
write(Event),nl.
:-end_object.
The problem is that the predicate get_event_ob/2 is not defined inside
the object "receiver". You need to write:
validate(Event):-
self(Self),
{get_event_ob(Event,Object)}, % external call; the {}/1 construct
bypasses the Logtalk pre-processor
write(Object),
write('<-object found for event->'),
write(Event),nl.
Cheers,
Paulo
-----------------------------------------------------------
Paulo Jorge Lopes de Moura
Dep. of Informatics Office 4.3 Ext. 3257
University of Beira Interior Phone: +351 275319700
6201-001 Covilhã Fax: +351 275319891
Portugal
<mailto:address@hidden>
<http://www.di.ubi.pt/~pmoura> <http://www.logtalk.org>
-----------------------------------------------------------