Subj : Re: Asynchronous script execution To : netscape.public.mozilla.jseng From : "Michael Putters" Date : Fri Nov 21 2003 02:49 pm "Brendan Eich" wrote in message news:3FBD87E5.6010104@meer.net... > >Basically, my (C) application starts. At some point, everything is loaded, > >and I can execute the script (JS_ExecuteScript). If that happens, the script > >does its stuff, then exits. > > > > How does it exit? It just doesn't call any function > > What I'd like is that the script remains in > >memory, > > > > Do you mean continue running, perhaps "in the background"? The JSScript > remains in memory already, although you need to protect it with > JS_NewScriptObject and a GC root. So that can't be the issue. Yup > > and that I can just call events. For example, assuming such > >functions would exist : > > > >void startscript( void ) > >{ > > handle = JS_ExecuteScriptAsync( context, somescript ); > > JS_CallFunction( context, global, "onStart", .. ); > >} > > > >void js_exit( void ) /* some function that can be called from the script > >{ > > JS_StopScript( handle ); > >} > > > >Hope this explains a bit better. > > > You have to use threads. The API and engine support threads (define > JS_THREADSAFE, read the docs, especially about JS_BeginRequest and > friends). It's up to you to figure out how to synchronize between the > thread calling startscript and the event handlers, and the thread that > actually executes the script. Be careful that you don't impose > multi-threaded programming on the people who write scripts for your > embedding. Guess I'll do that then ;p > > Basically, I'm wonder how a web browser can > >call onLoad once the script is running.. (since the execution is blocked at > >the JS_ExecuteScript call) > > > > Browser embedding execution is run-to-completion, apparently > single-threaded, precisely so web JS authors don't have to be MT > programmers. There may be threads under the hood, but they're hidden > from scripters. > > /be > Thanks .