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

Feature request: interop API #39

Open
jakkn opened this issue Sep 20, 2021 · 1 comment
Open

Feature request: interop API #39

jakkn opened this issue Sep 20, 2021 · 1 comment

Comments

@jakkn
Copy link

jakkn commented Sep 20, 2021

As a consumer of this library and writing code in languages other than Nim, I'd like to read and write files through a simple API.

Nim's bidirectional interfacing promises simple interfacing with C like targets, but an API must be defined and a library build must be shipped. The README already documents an API but the types, such as GffRoot, are complex and challenging to get right when crossing languages. A simpler API with basic data types such as cstring would make interoperability easier.

Example API:

proc readJsonFromGff*(gffFilename: cstring): cstring {.cdecl, exportc, dynlib.}
proc writeJsonToGff*(json: cstring, gffFilename: cstring) {.cdecl, exportc, dynlib.}

Example use from C#:

[DllImport("libnwn_gff.so", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr readJsonFromGff(
  [MarshalAs(UnmanagedType.LPUTF8Str)] string gffFilename
);

[DllImport("libnwn_gff.so", CallingConvention = CallingConvention.Cdecl)]
private static extern void writeJsonToGff(
  [MarshalAs(UnmanagedType.LPUTF8Str)] string json,
  [MarshalAs(UnmanagedType.LPUTF8Str)] string gffFilename
);

It seems useful to me that the API be defined and shipped with this project, but I may be missing some considerations. I also understand the maintenance implied by defining APIs, so please let me know how you feel about this. If you agree, I've already worked out the implementation and can PR the changes.

@niv
Copy link
Owner

niv commented Sep 27, 2021

Some lower-level shims sound like a good idea for me. If you need them, I'm happy to review a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants