-
Notifications
You must be signed in to change notification settings - Fork 1
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
Importing javascript functions through third party libraries #3
Comments
JavaScript files can be loaded into the context using eval with something like You might want to embed the JS file into your executable with file-embed instead of using readFile (file-embed uses template haskell so it does not work yet on GHC cross compiling to iOS and Android yet). |
Thank you! |
You can create a single function with eval and then use call to call it like this: f <- eval "function(x) {console.log(x)}"
call f (toJSVal "Helllo") For a JavaScript library that defines functions in the JavaScript global scope use something like: eval "var test = function(x) {console.log(x)}"
jsg1 "test" (toJSVal "Helllo") -- Like JavaScript test("Hello"); Note: in If the library defines the functions inside some other object you might need to do something like: eval "var test = { f: function(x) {console.log(x)} }"
jsg "test" ^. js1 "f" (toJSVal "Helllo") -- Like JavaScript test.f("Hello"); Without the number |
I wrote a small test along the lines you suggested, but am getting
When compiled with
|
Sorry, I forgot that To debug this I used the |
Very helpful pointers, thank you! Now, I am able to fix the error, as well as run the debugger using |
@hamishmack I'm currently trying to implement
Here is a rough idea of what I have so far:
What are the best practices for creating a Lastly, what is the best way to |
It will be helpful to show how to load the third-party libraries that are referenced in JS FFI. It can be just a simple js library/script defining, say an add function. The example can then show how to load that JS library (basically, how to link to the library referenced in FFI) and use the function referenced there.
I know how to do it through ghcjs (easy to script tag in index.html that ghcjs generates), but not how to do this through ghc. Will also appreciate pointers in comments because this will be very helpful in immediately moving forward with jsaddle, and third party JS libraries - I plan to use jsaddle, wkwebview and ghc along the lines of the hello example demonstrated here, but with third-party JS libraries also included.
The text was updated successfully, but these errors were encountered: