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

Is there a better way to import multiple functions? #114

Closed
Craigzyc opened this issue Jan 27, 2022 · 4 comments
Closed

Is there a better way to import multiple functions? #114

Craigzyc opened this issue Jan 27, 2022 · 4 comments
Assignees
Labels
Type: Question Needs clarification

Comments

@Craigzyc
Copy link

I have a communications library I'm basically porting to nodejs from .Net and have a number of functions inside .Net I need to expose.

I find it a bit clunky to import them all separately, is there a better way?

I was thinking of just using dynamic iputs and outputs and creating a method that allowed me to use all the functions via a switch statement but again that feels clunky and not optimal.

I have it working perfectly, but before I add another 10+ functions I just wanted to see if there was something better as I didn't see a way in the docs to import multiple methods.

I would be looking to import them like

let Coms = edge.func(......etc

Then be able to use

Coms.Open
Coms.GetAlarms
etc

@thetutlage
Copy link
Member

Not sure I understand what you mean by I find it a bit clunky to import them all separately, is there a better way?. Can you please share some code that you have written and you want to improve?

@thetutlage thetutlage self-assigned this Feb 2, 2022
@thetutlage thetutlage added the Type: Question Needs clarification label Feb 2, 2022
@Craigzyc
Copy link
Author

Craigzyc commented Feb 2, 2022

let edge = require("edge-js");

let exports = {};

let imports = [
  __dirname + "/../cs/example.dll",
  __dirname + "/../cs/example2.dll",
  __dirname + "/../cs/example3.dll"
];

exports.Open = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodName: "Open",
  references: imports,
});

exports.GetName = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodName: "GetName",
  references: imports,
});

exports.GetPoints = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodName: "GetPoints",
  references: imports,
});

exports.GetPoint = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodName: "GetPoint",
  references: imports,
});

exports.SetPoint = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodName: "SetPoint",
  references: imports,
});

module.exports = exports;

The code itself isn't bad really I dont think.
I've shortened it up. I actually import 11 dlls, and have 9 exports currently.

It works, and seemingly well. My concern is mostly that I'm loading the dlls for each export, which seems inefficient, but considering they all use the open connection under the hood well I'm guessing its optimized and only loads it once.

I couldn't see any multiple export methods in the docs, but wanted to make sure I wasn't missing something obvious as a syntax like below to export what I'm doing makes a lot of sense, or is it an abnormal use case to export a bunch of functions as none of the examples do it?

let exports = {};

exports = edge.func({
  source: __dirname + "/../cs/Example.cs",
  methodNames: ["Open", "GetName", "GetPoints", "GetPoint", "SetPoint"],
  references: imports,
});

@thetutlage
Copy link
Member

Are you sure, you are submitting the issue in the right repo? Coz, there is no API as edge.func

@Craigzyc
Copy link
Author

Craigzyc commented Feb 3, 2022

Well that's embarrassing.
The one I thought this was was edge-js, which is a derivative project of another one called edge. Must have landed here after a bad google search. Confusing naming. Sorry.

@Craigzyc Craigzyc closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Needs clarification
Projects
None yet
Development

No branches or pull requests

2 participants