Yuce's Blog

Cognitive dissonance is yoga for the brain.*

Ctypes Strings

2007-05-28

I've written bulk of PySWIP last summer, it is based on Nathan Denny's proolog.py. This is the first project that I used ctypes, a fantastic package which allows calling C functions from dynamic libraries that I use to link libpl.so (Linux) or libpl.dll (Windows) of SWI-Prolog. One of the dif­fi­cul­ties I had back then was finding the cor­re­spond­ing ctypes code for PL_get_chars which is defined at SWI-Prolog.h as follows:

PL_EXPORT(int) PL_get_chars(term_t t,
    char **s, unsigned int flags);

I use that function in queryGenerator:

answer = (c_char_p*maxsubresult)()
while PL_get_list(swipl_list, swipl_head, swipl_list):
    PL_get_chars(swipl_head, answer,
        CVT_ALL 
continue.

python, ctypes, prolog, pyswip