C++/Java integration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JonLT
    New Member
    • Jul 2007
    • 41

    C++/Java integration

    Hi!

    I could try to explain what I would like to do, but I think a little code would be much easier to understand. So here goes:

    C++ class:
    Code:
    class Cclass
    {
      void some_C_function(int i)
      {
        printf("%d\n",i);
      }
    };
    Java class:
    Code:
    Class Jclass extends Cclass
    {
      public void some_Java_function(int i)
      {
        some_C_function(i);
      }
    }
    C++ main:
    Code:
    int main()
    {
      Jclass *j = new Jclass;
      j->some_Java_function(5);
    
      return 0;
    }
    So i would like to be able to call c++ functions from java and java functions from c++. The reason for all this is that i would like to be able to use Java as a scripting language for my c++ program.

    Maybe the java class should not extend the c++ class but have the function available in some other way?

    I've read a little about CNI - but it seems that it only enables the calling of java methods from C++, and not the other way around.

    So my questing is this: Can the above be done, or should I look into some other solution to the scripting language problem.

    Thanks
  • JonLT
    New Member
    • Jul 2007
    • 41

    #2
    I've found a thing called pawn - and it does what i want. Sorry about the fast posting.

    Comment

    • gpraghuram
      Recognized Expert Top Contributor
      • Mar 2007
      • 1275

      #3
      Originally posted by JonLT
      I've found a thing called pawn - and it does what i want. Sorry about the fast posting.

      Is the pawn a open source tool?

      Raghu

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JonLT
        ...
        Java class:
        Code:
        Class Jclass extends Cclass
        {
          public void some_Java_function(int i)
          {
            some_C_function(i);
          }
        }
        ...
        1.) Class declarations start with the keyword class (small c) not Class.
        2.) Java is not a scripting language.
        3.) If you want to call c/c++ functions from Java then google JNI.

        Comment

        • JonLT
          New Member
          • Jul 2007
          • 41

          #5
          pawn is open source (zLib/libpng) and lets you call c++ functions from a pawn-script and also call functions in the script from c++.

          The script is compiled using a pawn-compiler and is then executed in an abstract machine (from within the c++ source code).

          The compiler is also open source so it can be implemented in the host application along with the abstract machine.

          Comment

          Working...