New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lua] add special markup + handling for extern closure instances #6415
Conversation
e73779a
to
4a51e56
Compare
I'm also looking for recommendations for naming. @:luaClosureInstance seemed clear, anything better? |
@:luaNoImplicitSelf ? |
@:luaDotAccess ? |
I like that better than my suggestion. Is it possible to apply that meta to a field, or only to an entire class? |
Pretty sure I can do both, let me see what that looks like. |
Not too bad! I'll hold this open for a few more days, but I think I can check it in as-is. |
hmmm @:luaDotMethod |
I was researching functions as members of structures and classes in the past hours and I think I have acquired a better understanding of the entire problem. If you are interested I can create some examples of the problems, but essentialy my conclusion is this:
These 2 rules will fix the bugs I am encountering right now, they take into account that classes that match can be assigned to structures (https://haxe.org/manual/types-structure-extensions.html) and the |
Thanks for doing some research on this. I appreciate having another person thinking about it. I originally had the generator working as you say. However, it's easy to run into problems because (as you note) you can assign class-based instances to structural types, methods can be marked "dynamic" and get rebound in the runtime, and in case of dynamic type access, the compiler won't really know which style of method to invoke. It became clear to me that I needed to stick with one style of method invocation for haxe generated code. Haxe as (a general rule) puts no restrictions on run-time access (e.g., all things are "public" in the runtime), so colon style access (with an exposed/rebindable "self" argument) made the most sense as the default. There's a lot of hoops to jump through here, but the end result is that there's no question of how to invoke an instance method for haxe generated code. We can use this extern to provide the sole case that breaks the rule for field access, and I think it'll be a lot easier to reason about moving forward. |
Fair enough. Btw. I just installed the latest development version and some of the problems I had are actually gone. Yay :). |
2f5d17d
to
a693370
Compare
one last tweak, using @:luaDotMethod here. It's clearer about being specific to methods. |
squashed this and merged. |
Here's a simple POC for supporting closure-style extern instances, as described in #6411.
The main idea is to provide special metadata that changes how an extern behaves:
Field method invocations on this instance will be simple "dot" style, rather than the colon.
There's a lot of advantages to this approach... It's restricted to extern only, and I can keep most of the code nicely isolated. Still, I don't think I can make this perfect.
There's ways this could break... it mostly would involve situations with dynamic, reflect, etc... also I guess this breaks if you pass it as a structural type, or try to use inheritance with this. Some of that I can guard against.
The other alternative is to wrap each instance in some kind of proxy that substitutes a dummy "self" argument where necessary. This makes the extern instances easier to pass around through the other type signatures. However, I couldn't think of a good way of doing this automatically (abstracts, etc.). @Simn you have ideas there? Also, I'm guessing the wrapping would add some overhead, which is not really ideal.
I'm leaning more towards the first option, which is what I have here. I have a utility method to support the second approach, but I can't figure out how to automatically apply it.