Accessing external JS code from WASM

14 views
Skip to first unread message

f_l...@yahoo.it

unread,
Dec 21, 2022, 12:25:31 PM12/21/22
to emscripten-discuss
Hi everybody,
I'd like to know if anybody found a way to access, from Wasm/C++ code,
some EXTERNAL Javascript code, i.e., code NOT contained in the C++ code as inline Javascript, like EM_JS(...).
I'm trying to do so also through the --js-library switch, but I cannot access my external JS function:

ColorFever.js:1387 Uncaught ReferenceError: JsLibCheatPanel is not defined
    at JsCheatPanel (ColorFever.js:1387:27)
    at imports.<computed> (ColorFever.js:8813:35)
    at SdkUtils::CheatPanel() (ColorFever.wasm:0x9d992)
    at SDKCheatPanel() (ColorFever.wasm:0x442d3)
    at GameUtils::MenuFunc(unsigned char) (ColorFever.wasm:0x1e012)
    at GAMMainLoop() (ColorFever.wasm:0x38fb1)
    at MainLoop() (ColorFever.wasm:0x67c5c)
    at dynCall_v (ColorFever.wasm:0x3d2255)
    at ret.<computed> (ColorFever.js:8847:35)
    at ColorFever.js:1174:22

any help is welcome!!

Thanks,
f_lande

Sam Clegg

unread,
Dec 21, 2022, 3:02:02 PM12/21/22
to emscripte...@googlegroups.com
Is JsCheatPanel the name of the `--js-library` function?  And is JsLibCheatPanel the name of the external JS function?

Have you loaded `JsLibCheatPanel` in the global scope somehow?   If you are using devtools can you see if `JsLibCheatPanel` exists?  If not, you need to arrange for that library to be loaded somehow into your global scope.  You can do this using any of the normal html / js methods of loading code.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/8cf3caa4-69ba-4e95-9289-8853d767e513n%40googlegroups.com.

Shlomi Fish

unread,
Dec 22, 2022, 12:34:14 AM12/22/22
to 'f_l...@yahoo.it' via emscripten-discuss
Hi f-lande!

On Wed, 21 Dec 2022 09:24:46 -0800 (PST)
"'f_l...@yahoo.it' via emscripten-discuss"
<emscripte...@googlegroups.com> wrote:

Please read the whole of these and follow their advice:

* https://github.com/shlomif/how-to-share-code-online

* https://github.com/shlomif/writing-the-perfect-question

> Thanks,
> f_lande
>



--

Shlomi Fish https://www.shlomifish.org/
Optimising Code for Speed - https://shlom.in/optimise

Not only is Rindolf an evil Reindeer, but he is also the notorious insane
tyrant and mass-murderer, Rindolf “Aim Very High” Hitlower.
https://www.shlomifish.org/me/rindolf/

Please reply to list if it's a mailing list post - https://shlom.in/reply .

Francesco Lande

unread,
Dec 22, 2022, 2:56:49 AM12/22/22
to emscripte...@googlegroups.com
Hi eveybody,
thanks for your reply.
Eventually, I found out that I had to prepend the function name with the namespace it was declared within,
something like "<namespace>.<function>", in my case "WebApp.JsLibCheatPanel", simple but tricky.

Best regards,

Francesco Lande


--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/GiaUaTfe9UA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages