I'm seeking some clarification/explanation/help with calling into the
JavaScript engine from 'C'. First of all - generally I;ve had no problems
with the engine and found it very easy to integrate - however I'm having
some problems getting the variables created where I expect them when I
recursively call the engine. Example:

1.    I register a JavaScript function with a native implementation - say
'MyFunction'
2.    'C' calls JavaScript engine to run a script.
3.    The script calls 'MyFunction'
4.    My Function somehow gets another JavaScript fragment (maybe from a
file, or from a string in a similar way to eval)
5.    'MyFunction' wants to call back (recursively) into the engine to
execute this fragment.

There are a number of options I'd like to have when I execute this script:
Option 1. Executes 'like a JavaScript' function
To do this I'd like to create a call object and have that used as the target
for 'var' declarations, rather than the global object. I can't work out how
to do this. Internally the engine only seems to do this if the 'js_Execute'
function is called with a 'down' object - which is the stack frame of the
caller. I can't see a way of doing this from the public interface.

Option 2. Execute the script fragment 'as though it were a statement in the
current parent script'.
In this case the call object is that of the parent - if its in a function -
or the global object otherwise. The creation point for 'var' declarations is
that of the parent calling script. Can't see how to do this - the 'eval'
implementation does this internally I think by getting the appropriate
objects then passing them to 'js_Execute'. Possible option is the debug
interface 'JS_EvaluateInStackFrame' function - but actually this is not a
debug operation - rather something I would like the option of doing from my
application.

Option 3. Exeucte in the global context - even if the parent was nested 'n'
levels deep in function calls. This seems to be the only option I can
legitimately do from the existing API.

I'm happy to explain what I'm trying to do and why - but that would make
this message even longer!

Comments greatly appreciated!
thanks in advance
Peter Wilson




Reply via email to