How to pass array of strings between javascript and C/C++ code with webassembly/emscripten?

780 views
Skip to first unread message

Mahesh Velankar

unread,
Dec 12, 2021, 7:50:53 PM12/12/21
to emscripten-discuss

I am trying to write a web application that will do sort of word processing (say spell check, grammar check, word analysis) using back-end C/C++ code. (I have got c/C++ code working in another desktop app... I want to bring it to web). I want an example minimal code doing this (pass array of strings from JavaScript to c/c++ code...c/c++ code will do the word operations... I have this code ......and the resulting array of strings will be sent back to JavaScript where they will be processed further. (passing arrays to and from is important) Please point me to any such code/tutorial, from where I can make a start.

I searched GitHub. I found several projects using emscripten but could not get this anywhere. (Only place I could get some clue was Hunspell built with emscripten ... however I could not build it successfully)

Please let me know . Thanks in advance.

Shlomi Fish

unread,
Dec 13, 2021, 12:38:50 AM12/13/21
to Mahesh Velankar, emscripte...@googlegroups.com
Hi Mahesh!

On Sun, 12 Dec 2021 16:50:53 -0800 (PST)
Mahesh Velankar <mvel...@gmail.com> wrote:

>
>
> I am trying to write a web application that will do sort of word processing
> (say spell check, grammar check, word analysis) using back-end C/C++ code.
> (I have got c/C++ code working in another desktop app... I want to bring it
> to web). I want an example minimal code doing this (*pass array of strings*
> from JavaScript to c/c++ code...c/c++ code will do the word operations... I
> have this code ......and *the resulting array of strings* will be sent back
> to JavaScript where they will be processed further. (passing *arrays* to
> and from is important) Please point me to any such code/tutorial, from
> where I can make a start.
>
> I searched GitHub. I found several projects using emscripten but could not
> get this anywhere. (Only place I could get some clue was Hunspell built
> with emscripten ... however I could not build it successfully)
>
> Please let me know . Thanks in advance.
>

I've done this (using 'char * *') here:

https://github.com/shlomif/fc-solve/blob/a2137b8882dbdd91444e2acda5b467aed2a9ebab/fc-solve/site/wml/src/ts/web-fc-solve.ts#L664

Regards,

-- Shlomi

--

Shlomi Fish https://www.shlomifish.org/
https://is.gd/htwEXQ - Integrating GNU Guile into GNU coreutils

Chuck Norris is his own boss. If you hire him, he’ll tell your boss what to
do. — https://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

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

Mahesh Velankar

unread,
Dec 13, 2021, 6:03:09 AM12/13/21
to emscripten-discuss
Shlomi
Thanks for your efforts for a quick response.
I will have to go thru your code to understand the typescript code. .. I will start doing that.
However I would have preferred a simple c++ - JavaScript example doing that.
Still let me start looking into your project. and Let me understand the passing of this char * * to and from between c++ and JavaScript
Thanks again
-Mahesh

Shlomi Fish

unread,
Dec 13, 2021, 8:29:16 AM12/13/21
to Mahesh Velankar, emscripte...@googlegroups.com
Hi Mahesh!

On Mon, 13 Dec 2021 03:03:09 -0800 (PST)
Mahesh Velankar <mvel...@gmail.com> wrote:

> Shlomi
> Thanks for your efforts for a quick response.
> I will have to go thru your code to understand the typescript code. .. I
> will start doing that.
> However I would have preferred a simple c++ - JavaScript example doing that.
> Still let me start looking into your project. and Let me understand the
> passing of this char * * to and from between c++ and JavaScript
> Thanks again

note the "#L664" anchor to line 664 in the URL.
https://youtu.be/GoEn1YfYTBM - Tiffany Alvord - “Fall Together”

I promised, I forgot, I did not keep my promise — just shoot me, and get on
with it!
https://www.shlomifish.org/humour.html

Shlomi Fish

unread,
Dec 24, 2021, 9:12:44 AM12/24/21
to Mahesh Velankar, emscripte...@googlegroups.com
Hi Mahesh!

In case it helps you and to help future questions, I set up:

https://github.com/shlomif/emcc-array-of-pointers-example


On Mon, 13 Dec 2021 03:03:09 -0800 (PST)
Perl Elems to Avoid - https://perl-begin.org/tutorials/bad-elements/

Always reach for the stars! Because even if you miss… You’ll be miles away
from me with your motivational bullshit.
https://is.gd/PuH02m

Mahesh Velankar

unread,
Dec 25, 2021, 6:25:59 AM12/25/21
to emscripten-discuss

Looks  very useful for newbies like me.
Will take a deeper look at this later next week.
Thanks a lot.
Reply all
Reply to author
Forward
0 new messages