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

Native modules #1861

Open
mbekkomo opened this issue Jan 14, 2025 · 1 comment
Open

Native modules #1861

mbekkomo opened this issue Jan 14, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mbekkomo
Copy link

mbekkomo commented Jan 14, 2025

Is your feature request related to a problem? Please describe.

FFI is one of a way to access native functions, but it's limitations are limited access to the VM and stacks, and you can't create a native Arturo type.

Describe the solution you'd like

The solution to that is to implement a native modularisation. I have something like this in my mind.

// arturo_lib.c
#include <arturo.h> // Exported Arturo C APIs

int lib_Foo(arturo_VM* vm) {
  const char *_ =  arturo_popArgString(vm);

  arturo_pushString(vm, "foo");

  return 1; // required args
}

const *arturo_RegFunc funcs = {
  {"foo", foo},
  {NULL, NULL},
};

void arturo_nativeOpen(arturo_VM* vm) {
  arturo_registerFuncs(funcs);
}

Run cc arturo_lib.c -fPIC -shared -larturo -o lib.so

;; `import` accepts `native` attribute to import native modules
;; `import.native` will search `lib.dll` in Windows, `lib.so` in Linux, and `lib.dylib` in MacOS on specified search paths
lib: import.native "lib"

print (lib\foo "foo")

Describe alternatives you've considered

Additional context

You can take a look at Lua C API for reference.

@mbekkomo mbekkomo added the enhancement New feature or request label Jan 14, 2025
Copy link

Thank you for submitting an issue! :)

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