-
Notifications
You must be signed in to change notification settings - Fork 55
Conversation
@dcharkes Ideally we'd just have a single |
I'd like to use consistent naming among FFIgen and JNIgen. We had the same discussion in JNIgen but didn't make a move there. dart-lang/native#585 I believe the renumbering here might be worse because the blocks are not named within a class like the constructors in Java or Kotlin. Do you have some examples of how bad the renumbering gets on some example APIs? |
The HealthKit example I'm working on gets up to I definitely want to switch to either this PR's type name approach, or figure out how to do it using templates. The question is whether we like |
Okay, that sounds rather painful. So we definitely want a solution here. If you run FFIgen on a substantial part of the APIs, how large to the names get?
wdym? You're using a type argument there right? Not a template? |
The longest name in the HealthKit bindings is
Yeah, I meant type arguments. In C++ land these are called templates, and I've been using the same term in Dart. What does "template" mean to you, in a Dart context? Anyway, @dcharkes I was just wondering if you had any opinion about whether UPDATE: I tried implementing the type arg approach today, but I can't figure out a clean way of doing the constructors. They need to be code genned for each block type, but we don't have static extension methods, so there's no good way of doing this AFAICT. Best I can do is put a static method on the extension (and name the extension using the scheme in this PR), which the user would have to invoke like this: ObjCBlock<ffi.Int32 Function(ffi.Int32)> myBlock = ObjCBlock_Int32_Int32.fromFunction(lib, func); The benefits I mentioned above would still apply, so it's arguably still better than just using final myBlock = ObjCBlock<ffi.Int32 Function(ffi.Int32)>.fromFunction(lib, func); Unfortunately I don't see a way of doing that without static extension methods. |
Off-topic: And in doing code generation, a template could just be a string with dollar variable names: https://github.com/flutter/flutter/tree/master/packages/flutter_tools/templates. But that is using templates without type arguments, but in the context of code generation, which we are doing here as well. On-topic:
Can't we achieve that by a factory constructor on |
After playing around a bit, I don't think it's possible to implement a clean |
It's because we need to call some specific generated code based on the type right? It might be worth leaving some documentation trail with examples.
sgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Thanks @liamappelbe !
Instead of
ObjcBlock
,ObjCBlock1
,ObjCBlock2
etc, we assign block names based on their type. These are much more verbose (egObjCBlock_Int32_Int32
) but at least won't change based on header parse order or including more headers like the numbers can. This stability allows users totypedef
the long type names down to more readable names based on their use case.Fixes dart-lang/native#472.