简体   繁体   English

如何将java jna接口转换为kotlin

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

I am trying to port to kotlin the openvr binding 我正在尝试将openvr绑定移植到kotlin

I have the following in java: 我在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 translates it automatically to Intellij自动将其翻译为

var GetRecommendedRenderTargetSize: IVRSystem.GetRecommendedRenderTargetSize_callback? = null

interface GetRecommendedRenderTargetSize_callback : Callback {

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

I changed it then to: 我把它改成了:

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

interface GetRecommendedRenderTargetSize_callback : Callback {

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

but it complains 但它抱怨

unresolved reference: apply 未解决的参考:申请

Why? 为什么? How can I fix that? 我该如何解决这个问题?

For reference, C++ code 供参考,C ++代码

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

GetRecommendedRenderTargetSize_callback is an interface. GetRecommendedRenderTargetSize_callback是一个界面。

The interface itself does not have an apply(IntBuffer, IntBuffer) function but defines such a function for implementing instances of the interface. 接口本身没有apply(IntBuffer, IntBuffer)函数,但定义了实现接口实例的功能。

You'll need an instance of an object which implements your interface in order to be able to call its "apply" function but such would not be a "port" of the Java code you provided. 您需要一个实现接口的对象实例,以便能够调用其“apply”函数,但这不是您提供的Java代码的“端口”。

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

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