-
Notifications
You must be signed in to change notification settings - Fork 36
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
Added support for enum's. #74
base: master
Are you sure you want to change the base?
Conversation
Just the enum patch. |
5f58914
to
7265e68
Compare
Removed the dead code. |
Are there any remaining problems with this patch? I thought you said you were happy with it the other night? |
I'm adding tests to it, and the static interface doesn't make a whole lot of sense when enums are strings. Consider the following correct test: enum E { Key0, Key1 }
pushStaticTypeInterface!E(L);
lua_setglobal(L, "E");
unittest_lua(L, `
assert(type(E) == "table")
assert(E.init == "Key0")
assert(E.Key0 == "Key0")
assert(E.Key1 == "Key1")
assert(#E.keys == 2)
assert(E.keys[1] == "Key0")
assert(E.keys[2] == "Key1")
assert(#E.values == 2)
assert(E.values[1] == 0)
assert(E.values[2] == 1)
`); I think it's pretty unintuitive that |
I agree with your view. And I also suggest the latter, but we can live with it as is for the moment I think. |
For clarity, the reason I created E.Key0 == "Key0" is that if you use E.Key0 in your lua code instead of string literals, it will silently port to userdata when it is written... |
Is this blocked on anything in particular? Anything I can do to help? |
I'd like to offer any assistance I could give too. Manu's patch suite will let me get one of the biggest hacks out of my project's scripting API. |
I have more in the pipeline, but I need to get this sequence of patched through before I push more. The next set start building on top of this stuff, particularly the struct patch. |
@aubade If you want to test my patches with your stuff? I'm only testing against my own environment. |
Sure thing. Can I just pull from your repository's master branch? |
Probably best approach is to fork my repo, and then work against each of my feature branches individually. Then you can create PR to me, and that will flow through to my existing PR's to mainline. So if you want to try each of the features in my feature branches individually against your own project, and make any fixes you need to work with your own code, then PR for each one back to me. Also feel free to add any tests, I've spent a lot of time on this so far, and I just haven't had time to think about comprehensive tests. |
Really sorry it took so long to finally get to this but I've started playing with your code, @TurkeyMan. Initial results are really promising at the moment, but I'm having a regression with some struct properties triggering a "no setters?! shouldn't be here..." assert. I'll try and get a pared down testcase for this. And a short list of things that conversion currently barfs on for me:
The last one is a bit nasty because even @noscript won't stop the compile from erroring out. |
Let me know when you isolate the struct property issue. I've had good results in all my cases. The other 3 you found are cases I never considered. Please feel free to create PR's for those cases of yours too. |
Alright. Pretty minimal testcase to trigger the "no setters?!" error:
And interfaces weren't too hard to implement--I'll have a pull request ready to file soon. The other two, however, are a little bit beyond my current knowledge of D's metaprogramming. BitArray seems to be failing because it has member functions called init that LuaD's trying to use like properties, and I'm not sure how to check for this case. |
I think the problem with your setters is that they don't return void. setters are supposed to return void... (no?) The others should be straight forward, I'll check it out when I have some time. But they're unrelated to this (enum) pull request... |
Non-void setters do work and useful for cases like auto variable = struct.property = 1; And sorry, should I delete the comments and move them to the right PRs? |
Is it idiomatic? I've never seen it anywhere... why isn't that the standard? It's better to comment in the appropriate place, but it doesn't matter now. |
I'm not sure why it isn't more common; I found it out myself through experimentation when a void setter couldn't pass a value transitively, so I'm guessing it's an intentional thing even if it's not explicitly mentioned. DSFML ( https://github.com/Jebbs/DSFML ) does use non-void setters too, so I'm at least not the only person in the world who does it. |
I think non-void setters should be used whenever the getter operation is more or less free. This is not always the case, so void setters often make sense, too.
It should be fixed in Phobos. Naming a member
I'm not sure why a temporary interface should be pushed to LuaD. It's knowingly not as good as it can be and just breaks code later :/ Most of all though, there needs to be tests. In the preliminary tests I wrote for this patch (why am I the one doing it??), there were basic errors in the stack manipulating code that were easily fixed by running some basic tests... |
Yes, this would really help.
Because I've invested a lot (multiple weeks) of time into this suite of patches. Literally as much as I could spare. I need help, and it's kinda your project. I have quite some more work to do here too, but I don't want to continue until at least the struct/class patch is accepted, otherwise I start building on shaky ground. I suspect the struct/class review process may reveal some changes, so it's a waste of time to build on top of that before it's accepted.
Really? Are your tests available? |
Enums are held in Lua as strings. No support for enum values that are not valid keys. No support for bitfields (yet?). Conversion function performance could be improved (linear search >_<).
Enums are held in Lua as strings.
No support for enum values that are not valid keys.
No support for bitfields (yet?).
Conversion function performance could be improved (linear search >_<).