28 lines
594 B
Text
28 lines
594 B
Text
:- module query.
|
|
:- interface.
|
|
|
|
:- pred query(string::in, string::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
query(_, "Hello, world!").
|
|
|
|
:- pragma foreign_export("C", query(in, out), "query").
|
|
|
|
:- pragma foreign_decl("C",
|
|
"
|
|
#include <string.h>
|
|
int Query (char * Data, size_t * Length);
|
|
").
|
|
:- pragma foreign_code("C",
|
|
"
|
|
int Query (char *Data, size_t *Length) {
|
|
MR_String input, result;
|
|
MR_allocate_aligned_string_msg(input, *Length, MR_ALLOC_ID);
|
|
memmove(input, Data, *Length);
|
|
query(input, &result);
|
|
*Length = strlen(result);
|
|
memmove(Data, result, *Length);
|
|
return 1;
|
|
}
|
|
").
|