Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Nov 2009
Posts: 11
#1: 2 Weeks Ago
Suppose that I have some simple function in C like the following when I want to use it in javascript code

Expand|Select|Wrap|Line Numbers
  1. int plus1(int a)
  2. {
  3.     return a+1;
  4. }
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

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript" RUNAT=SERVER>
  2. function plus1(a)
  3. {
  4.   return a+1;
  5. }
  6. Response.Write(plus1(5));
  7. </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.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#2: 2 Weeks Ago

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


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.
Expand|Select|Wrap|Line Numbers
  1. a++;
Newbie
 
Join Date: Nov 2009
Posts: 11
#3: 2 Weeks Ago

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


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.createobject 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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#4: 2 Weeks Ago

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


Quote:

Originally Posted by urib View Post

C is also faster

of course it’s faster, compiled code always is (compared to parsed code).
… unless you have system interactions

Quote:

Originally Posted by urib View Post

and people told me that I can use something like
server.createobject 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.

Quote:

Originally Posted by urib View Post

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?
Newbie
 
Join Date: Nov 2009
Posts: 11
#5: 2 Weeks Ago

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


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).
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#6: 2 Weeks Ago

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


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.
Newbie
 
Join Date: Nov 2009
Posts: 11
#7: 2 Weeks Ago

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


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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#8: 2 Weeks Ago

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


Quote:

Originally Posted by urib View Post

Maybe I should go to asp.net forum.

they should definitely know more about MS server scripting

Quote:

Originally Posted by urib View Post

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.

Quote:

Originally Posted by urib View Post

(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?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#9: 2 Weeks Ago

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


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++
Newbie
 
Join Date: Nov 2009
Posts: 11
#10: 2 Weeks Ago

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


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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,626
#11: 2 Weeks Ago

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


I could help out with PHP…
Reply