2024-09-16 00:20:03 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-09-18 15:36:11 +02:00
|
|
|
import java.lang.ref.Cleaner;
|
2024-09-17 02:40:03 +02:00
|
|
|
|
2024-09-17 23:16:39 +02:00
|
|
|
/**
|
|
|
|
* A class holding utility functions, as well as functions which are specific
|
|
|
|
* to this language's glue and don't necessarily have a counterpart in the
|
|
|
|
* broader CodeMP API.
|
|
|
|
*/
|
|
|
|
public final class Extensions {
|
2024-09-18 15:36:11 +02:00
|
|
|
/** A {@link Cleaner} handling freeing of memory for library objects. */
|
|
|
|
static final Cleaner CLEANER = Cleaner.create();
|
|
|
|
|
2024-09-16 00:20:03 +02:00
|
|
|
/**
|
2024-09-25 13:14:52 +02:00
|
|
|
* Returns the version of the Rust crate as a String.
|
|
|
|
* @return the current version
|
|
|
|
*/
|
|
|
|
public static native String version();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hashes the given String using CodeMP's hashing algorithm (xxh3).
|
2024-09-16 00:20:03 +02:00
|
|
|
* @param input the string to hash
|
|
|
|
* @return the hash
|
|
|
|
*/
|
|
|
|
public static native long hash(String input);
|
|
|
|
|
|
|
|
/**
|
2024-09-17 23:16:39 +02:00
|
|
|
* Drive the underlying library's asynchronous event loop. In other words, tells
|
|
|
|
* it what thread to use. You usually want to call this during initialisation.
|
|
|
|
* <p>
|
|
|
|
* Passing false will have the native library manage threads, but it may fail to
|
|
|
|
* work with some more advanced features.
|
|
|
|
* <p>
|
|
|
|
* You may alternatively call this with true, in a separate and dedicated Java thread;
|
|
|
|
* it will remain active in the background and act as event loop. Assign it like this:
|
|
|
|
* <p><code>new Thread(() -> Extensions.drive(true)).start();</code></p>
|
|
|
|
* @param block true if it should use the current thread
|
2024-09-16 00:20:03 +02:00
|
|
|
*/
|
|
|
|
public static native void drive(boolean block);
|
2024-09-17 02:40:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures the tracing subscriber for the native logs.
|
2024-09-17 23:16:39 +02:00
|
|
|
* Do not call this unless you want to see the native library's logs.
|
2024-09-17 02:40:03 +02:00
|
|
|
* @param path where to output this, null to use stdout
|
|
|
|
* @param debug whether to run it in debug mode
|
|
|
|
*/
|
|
|
|
public static native void setupTracing(String path, boolean debug);
|
|
|
|
|
|
|
|
static {
|
2024-09-18 14:54:54 +02:00
|
|
|
NativeUtils.loadLibraryIfNeeded();
|
2024-09-17 02:40:03 +02:00
|
|
|
}
|
2024-09-16 00:20:03 +02:00
|
|
|
}
|