-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (40 loc) · 1.9 KB
/
Main.java
File metadata and controls
45 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.lang.foreign.*;
import java.lang.invoke.*;
public class Main {
public static void main(String[] args) throws Throwable {
try (Arena arena = Arena.ofConfined()) {
Linker linker = Linker.nativeLinker();
SymbolLookup lookup = SymbolLookup.libraryLookup("tcl86t", arena).or(SymbolLookup.libraryLookup("tk86t", arena));
MethodHandle createInterp = linker.downcallHandle(
lookup.find("Tcl_CreateInterp").get(),
FunctionDescriptor.of(ValueLayout.ADDRESS)
);
MethodHandle init = linker.downcallHandle(
lookup.find("Tcl_Init").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)
);
MethodHandle eval = linker.downcallHandle(
lookup.find("Tcl_Eval").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
);
MethodHandle tk_init = linker.downcallHandle(
lookup.find("Tk_Init").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)
);
MethodHandle tk_mainloop = linker.downcallHandle(
lookup.find("Tk_MainLoop").get(),
FunctionDescriptor.ofVoid()
);
var interp = (MemorySegment)createInterp.invoke();
eval.invoke(interp, arena.allocateFrom("set tcl_library {tcl8.6}"));
eval.invoke(interp, arena.allocateFrom("set tk_library {tk8.6}"));
int result0 = (int)init.invoke(interp);
IO.println(result0);
int result1 = (int)tk_init.invoke(interp);
IO.println(result1);
eval.invoke(interp, arena.allocateFrom("button .b -text \"click me\""));
eval.invoke(interp, arena.allocateFrom("pack .b"));
tk_mainloop.invoke();
}
}
}