Skip to content

Commit

Permalink
fix special handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 9, 2025
1 parent 90ac8c4 commit 62f7336
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
14 changes: 13 additions & 1 deletion packages/nitrogen/src/syntax/kotlin/KotlinCxxBridgedType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
// Function needs to be converted from JFunc_... to Lambda
return true
default:
return false
break
}
// check if any types this type references (e.g. underlying optional, array element, ...)
// needs special handling. if yes, we need it as well
const referencedTypes = getReferencedTypes(this.type)
.filter((t) => t !== this.type)
.map((t) => new KotlinCxxBridgedType(t))
for (const type of referencedTypes) {
if (type.needsSpecialHandling) {
return true
}
}
// no special handling needed
return false
}

getRequiredImports(): SourceImport[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace margelo::nitro::image {
std::optional<std::function<void(double /* value */)>> JHybridTestObjectSwiftKotlinSpec::getOptionalCallback() {
try {

static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JFunc_void_double::javaobject>()>("getOptionalCallback");
static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JFunc_void_double::javaobject>()>("getOptionalCallback_cxx");
auto __result = method(_javaPart);
return __result != nullptr ? std::make_optional(__result->cthis()->getFunction()) : std::nullopt;

Expand All @@ -361,7 +361,7 @@ namespace margelo::nitro::image {
void JHybridTestObjectSwiftKotlinSpec::setOptionalCallback(const std::optional<std::function<void(double /* value */)>>& optionalCallback) {
try {

static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_double::javaobject> /* optionalCallback */)>("setOptionalCallback");
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_double::javaobject> /* optionalCallback */)>("setOptionalCallback_cxx");
method(_javaPart, optionalCallback.has_value() ? JFunc_void_double::fromCpp(optionalCallback.value()) : nullptr);

} catch (const jni::JniException& exc) {
Expand Down Expand Up @@ -1023,7 +1023,7 @@ namespace margelo::nitro::image {
void JHybridTestObjectSwiftKotlinSpec::jsStyleObjectAsParameters(const JsStyleStruct& params) {
try {

static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JJsStyleStruct> /* params */)>("jsStyleObjectAsParameters");
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JJsStyleStruct> /* params */)>("jsStyleObjectAsParameters_cxx");
method(_javaPart, JJsStyleStruct::fromCpp(params));

} catch (const jni::JniException& exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() {
@set:Keep
abstract var optionalCallback: ((value: Double) -> Unit)?

private var optionalCallback_cxx: ((value: Double) -> Unit)?
get() {
return optionalCallback
}
set(value) {
optionalCallback = value
}

@get:DoNotStrip
@get:Keep
@set:DoNotStrip
Expand Down Expand Up @@ -347,6 +355,13 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() {
@Keep
abstract fun jsStyleObjectAsParameters(params: JsStyleStruct): Unit

@DoNotStrip
@Keep
private fun jsStyleObjectAsParameters_cxx(params: JsStyleStruct): Unit {
val __result = jsStyleObjectAsParameters(params)
return __result
}

@DoNotStrip
@Keep
abstract fun createArrayBuffer(): ArrayBuffer
Expand Down

0 comments on commit 62f7336

Please sign in to comment.