"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.invokeOrError = exports.VOID = exports.NULL_POINTER = exports.native = void 0;
const path_1 = __importDefault(require("path"));
const ref_napi_1 = require("ref-napi");
const rainway_ffi_1 = require("./rainway-ffi");
/**
 * Path to the native rainway sdk library
 */
const DLL_PATH = (_a = process.env["RAINWAYSDK_DLL_PATH"]) !== null && _a !== void 0 ? _a : path_1.default.join(__dirname, "../../native/rainwaysdk");
/**
 * The opened librainway library.
 * @internal
 */
exports.native = (0, rainway_ffi_1.dlopen)(DLL_PATH);
/**
 * A Rainway FFI compatible null pointer
 * @internal
 */
exports.NULL_POINTER = ref_napi_1.NULL_POINTER;
/**
 * A RainwayVoid FFI compatible VOID value
 * @internal
 */
exports.VOID = 0;
/**
 * Invokes a Rainway function, throwing an error if it errors.
 * @internal
 * @param name - the name of the function
 * @param cb - the invocation
 */
function invokeOrError(name, cb) {
    const err = cb();
    if (err != rainway_ffi_1.RainwayError.Success) {
        throw new Error(`Failed to invoke ${name}: ${rainway_ffi_1.RainwayError[err]}`);
    }
}
exports.invokeOrError = invokeOrError;
//# sourceMappingURL=native.js.map