www.digitalmars.com         C & C++   DMDScript  

DMDScript - How to call JS function from C++?

reply ajax.zheng synactive.net writes:
Hi I'm new to DMDScript. I've figured out a way to call C++ function from JS but
not call JS function from C++ code. Can anybody give me a hint? Thanks!

Also I've found that if I "register" a C++ function for example like "Print()"
and then define a same name function Print() in JS and assigned to a member like
"Application.Print = Print()", the C++ function will still get called instead of
the JS function. My question is is there a way that DMDScript engine can support
that the function in C++ can be overrided by JS function if user would like to
provide their own implementation.

Hope my questions here are clear. Thanks for your help in advance.

Ajax
Jul 18 2005
parent reply ajax.zheng synactive.net writes:
Never mind, I've figured out these 2 questions by meself.

In article <dbhags$oe3$1 digitaldaemon.com>, ajax.zheng synactive.net says...
Hi I'm new to DMDScript. I've figured out a way to call C++ function from JS but
not call JS function from C++ code. Can anybody give me a hint? Thanks!

Also I've found that if I "register" a C++ function for example like "Print()"
and then define a same name function Print() in JS and assigned to a member like
"Application.Print = Print()", the C++ function will still get called instead of
the JS function. My question is is there a way that DMDScript engine can support
that the function in C++ can be overrided by JS function if user would like to
provide their own implementation.

Hope my questions here are clear. Thanks for your help in advance.

Ajax
Jul 18 2005
parent reply jicman <jicman_member pathlink.com> writes:
Would you like to post your findings here?  some of us would like to know. :-)

thanks.

josé

ajax.zheng synactive.net says...
Never mind, I've figured out these 2 questions by meself.

In article <dbhags$oe3$1 digitaldaemon.com>, ajax.zheng synactive.net says...
Hi I'm new to DMDScript. I've figured out a way to call C++ function from JS but
not call JS function from C++ code. Can anybody give me a hint? Thanks!

Also I've found that if I "register" a C++ function for example like "Print()"
and then define a same name function Print() in JS and assigned to a member like
"Application.Print = Print()", the C++ function will still get called instead of
the JS function. My question is is there a way that DMDScript engine can support
that the function in C++ can be overrided by JS function if user would like to
provide their own implementation.

Hope my questions here are clear. Thanks for your help in advance.

Ajax
Jul 20 2005
parent adzheng <adzheng_member pathlink.com> writes:
Sorry to reply late...I've been busy for a while. The implementation is fairly
simple:

void CallJSFunction(
LPCTSTR pszFuncName, unsigned argc/*=0*/, Value *arglist/*=NULL*/)
{
if (pszFuncName && *pszFuncName)
{
d_string s = Lstring::ctor((dchar *) pszFuncName);
Value *pVal = m_pJavaScript->callcontext->global->Get(s);

if (pVal && (pVal->getType() == TypeObject))
{
Dobject *pObject = pVal->toObject();
Value ret;
Value::copy(&ret, &vundefined);

pObject->Call(
m_pJavaScript->callcontext,
m_pJavaScript->callcontext->global,
&ret,
argc, arglist
);
}
}
}


In article <dblm0e$626$1 digitaldaemon.com>, jicman says...
Would you like to post your findings here?  some of us would like to know. :-)

thanks.

josé

ajax.zheng synactive.net says...
Never mind, I've figured out these 2 questions by meself.

In article <dbhags$oe3$1 digitaldaemon.com>, ajax.zheng synactive.net says...
Hi I'm new to DMDScript. I've figured out a way to call C++ function from JS but
not call JS function from C++ code. Can anybody give me a hint? Thanks!

Also I've found that if I "register" a C++ function for example like "Print()"
and then define a same name function Print() in JS and assigned to a member like
"Application.Print = Print()", the C++ function will still get called instead of
the JS function. My question is is there a way that DMDScript engine can support
that the function in C++ can be overrided by JS function if user would like to
provide their own implementation.

Hope my questions here are clear. Thanks for your help in advance.

Ajax
Nov 04 2005