throw new RuntimeException(e);
}
}
+
+ public static String getConfigPath() {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try {
+ MemorySegment cstr = (MemorySegment)ui.getappdir.invoke();
+ if(cstr == MemorySegment.NULL) {
+ return null;
+ }
+ long len = (long)ui.strlen.invoke(cstr);
+ cstr = cstr.reinterpret(len+1);
+ return cstr.getString(0);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String getConfigFilePath(String fileName) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try(Arena arena = Arena.ofConfined()) {
+ MemorySegment fileNameCstr = arena.allocateFrom(fileName);
+ MemorySegment cstr = (MemorySegment)ui.configfile.invoke(fileNameCstr);
+ if(cstr == MemorySegment.NULL) {
+ return null;
+ }
+ long len = (long)ui.strlen.invoke(cstr);
+ cstr = cstr.reinterpret(len+1);
+ return cstr.getString(0);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
}
public MethodHandle ui_malloc;
public MethodHandle ui_free;
+ public MethodHandle getappdir;
+ public MethodHandle configfile;
+
// some libc stuff
public MethodHandle malloc;
public MethodHandle free;
MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
MemorySegment ui_free_addr = lib.find("ui_free").orElseThrow();
+ MemorySegment getappdir_addr = lib.find("getappdir").orElseThrow();
+ MemorySegment configfile_addr = lib.find("configfile").orElseThrow();
+
MemorySegment malloc_addr = lib.find("malloc").orElseThrow();
MemorySegment free_addr = lib.find("free").orElseThrow();
MemorySegment strlen_addr = lib.find("strlen").orElseThrow();
call_mainthread = linker.downcallHandle(call_mainthread_addr, sigv_mm);
+ getappdir = linker.downcallHandle(getappdir_addr, sigm);
+ configfile = linker.downcallHandle(configfile_addr, sigm_m);
+
ui_malloc = linker.downcallHandle(ui_malloc_addr, sigm_ml);
ui_free = linker.downcallHandle(ui_free_addr, sigv_mm);