locked
Can you please tell me, can i use JavaScript in C++ with WinRT instead of scripting language ? for games purposes.

    Question

  • Can i use JavaScript not particularly with HTML/CSS, but only with C++ for example, like a Scripting Language ?

    For example i want to write C++/CX library and after i want use JavaScript inside that library, which is also uses this C++/CX library.

    Analogues:

    C++ + LUA bindings etc...

    Because my vision of why WinRT needs C++, C# and also JavaScript:

    - C++/CX for native optimized engine code, using JS scripts

    - C# for game engine editor, using JS scripts and C++/CX engine code

    - JavaScript for scripting language, using C++/CX engine code and C# editor code

    Can i accomplish this with WinRT thanx to cross-language features ?

    That would be really awsome.

    • Edited by NewbTom Tuesday, May 29, 2012 11:12 AM
    Tuesday, May 29, 2012 11:05 AM

Answers

  • Correct. You cannot use JavaScript in a C++ app. You can create a Windows Runtime Component in C++ or C# to use in a JavaScript app.

    --Rob

    • Marked as answer by NewbTom Friday, June 01, 2012 6:34 PM
    Thursday, May 31, 2012 2:28 AM
    Owner

All replies

  •  

    Hello,

     

    There is a document to talk about the Windows Runtime Components, and interaction between them.

     

    Creating Windows Runtime Components

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh441572(v=vs.110).aspx

     

    By using the Windows Runtime, you can create components (essentially DLLs) in C++, C#, or Visual Basic, and call into them in a simple and natural way from a Windows Metro style app that's built by using JavaScript. Although you can use JavaScript to access the Windows Runtime APIs, JavaScript cannot easily access native C++ libraries or .NET Framework class library functionality.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 30, 2012 7:20 AM
  • wrong understanding of question.

    wrong answer.

    Let's break the question on small parts:

    1st part) Can i compile Script.js source code file and execute some functions, from my C++/CX code ?

    smth like:

    compiledScript = CompileJavaScript("Script.js");

    someFunction = compiledScript.GetFunction("SomeFunction");

    someFunction();

    or:

    CompileJavaScriptToDLL("Script.js", "Script.DLL");

    compiledScript = LoadScriptDLL("Script.DLL");

    someFunction = compiledScript.GetFunction("SomeFunction");

    someFunction();



    • Edited by NewbTom Wednesday, May 30, 2012 9:32 AM
    Wednesday, May 30, 2012 9:15 AM
  • Hi NewbTom,

    There is no JavaScript compiler or interpreter provided for use within your C++ code. The JavaScript engine is available only as part of the host for HTML/JS apps or within the WebView control.

    --Rob

    Wednesday, May 30, 2012 6:20 PM
    Owner
  • :````(

    So i can't call JavaScript COM functions via C++/CX ??? Anyhow ?

    Or i can't create COM functions in JavaScript at all ?

    [quote]

    The JavaScript engine is available only as part of the host for HTML/JS apps or within the WebView control

    [/quote]

    does this mean that i can't create JavaScript DLLs ?


    • Edited by NewbTom Wednesday, May 30, 2012 10:36 PM
    Wednesday, May 30, 2012 10:28 PM
  • Correct. You cannot use JavaScript in a C++ app. You can create a Windows Runtime Component in C++ or C# to use in a JavaScript app.

    --Rob

    • Marked as answer by NewbTom Friday, June 01, 2012 6:34 PM
    Thursday, May 31, 2012 2:28 AM
    Owner
  • Well, i'm rly disappointed :`(

    JavaScript would perfectly fit scripting needs.

    C# too huge and complicated for scripting language.

    And when will you finally make Compiler-As-A-Service ?

    How long else to wait Compile("Soluton.sln") at runtime ?

    Ok, let's considers this scenario:

    I will use C++/CX and C# for writing game engine staff,

    and use JavaScript for high level staff + scripts.

    I hope this is not forbidden ?

    I.e. C++/CX + C# for low level code, and only JavaScript for high level launch code or smth like that.

    Also would be nice to have customizable Scripting language, where i could add new keywords, new functionality and Intellisence also must support this additional functionality, etc... Need smth advanced Scripting develope in VisualStudio, where i could create my own scripting language, which support new COM style managed functions and types. Whats up with Roslyn ? i hope it will allow us to create scripting languages, not only parse existing languages.


    • Edited by NewbTom Friday, June 01, 2012 12:55 AM
    Thursday, May 31, 2012 11:42 PM
  • Hi Rob,

    Is there any chance we can use JavaScript WinRT component from C++/C# in final release (or future version) of Visual Studio?

    Is there any workaround to do this indirectly? Any help will be appreciated.

    -Nitin

    Wednesday, June 06, 2012 7:18 AM