how do I write code in javascript to use a function in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • urib
    New Member
    • Nov 2009
    • 14

    how do I write code in javascript to use a function in C

    Suppose that I have some simple function in C like the following when I want to use it in javascript code

    Code:
    int plus1(int a)
    {
    	return a+1;
    }
    I am using visual C++2008 for my C code.

    I guess that I need to start by
    file->new project->class library and call it with some name
    let call it classtest

    Now the visual C++ give me some files

    I guess that I need to add some code to the file classtest.h and to file
    classtest.cpp but I am not 100% sure what I need to add and I am not 100% sure what I need to add in javascript to use the function.

    If you tell me what to do in this specific case then hopefully it is going to help me to use more complex functions that I have in C in javascript.

    Note that I know how to do it only with javascript
    and I simply do the following steps:

    1)type the following code in a new asp file

    Code:
    <SCRIPT LANGUAGE="JavaScript" RUNAT=SERVER>
    function plus1(a)
    {
      return a+1;
    }
    Response.Write(plus1(5));
    </SCRIPT>
    2)save it in as javaexample.asp

    3)goto
    http://****/***/javaexample.asp

    4)see 6 in the screen

    I replaced some letters by **** but
    **** is specific to the server that I am using that is only connected to the computer that I use even when I am not connected to the interenet so it is not important.
    Last edited by Dormilich; Nov 5 '09, 01:12 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you can’t* use C/C++ functions in JavaScript.

    main reason: C++ => compiled in an application, JavaScript => parsed in the browser’s sandbox.

    to create JavaScript you only need a text editor (although tag highlighting and all the bells and whistles make it more comfortable) to write and a simple (X)HTML page to host/execute.

    btw. what makes you think JavaScript is unable to do complex tasks, or is it just the urge to re-use already written code?

    * - if you want to run the JS in the browser, other host applications may provide an API you can use.

    PS.
    Code:
    a++;

    Comment

    • urib
      New Member
      • Nov 2009
      • 14

      #3
      one of the reasons is that I want to re-use already written code but it is not the only reason.

      C is also faster and people told me that I can use something like
      server.createob ject and dll but I am not sure exactly what I need to do for it.

      Some step by step instructions can clearly help me.

      If I can see step by step instructions for a simple example it can help me to use other functions that I already have code for them.

      Uri

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by urib
        C is also faster
        of course it’s faster, compiled code always is (compared to parsed code).
        … unless you have system interactions

        Originally posted by urib
        and people told me that I can use something like
        server.createob ject and dll but I am not sure exactly what I need to do for it.
        never heard of that before. anyway, JavaScript does not have access to local files.

        Originally posted by urib
        If I can see step by step instructions for a simple example it can help me to use other functions that I already have code for them.
        did I already mention that it’s not possible?

        Comment

        • urib
          New Member
          • Nov 2009
          • 14

          #5
          There is a difference between javascript in server and java script in client side.
          I write javascript in runat server(see RUNAT=SERVER in my code).

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I don’t know ASP. and if you want to use the code on the server only, I don’t see the need of using JavaScript at all, which is used (in almost every case) on the client side.

            maybe you’re mistaking C# for JavaScript, they have a very similar syntax.

            Comment

            • urib
              New Member
              • Nov 2009
              • 14

              #7
              Thanks for your replies.
              Maybe I should go to asp.net forum.

              The programmer that I talked with him agree that today javascript is not the best way to code on the server(I understood that he used javescript in the past but today he is using visual studio.net).

              Uri

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by urib
                Maybe I should go to asp.net forum.
                they should definitely know more about MS server scripting

                Originally posted by urib
                The programmer that I talked with him agree that today javascript is not the best way to code on the server
                Javascript has its strength in handling document content.

                Originally posted by urib
                (I understood that he used javescript in the past but today he is using visual studio.net).
                does that mean he uses JavaScript with that IDE?

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  I believe you can use managed c++ as the backend for asP.NET pages in the same way you can use C# and VBNET. Not positive as I've never bothered with managed c++

                  Comment

                  • urib
                    New Member
                    • Nov 2009
                    • 14

                    #10
                    I asked the programmer that I talked with him again and he told me that
                    Today he is using vb.net that is only for server code when he use javascript for client code so I guess the right forum to ask about server coding is vb.net(I still did not decide where to ask my question)

                    Uri

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      I could help out with PHP…

                      Comment

                      Working...