Thread overview
How to call JS function from C++?
Jul 18, 2005
ajax.zheng
Jul 19, 2005
ajax.zheng
Jul 20, 2005
jicman
Nov 04, 2005
adzheng
July 18, 2005
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


July 19, 2005
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
>
>


July 20, 2005
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
>>
>>
>
>


November 04, 2005
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
>>>
>>>
>>
>>
>
>