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

Possbile plugin system? #480

Open
Iskander0 opened this issue Oct 5, 2022 · 1 comment
Open

Possbile plugin system? #480

Iskander0 opened this issue Oct 5, 2022 · 1 comment

Comments

@Iskander0
Copy link

Iskander0 commented Oct 5, 2022

I extended ABS for myself to be able to call functions from go plugins. Perhaps something like this can be considered for main.

Simplest plugin example :

package main

func Add(argc int32, argv []interface{}) interface{} {
    x := argv[0].(float64)
    y := argv[1].(float64)
   return x + y // Returned values automatically converted to ABS data types
}

Compiled with go build -buildmode=plugin, can be called from an ABS script like this:

# arg1 : path to compiled plugin ; arg2 : Plugin gets a name which is used in execShared
importShared("plugin.so", "plugin") /

# arg1: Name from arg2 of importShared ; arg2 : Name of exported functions from the go plugin ; arg3 : Array which gets passed to the go function called, basic types automatically converted.
execShared("plugin", "Add", [1, 2]) // returns 3

The implementation is kind of bad, as it would be nice to be able to get a library "object" instead of having to "name" all loaded plugins, but I like the simplicity of not having to worry about ABS-specific or go-specific types (as is the case with something like luajit ffi, or python C extensions). I can share some code if anyone is interested.

@odino
Copy link
Collaborator

odino commented Nov 29, 2022

hey @Agathon1 -- apologies, missed this one! 😊

I would be +1 on the ability to load external plugins. One thing to consider, the public interface could probably be looking a little different eg. we could make this work with x = require('plugin.so') and then be able to call x.something. I don't have a strong sense on what we need to do to get this working, but I'd be happy to engage with you if you wished to send a PR / proposal.

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