alef 0.67.4

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    private static void checkLastError() throws Throwable {
        int errCode = (int)(long) NativeLib.{{ prefix_upper }}_LAST_ERROR_CODE.invoke();
        if (errCode != 0) {
            var ctxPtr = (MemorySegment) NativeLib.{{ prefix_upper }}_LAST_ERROR_CONTEXT.invoke();
            String msg = ctxPtr.equals(MemorySegment.NULL)
                ? "Native call failed with error code " + errCode
                : ctxPtr.reinterpret(Long.MAX_VALUE).getString(0);
            switch (errCode) {
{% for error_code in error_codes %}
                case {{ error_code.0 }} -> throw new {{ error_code.1 }}(msg);
{% endfor %}
                default -> throw new {{ class_name }}Exception(errCode, msg);
            }
        }
    }