org.lwjgl.system.macosx.MacOSXLibraryDL Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.lwjgl.lwjgl Show documentation
Show all versions of org.lwjgl.lwjgl Show documentation
LWJGL OSGi bundle (Core LWJGL bundle)
The newest version!
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl.system.macosx;
import org.lwjgl.system.*;
import javax.annotation.*;
import java.nio.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.macosx.DynamicLinkLoader.*;
/** Implements a {@link SharedLibrary} on the macOS using {@link DynamicLinkLoader#dlopen dlopen}. */
public class MacOSXLibraryDL extends MacOSXLibrary {
public MacOSXLibraryDL(String name) {
this(name, loadLibrary(name));
}
public MacOSXLibraryDL(String name, long handle) {
super(name, handle);
}
private static long loadLibrary(String name) {
long handle;
try (MemoryStack stack = stackPush()) {
handle = dlopen(stack.UTF8(name), RTLD_LAZY | RTLD_LOCAL);
}
if (handle == NULL) {
throw new UnsatisfiedLinkError("Failed to dynamically load library: " + name + "(error = " + dlerror() + ")");
}
return handle;
}
@Nullable
@Override
public String getPath() {
return SharedLibraryUtil.getLibraryPath(address());
}
@Override
public long getFunctionAddress(ByteBuffer functionName) {
return dlsym(address(), functionName);
}
@Override
public void free() {
dlclose(address());
}
}