-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainkt.kt
More file actions
42 lines (37 loc) · 1.51 KB
/
Mainkt.kt
File metadata and controls
42 lines (37 loc) · 1.51 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
import java.lang.foreign.*;
import java.lang.invoke.*;
fun main() {
val arena = Arena.ofConfined()
val linker = Linker.nativeLinker()
val lookup = SymbolLookup.libraryLookup("tcl86t", arena).or(SymbolLookup.libraryLookup("tk86t", arena))
val createInterp = linker.downcallHandle(
lookup.find("Tcl_CreateInterp").get(),
FunctionDescriptor.of(ValueLayout.ADDRESS)
)
val init = linker.downcallHandle(
lookup.find("Tcl_Init").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)
)
val eval = linker.downcallHandle(
lookup.find("Tcl_Eval").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
)
val tk_init = linker.downcallHandle(
lookup.find("Tk_Init").get(),
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)
)
val tk_mainloop = linker.downcallHandle(
lookup.find("Tk_MainLoop").get(),
FunctionDescriptor.ofVoid()
)
val interp = createInterp.invoke() as MemorySegment
eval.invoke(interp, arena.allocateFrom("set tcl_library {tcl8.6}"))
eval.invoke(interp, arena.allocateFrom("set tk_library {tk8.6}"))
val result0 = init.invoke(interp) as Int
println(result0)
val result1 = tk_init.invoke(interp) as Int
println(result1)
eval.invoke(interp, arena.allocateFrom("button .b -text \"click me\""))
eval.invoke(interp, arena.allocateFrom("pack .b"))
tk_mainloop.invoke()
}