Skip to content
New issue

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

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

Already on GitHub? # to your account

Export Julia packages as JavaScript (CommonJS) modules #6

Closed
sebastiang opened this issue Feb 27, 2015 · 2 comments
Closed

Export Julia packages as JavaScript (CommonJS) modules #6

sebastiang opened this issue Feb 27, 2015 · 2 comments
Assignees
Milestone

Comments

@sebastiang
Copy link
Contributor

var package = julia.using('Package')

could load the Julia package, and scan the exported symbols from a julia package, creating them as exports, so that then you could just natively write

package.my_function("my", "JavaScript", "values")

This would enable much more native Julia integration

Since the smarts of function dispatch is done dynamically anyway, it seems like this would involve little more than scanning all the symbols exports and creating functions for each, vaguely like this.

foreach(exported_symbol in package)
  function exported_symbol(args) { return julia.exec(exported_symbol, args); }
@sebastiang sebastiang changed the title Export Julia modules as JavaScript (CommonJS) modules Export Julia packages as JavaScript (CommonJS) modules Feb 27, 2015
@waTeim
Copy link
Owner

waTeim commented Feb 28, 2015

oh! I really like this idea, though maybe julia.import might be closer semantically, what do you think?

@waTeim waTeim added this to the 1.1.0 milestone Mar 8, 2015
@waTeim waTeim self-assigned this Mar 8, 2015
@waTeim waTeim closed this as completed in cbc1dee Mar 8, 2015
@waTeim
Copy link
Owner

waTeim commented Mar 8, 2015

As described above, there is now added functionality for importing julia modules. The syntax is
julia.import(modulename); and then subsequently the exported function can be used directly. So for example, using Julia's JSON package, one can do the following (in a file called index.js)

var julia = require('node-julia');
var juliaJSON = julia.import('JSON');

// Create a JRef of a Julia Dict then export that JSON of
// the Dict, but Julia exports this as a string, so then
// use JSON.parse on the output.

var x = julia.eval('Dict("a" => "b")');
var y = juliaJSON.json(x);

console.log(JSON.parse(y));

Produces:

bizarro% node index.js 
{ a: 'b' }

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants