Scala:在JNI方法中创建/使用自定义类型
Scala: Create /use custom types in JNI methods
我有各种Scala原生方法。一些例子:
@native protected def xOpen(): Long
@native protected def flushNative(xServPtr: Long): Unit
@native protected def drawLineNative(xServPtr: Long, winPtr: Long, x1: Int, y1: Int, x2: Int, y2: Int): Unit
@native protected def newGraphicsContextNative(xServPtr: Long, winPtr: Long): Long
//And a couple of the signatures from the C++ file.
extern "C" JNIEXPORT void JNICALL Java_pXClient_XCClass_flushNative(JNIEnv * env, jobject c1, jlong displayPtr)
extern "C" JNIEXPORT jlong JNICALL Java_pXClient_XCClass_newGraphicsContextNative(JNIEnv * env, jobject c1,
jlong displayPtr, jlong winPtr)
我希望在指针上有更强的打字能力,而不是把它们都当作长传。有没有一种方法可以在这里使用AnyVal类,例如:
class XServPtr(val value: Long) extends AnyVal
class WinPtr(val value: Long) extends AnyVal
我可以向JNI添加自定义类型吗?然后,我可以进行从JNI类型到特定c++指针类型的自定义c++隐式类型转换,并在两端都具有类型安全性。
如果您想在类型中显式,您可以使用类似的东西
type wPtr = Any
type HANDLE = wPtr
type HWND = wPtr
@native def SHGetFolderPath(hwndOwner: HWND, nFolder: Int, hToken: HANDLE, dwFlags: Int, pszPath: Array[Char]): Int
至少,我要试一试:)
编辑:最后我做了一个Scala版本的@585534来做我想做的事。
相关文章:
- 使用QJsEngine在Qt中注册自定义类型
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 如何使自定义类型在unordered_map中用作键
- Qt5 远程对象 + 自定义类型,但不在 POD 中
- 标准::原子中的自定义类型
- 如何使用自定义类型声明Arduino数组?
- 使用自定义访问者时具有自定义类型的提升变体失败(源自 boost::static_visitor)
- 您可以将binary_search应用于具有自定义类型的矢量吗?
- 在自定义类型图中重用 SWIG 映射
- 扩展自定义类型的spdlog
- 重载自定义类型的 std::to_string 和 std::to_chars?
- 自定义类型转换运算符在转发引用上调用时不起作用(当对象按值传递时有效)
- 初始化自定义类型构造函数的数组
- 如何使用 QListIterator 的声明自定义类型定义
- 向前删除标题文件中其他名称空间的自定义类型
- 如何为提升日志和自定义类型定义输出流运算符
- typedef 中的自定义类型为 Qt MetaType
- 无法专门化 std::hash 以unordered_map存储自定义类型
- 运算符/ STD :: Chrono ::持续时间和自定义类型与Clang