# \#ffi

**URL:** https://swi-prolog.discourse.group/tag/ffi/45.md

[Latest](https://swi-prolog.discourse.group/latest.md) · [Categories](https://swi-prolog.discourse.group/categories.md) · [Tags](https://swi-prolog.discourse.group/tags.md)

---

## [PL\_get\_integer returns false even with confirmed integer term\_t](https://swi-prolog.discourse.group/t/pl-get-integer-returns-false-even-with-confirmed-integer-term-t/8738)

<div class="topic-metadata">

**Author:** [@robert314](https://swi-prolog.discourse.group/u/robert314)\
**Replies:** 10\
**Last updated:** [January 24, 2025, 1:22pm UTC](https://swi-prolog.discourse.group/t/pl-get-integer-returns-false-even-with-confirmed-integer-term-t/8738 "2025-01-24T13:22:03Z")

</div>

I’m using: SWI-Prolog version 9.3.18 for x64-win64 I want the code to: convert a prolog integer term to a C integer using PL\_get\_integer But what I’m getting is: false, even though I confirm the prolog term is indeed i…

---

## [PlDoc and foreign code](https://swi-prolog.discourse.group/t/pldoc-and-foreign-code/8577)

<div class="topic-metadata">

**Author:** [@pizzapal](https://swi-prolog.discourse.group/u/pizzapal)\
**Replies:** 2\
**Last updated:** [November 3, 2024, 5:23pm UTC](https://swi-prolog.discourse.group/t/pldoc-and-foreign-code/8577 "2024-11-03T17:23:51Z")

</div>

Can I get PlDoc to slurp up predicate documentation comments for foreign predicates (i.e., written in C or C++ and registered using some variety of PL\_register\_\*)? I have a definition this, registered using the SWI-cpp2…

---

## [How to best undo PL\_assert in embedded Prolog](https://swi-prolog.discourse.group/t/how-to-best-undo-pl-assert-in-embedded-prolog/6329)

<div class="topic-metadata">

**Author:** [@rlepigre](https://swi-prolog.discourse.group/u/rlepigre)\
**Replies:** 3\
**Last updated:** [March 2, 2023, 3:32pm UTC](https://swi-prolog.discourse.group/t/how-to-best-undo-pl-assert-in-embedded-prolog/6329 "2023-03-02T15:32:56Z")

</div>

We are trying to embed SWI-prolog in a larger program, where we would like to use it to compute a function by encoding the problem in Prolog, making a query, and extracting the result. This function may be called any num…

---

## [Escaping unbound prolog variables and FFI](https://swi-prolog.discourse.group/t/escaping-unbound-prolog-variables-and-ffi/5649)

<div class="topic-metadata">

**Author:** [@NHALX](https://swi-prolog.discourse.group/u/NHALX)\
**Replies:** 3\
**Last updated:** [August 4, 2022, 8:54am UTC](https://swi-prolog.discourse.group/t/escaping-unbound-prolog-variables-and-ffi/5649 "2022-08-04T08:54:39Z")

</div>

Is there a way to allow unbound prolog variables to escape into an FFI context and later be reintroduced? Currently this works downwards, due to the way the stack works, but it doesn’t work upward. It seems term refs can…

---

## [Prolog streams from foreign code](https://swi-prolog.discourse.group/t/prolog-streams-from-foreign-code/5453)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 6\
**Last updated:** [July 28, 2022, 12:01pm UTC](https://swi-prolog.discourse.group/t/prolog-streams-from-foreign-code/5453 "2022-07-28T12:01:31Z")

</div>

Hello friends, I’m currently investigating how to directly write to streams from rust code. The main reason for this is that at TerminusDB we realized that returning strings from rust into prolog, then having prolog pri…

---

## [Getting an UTF8 name from a text atom in foreign code](https://swi-prolog.discourse.group/t/getting-an-utf8-name-from-a-text-atom-in-foreign-code/5620)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 6\
**Last updated:** [July 18, 2022, 8:44pm UTC](https://swi-prolog.discourse.group/t/getting-an-utf8-name-from-a-text-atom-in-foreign-code/5620 "2022-07-18T20:44:52Z")

</div>

Hi friends, I’m back again with a fun ffi question. For terms, we have PL\_get\_chars and PL\_get\_nchars, which lets you pass in a desired representation for your output, one of those representations being UTF8. This mean…

---

## [Questions about foreign frames](https://swi-prolog.discourse.group/t/questions-about-foreign-frames/5034)

<div class="topic-metadata">

**Author:** [@john](https://swi-prolog.discourse.group/u/john)\
**Replies:** 0\
**Last updated:** [February 18, 2022, 10:25pm UTC](https://swi-prolog.discourse.group/t/questions-about-foreign-frames/5034 "2022-02-18T22:25:21Z")

</div>

Hi! I have been using SWI-Prolog for the backend of a Win32 GUI application in C with great success, but I am still a little unsure whether I have understood how data should be properly discarded. More precisely, my que…

---

## [Dictionaries from foreign code - questions](https://swi-prolog.discourse.group/t/dictionaries-from-foreign-code-questions/4927)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 3\
**Last updated:** [January 22, 2022, 2:35pm UTC](https://swi-prolog.discourse.group/t/dictionaries-from-foreign-code-questions/4927 "2022-01-22T14:35:25Z")

</div>

I’ve been working on implementing dictionary support into swipl-rs. I really like dictionaries in SWI-Prolog, and we use them extensively in TerminusDB. However, it looks like the foreign function interface to dictionari…

---

## [Importing a foreign predicate that was registered in a module](https://swi-prolog.discourse.group/t/importing-a-foreign-predicate-that-was-registered-in-a-module/4923)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 2\
**Last updated:** [January 20, 2022, 4:31pm UTC](https://swi-prolog.discourse.group/t/importing-a-foreign-predicate-that-was-registered-in-a-module/4923 "2022-01-20T16:31:13Z")

</div>

When defining foreign predicates, it’s possible to define them in a particular module using PL\_register\_foreign\_in\_module("some\_module\_name", "some\_predicate\_name", ...). After loading the foreign library, the predicate …

---

## [Yielding prolog engines from within a foreign predicate](https://swi-prolog.discourse.group/t/yielding-prolog-engines-from-within-a-foreign-predicate/4806)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 21\
**Last updated:** [January 2, 2022, 12:19pm UTC](https://swi-prolog.discourse.group/t/yielding-prolog-engines-from-within-a-foreign-predicate/4806 "2022-01-02T12:19:13Z")

</div>

Hello friends, I’m spending my christmas holiday trying to integrate tokio, a rust library for asynchronous code, with SWI-Prolog. Tokio allows one to write rust code where certain operations, like network communication…

---

## [Where is libswipl.a?](https://swi-prolog.discourse.group/t/where-is-libswipl-a/3897)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 26\
**Last updated:** [May 6, 2021, 6:48pm UTC](https://swi-prolog.discourse.group/t/where-is-libswipl-a/3897 "2021-05-06T18:48:08Z")

</div>

This documentation page says there should be a file at swipl/runtime/libswipl.a. When I build from source though, there doesn’t seem to be a directory called runtime and libswipl.a is nowhere to be found. This is strang…

---

## [Announcing swipl-rs - a high-level interface to SWI-Prolog for rust](https://swi-prolog.discourse.group/t/announcing-swipl-rs-a-high-level-interface-to-swi-prolog-for-rust/3921)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 0\
**Last updated:** [May 6, 2021, 2:44pm UTC](https://swi-prolog.discourse.group/t/announcing-swipl-rs-a-high-level-interface-to-swi-prolog-for-rust/3921 "2021-05-06T14:44:41Z")

</div>

Hello friends, I’ve just published swipl-rs version 0.3.0. swipl-rs is a rust library that allows you to easily write foreign libraries for SWI-Prolog in rust, or write binaries that embed SWI-Prolog in a larger rust pr…

---

## [BLOB name clashes](https://swi-prolog.discourse.group/t/blob-name-clashes/3903)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 0\
**Last updated:** [May 3, 2021, 2:34pm UTC](https://swi-prolog.discourse.group/t/blob-name-clashes/3903 "2021-05-03T14:34:31Z")

</div>

I’m experimenting with blobs in the foreign interface, and couldn’t help but notice that it is entirely possible to have two separate blobs that use the same name. It seems that the only consequence of this is that curre…

---

## [How do I put an argument in foreign code?](https://swi-prolog.discourse.group/t/how-do-i-put-an-argument-in-foreign-code/3546)

<div class="topic-metadata">

**Author:** [@maren](https://swi-prolog.discourse.group/u/maren)\
**Replies:** 2\
**Last updated:** [February 1, 2021, 10:48am UTC](https://swi-prolog.discourse.group/t/how-do-i-put-an-argument-in-foreign-code/3546 "2021-02-01T10:48:24Z")

</div>

Hello friends, While implementing the rust wrapper around SWI-Prolog’s foreign language interface, I noticed that while there’s a PL\_get\_arg() and a PL\_unify\_arg(), there is no PL\_put\_arg(). I thought I could just impl…

---

## [Arguments to PL\_predicate](https://swi-prolog.discourse.group/t/arguments-to-pl-predicate/1834)

<div class="topic-metadata">

**Author:** [@anniepoo](https://swi-prolog.discourse.group/u/anniepoo)\
**Replies:** 2\
**Last updated:** [February 4, 2020, 3:55pm UTC](https://swi-prolog.discourse.group/t/arguments-to-pl-predicate/1834 "2020-02-04T15:55:12Z")

</div>

This example is from Initiating a query from C char \* ancestor(const char \*me) { term\_t a0 = PL\_new\_term\_refs(2); static predicate\_t p; if ( !p ) p = PL\_predicate("is\_a", 2, "database"); PL\_put\_atom\_chars(a0…
