How to call "main" myself?

278 views
Skip to first unread message

Danilo Guanabara

unread,
Apr 22, 2015, 11:13:13 AM4/22/15
to emscripte...@googlegroups.com
Is there any way to run the code exactly when I want it to run and not just when the runtime was loaded?

Aidan Hobson Sayers

unread,
Apr 22, 2015, 1:49:41 PM4/22/15
to emscripte...@googlegroups.com
What do you mean by 'when the runtime was loaded'?

I use --pre-js and --post-js to have fine-grained control over running order.

You could modify this by putting the stuff in post-js inside a function itself which you could insert into window as 'initemtcl' or something similar.
Honestly, I'm not sure if those two links are the best way to do this kind of thing any more. I created this structure of pre/post-js about a year and a half ago and I've just copied and pasted since then. For example, I don't know if emscripten still pollutes `window.Module`.

Hopefully it gives you a starting point - basically just wrap everything in a function and run that when you want to kick off.

Aidan

On 22 April 2015 at 16:13, Danilo Guanabara <dang...@gmail.com> wrote:
Is there any way to run the code exactly when I want it to run and not just when the runtime was loaded?

--
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.
For more options, visit https://groups.google.com/d/optout.

Alon Zakai

unread,
Apr 22, 2015, 2:08:26 PM4/22/15
to emscripte...@googlegroups.com
Another option is to build with  -s INVOKE_RUN=0  so that we don't run the project automatically. Then just call  _main()  yourself (if you want to pass arguments, can use ccall).

- Alon


On Wed, Apr 22, 2015 at 8:13 AM, Danilo Guanabara <dang...@gmail.com> wrote:
Is there any way to run the code exactly when I want it to run and not just when the runtime was loaded?

--

Danilo Guanabara Fernandes

unread,
Apr 22, 2015, 3:13:28 PM4/22/15
to emscripte...@googlegroups.com
I read somewhere that the main function is executed in the exact moment that the runtime is loaded and ready. But anyway...

The only thing that I need is to start Emscripten's execution, for example, when some UI event occurs.
I am not sure if your solution will accomplish that, it seems that it only affects the execution order.

--
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/9Ej-JPYjRSw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

Danilo Guanabara Fernandes

unread,
Apr 22, 2015, 3:14:10 PM4/22/15
to emscripte...@googlegroups.com
Thanks, Alon! That's what I was looking for.

Aidan Hobson Sayers

unread,
Apr 22, 2015, 4:39:53 PM4/22/15
to emscripte...@googlegroups.com
As a general point, if you wrap some JS code in a function, *nothing* will be executed until you execute the function. Having pre and post js look like "function abc() {" and "}" accomplishes this.

Alon Zakai

unread,
Apr 22, 2015, 7:51:27 PM4/22/15
to emscripte...@googlegroups.com
Yeah, that's a more guaranteed simple way to do this. But it does mean that asynchronously loading the memory init file etc. will only happen when you actually call it. If that delay is not a concern, though, then definitely this is the easiest way.

- Alon

Reply all
Reply to author
Forward
0 new messages