I’m trying to run a small Elm script through Bellard’s Quickjs on Linux but the following error is produced during initialization:
debian@love >./qjstest
TypeError: not a function
It is unclear which function this refers to. I’ve managed to trace the issue back to the “_Platform_worker” function which executes and returns correctly. The error happens some time after that but I’m not sure where.
The callsite looks like this:
#include "quickjspp.hpp" // wrapper for quickjs
// ... some time later:
context.eval("function setTimeout(a,b) { a(); return 42; } "
"function clearTimeout(a) { } "
"var app = Elm.Main.init(); "
"app.ports.debugPr.subscript(jsDebug); ");
The “setTimeout” function is a stub for now, I don’t think that should cause a problem here. The “jsDebug” function is provided by this and is working correctly:
context.global().add(“jsDebug”, (const std::string& str) { std::cout << str << std::endl; });
The “debugPr” function is a port and the “jsDebug” function is supposed to execute and print to the console.
Finally the Elm code is trivial:
port module Main exposing (main)
import Platform exposing (Program)
port debugPr : String -> Cmd msg
main : Program () () ()
main =
Platform.worker
{ init = \() -> ( (), debugPr "Elm started" )
, update = \() -> \() -> ( (), Cmd.none )
, subscriptions = \() -> Sub.none
}
I was also looking into trying mujs as an alternative so far there appears to be the same problem and the code is similar. I can provide that code later if it can help identifying the issue.
Hope someone can help pointing me into the direction of how to deal with this!
Thank you in advance.