Thursday, February 26, 2015

Nim and Java and C++

This single markdown file, mixes: Nim, Java, and C++. The output is a single executeable that includes the Nim code translated to C, the Nim C runtime, Rusthon code translated to C++, and links to the JVM. This allows you to call Nim and Java functions from Rusthon, and manage passing data between them. For how to load a JAR library, see here.


import nim
import jvm

class PointSubclass( Point ):
 def __init__(self, x:int, y:int):

 def show(self):
  print self.getx()
  print self.gety()

def main():
 p1 = jvm( PointSubclass(1,2) )
 p2 = jvm( PointSubclass(10,20) )
 p2.scale( nim_sum(100, 1000) )

Mixing Nim, Java and C++ in a single binary would normally require some complex build, and running a wrapper generator like Nimrod-Java. But Nimrod-Java has not been updated in a year, and calling JNI through Nim is going to complicate threading.

No comments:

Post a Comment