-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeExample.cpp
More file actions
27 lines (23 loc) · 788 Bytes
/
Copy pathNativeExample.cpp
File metadata and controls
27 lines (23 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* @Author: khfahqp khfahqp@gmail.com
* @LastEditors: khfahqp khfahqp@gmail.com
* Copyright (c) 2026 by FlybirdGames, All Rights Reserved.
*/
#include <jni.h>
#include <libJTool/JTool.hpp>
extern "C" JNIEXPORT jint JNICALL
Java_com_example_NativeApi_parseNumber(JNIEnv* env, jclass, jstring text) {
auto helper = jtool::JHelper::fromJniEnv(env);
auto integerClass = helper.findClass(jtool::kInteger);
auto method = helper.createMethod(
integerClass,
jtool::JavaType::kInt,
"parseInt",
"(Ljava/lang/String;)I",
{jtool::JniObject::objectValue(text, jtool::JavaType::kStringObject)});
jint result = 0;
if (helper.invoke(method)) {
result = helper.getReturnValue(method)->m_value.m_int;
}
return result;
}