Subject: Creating a DLL, parameter problem

From: Joerg Herrmann <[email-masked]>
Date: Thu, 09 Nov 2000 14:04:51 +0100

Hello,

I want to create a DLL from a SWI-Prolog source file hello.pl
As far as I understand your manual, the only way is to write a
C-Wrapper that calls the intended prolog predicates.
Below you will find such a wrapper.
I assume, one has to call plld -share -o <dll-output> pl.c hello.pl
for creating the dll or a share object under Linux.

If so, I like to know, how to adjust pl.c attached so that hello/2
accepts a second argument.
So far hello/2 gets only the first command line parameter in the case:

        plld -o test hello.pl pl.c
        ...
        test abc def

Thanks for your help!

Jörg Herrmann

     #include <stdio.h>
     #include <SWI-Prolog.h>

     #define TOPLEVEL_PREDICATE "hello"
     #define TOPLEVEL_PREDICATE_ARITY 2

     int
     main(int argc, char **argv)
     { 
       /* initialise Prolog */

       if ( !PL_initialise(
               TOPLEVEL_PREDICATE_ARITY,
               argv
               ) )
         PL_halt(1);

       /* Lookup TOPLEVEL_PREDICATE/TOPLEVEL_PREDICATE_ARITY: make the
arguments and call */

       {
         term_t pl_args = PL_new_term_refs(TOPLEVEL_PREDICATE_ARITY);
         PL_put_atom_chars(
           pl_args,
           argv[1]
           );
         PL_halt(
           PL_call_predicate(
             NULL, PL_Q_NORMAL,
             PL_predicate(
               TOPLEVEL_PREDICATE,
               TOPLEVEL_PREDICATE_ARITY,
               "user"
               ),
             pl_args
             ) ? 0 : 1);
       }

       return 0;
     }