繁体   English   中英

如何将java jna接口转换为kotlin

[英]How to translate a java jna interface to kotlin

我正在尝试将openvr绑定移植到kotlin

我在java中有以下内容:

public class IVRSystem extends Structure {

    /**
     * C type : GetRecommendedRenderTargetSize_callback*
     */
    public IVRSystem.GetRecommendedRenderTargetSize_callback GetRecommendedRenderTargetSize;

    public interface GetRecommendedRenderTargetSize_callback extends Callback {

        void apply(IntBuffer pnWidth, IntBuffer pnHeight);
    };
}

Intellij自动将其翻译为

var GetRecommendedRenderTargetSize: IVRSystem.GetRecommendedRenderTargetSize_callback? = null

interface GetRecommendedRenderTargetSize_callback : Callback {

    fun apply(pnWidth: IntBuffer, pnHeight: IntBuffer)
}

我把它改成了:

fun getRecommendedRenderTargetSize(pnWidth: IntBuffer, pnHeight: IntBuffer) = GetRecommendedRenderTargetSize_callback.apply(pnWidth, pnHeight)

interface GetRecommendedRenderTargetSize_callback : Callback {

    fun apply(pnWidth: IntBuffer, pnHeight: IntBuffer)
}

但它抱怨

未解决的参考:申请

为什么? 我该如何解决这个问题?

供参考,C ++代码

class IVRSystem
{
    public:
         virtual void GetRecommendedRenderTargetSize( uint32_t *pnWidth, uint32_t *pnHeight ) = 0;
}

GetRecommendedRenderTargetSize_callback是一个界面。

接口本身没有apply(IntBuffer, IntBuffer)函数,但定义了实现接口实例的功能。

您需要一个实现接口的对象实例,以便能够调用其“apply”函数,但这不是您提供的Java代码的“端口”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM