Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C/C++ FFI? #8

Open
phillvancejr opened this issue Jan 23, 2021 · 2 comments
Open

C/C++ FFI? #8

phillvancejr opened this issue Jan 23, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@phillvancejr
Copy link

phillvancejr commented Jan 23, 2021

Hello, I've skimmed Pyxell's documentation but didn't notice anything about an ffi, can Pyxell call C or C++? I assume that it has an easy cpp ffi since it compiles to c++.

@adamsol
Copy link
Owner

adamsol commented Jan 24, 2021

There is an undocumented extern keyword for declaring functions defined elsewhere. You can write something like this:

func sinh(x: Float): Float extern

After this declaration you can just use the sinh function in your Pyxell code. It works because cmath library is included by default.

To call functions from other libraries, you would also need to include a proper header file when compiling the C++ file (and probably also link the library if it's not header-only). Currently the only way to do so is to first transpile Pyxell code to C++ (with -s option), and then manually compile the C++ code with GCC or Clang (with -include <header_file> and optionally linking the library).

It's a good idea to add the full support for FFI (without 2-step compilation) and describe it in the documentation. Thanks!

@adamsol
Copy link
Owner

adamsol commented Jan 26, 2021

Actually, this issue can remain open so that I don't forget about it.

@adamsol adamsol reopened this Jan 26, 2021
@adamsol adamsol added the enhancement New feature or request label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants