This commit is contained in:
nora 2023-01-09 10:01:17 +01:00
parent 193c89c25c
commit 5bfabd3cec
7 changed files with 568 additions and 3 deletions

13
rs-wrapper/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "rs-wrapper"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
[dependencies]
jni = "0.20.0"
minmax = { path = "../minmax-rs" }

View file

@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ch_bbw_m411_connect4_RustPlayer */
#ifndef _Included_ch_bbw_m411_connect4_RustPlayer
#define _Included_ch_bbw_m411_connect4_RustPlayer
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: ch_bbw_m411_connect4_RustPlayer
* Method: rustPlay
* Signature: (B[Lch/bbw/m411/connect4/Connect4ArenaMain/Stone;)I
*/
JNIEXPORT jint JNICALL Java_ch_bbw_m411_connect4_RustPlayer_rustPlay
(JNIEnv *, jobject, jbyte, jobjectArray);
#ifdef __cplusplus
}
#endif
#endif

35
rs-wrapper/src/lib.rs Normal file
View file

@ -0,0 +1,35 @@
// This is the interface to the JVM that we'll call the majority of our
// methods on.
use jni::JNIEnv;
// These objects are what you should use as arguments to your native
// function. They carry extra lifetime information to prevent them escaping
// this context and getting used after being GC'd.
use jni::objects::{JClass, JObject};
// This is just a pointer. We'll be returning it from our function. We
// can't return one of the objects with lifetime information because the
// lifetime checker won't let us.
use jni::sys::{jbyte, jint};
use minmax::{connect4::board::Connect4, GamePlayer};
// 0 -> X
// 1 -> O
pub fn wrap_player<P: GamePlayer<Connect4>>(current_player: i8, board: ()) -> i32 {
0
}
// This keeps Rust from "mangling" the name and making it unique for this
// crate.
#[no_mangle]
pub extern "system" fn Java_ch_bbw_m411_connect4_RustPlayer_rustPlay(
env: JNIEnv<'_>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
class: JClass<'_>,
player: jbyte,
board: JObject<'_>,
) -> jint {
0
}