-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Calling Haskell from JavaScript #182
Comments
You can use it like an ordinary JavaScript function, e.g.
I should probably write this down somewhere in the documentation. |
I think you misinterpreted my question --- I should probably have been clearer. This is what I meant to ask:
|
Perhaps confusingly, the The
to make a new identifier |
Thank you!
It might also be a good idea to record the method you gave for 'exporting' a Haskell function in the documentation. P.S.: In case you want to know what I needed this for, I'm using it to create a menu using Electron (see #111 and https://github.com/HeinrichApfelmus/threepenny-gui/blob/master/doc/electron.md). My code: -- Main.hs
module Main where
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
...
setup :: Window -> UI ()
setup window = do
fname <- UI.input
saveBtn <- UI.button # set text "Save file"
box <- UI.textarea # set UI.id_ "text"
...
let fun = void $ runUI window $ element box # set text "Hello from Haskell!"
handler <- ffiExport fun
runFunction $ ffi "window.sayHello = %1" handler
... // electron.js
...
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: false },
});
...
app.on('ready', () => {
...
setMainMenu()
});
...
// based on http://stackoverflow.com/a/37798089
function setMainMenu() {
const template = [
{
label: 'Hello',
submenu: [
{
...
label: 'Hello from Haskell',
accelerator: 'CmdOrCtrl+H',
click() {
win.webContents.executeJavaScript('window.sayHello()')
}
}]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
}); |
When using
exportHandler
to export a Haskell function to JavaScript, how do you call the exported function from the JavaScript side?The text was updated successfully, but these errors were encountered: