John Huang
11/15/2022, 7:41 PMnapperley
11/16/2022, 10:30 PMnapperley
11/16/2022, 10:32 PMJohn Huang
11/16/2022, 10:40 PMChris Lee
11/16/2022, 10:41 PMJohn Huang
11/16/2022, 10:42 PMnapperley
11/16/2022, 10:42 PMChris Lee
11/16/2022, 10:44 PMBig Chungus
11/17/2022, 11:56 AMBig Chungus
11/17/2022, 11:57 AMnapperley
11/17/2022, 11:29 PMnapperley
11/17/2022, 11:30 PMSam Gammon
11/17/2022, 11:54 PMSam Gammon
11/17/2022, 11:57 PMimport java.io.*;
import org.graalvm.polyglot.*;
object Polyglot {
@JvmStatic fun main(args: Array<String>) {
val polyglot = Context.newBuilder().allowAllAccess(true).build()
val file = new File("polyglot")
val source = Source.newBuilder("llvm", file).build()
val cpart = polyglot.eval(source)
cpart.execute()
}
}
that's calling into native code from kotlin. to call into kotlin, you would need to use the Polyglot C API:
#include <stdio.h>
#include <graalvm/llvm/polyglot.h>
int main() {
void *arrayType = polyglot_java_type("int[]");
void *array = polyglot_new_instance(arrayType, 4);
polyglot_set_array_element(array, 2, 24);
int element = polyglot_as_i32(polyglot_get_array_element(array, 2));
printf("%d\n", element);
return element;
}
Sam Gammon
11/17/2022, 11:57 PM