Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native functions returning scalars don't work #125

Closed
nikomatsakis opened this issue Mar 12, 2024 · 1 comment
Closed

Native functions returning scalars don't work #125

nikomatsakis opened this issue Mar 12, 2024 · 1 comment

Comments

@nikomatsakis
Copy link
Member

I tried to make a native function...

    native int getAgeNative(long nativePointer);

and the Rust code

#[duchess::java_function(callback.Dummy::getAgeNative)]
fn get_age_native(_this: &callback::Dummy, native_pointer: i64) -> duchess::GlobalResult<i32> {
    let callback: &Callback = unsafe { &*(native_pointer as usize as *const Callback) };
    Ok(callback.age)
}

but this doesn't compile because it invokes

duchess/src/jvm.rs

Lines 182 to 185 in 6d50afe

pub unsafe fn native_function_returning_scalar<J, R>(env: EnvPtr<'_>, op: impl FnOnce() -> R) -> R
where
J: Upcast<crate::java::lang::Object> + Upcast<J>,
R: JavaScalar,

and that function requires a R: JavaScalar. It should require a R: ToJavaScalar (much like native_function_returning_object requires a R: ToJavaImpl<J>. That ToJavaScalar trait should then be implemented for Result.

@bowemi
Copy link
Contributor

bowemi commented Jan 1, 2025

This issue can be closed, this was implemented in cd81289

@rcoh rcoh closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants