-
Notifications
You must be signed in to change notification settings - Fork 57
Add fnRegsFromStruct for comptime-generation of Lua function registrations #179
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi! Is moving the comptime keyword to caller site the more idiomatic way in Zig? I guess I'm used to doing it the way I did it in the original version.
For example, I see comptime used in the library, not at call time, like in the initCompTime function here:
https://ziglang.org/documentation/master/std/#src/std/static_string_map.zig
I don't have a super strong opinion about, but I guess I have a preference for version that doesn't require the callsite to mark the call comptime.
BTW, I intentionally had this working only for structs because I didn't think this sort of "get decls from a namespace" makes so much sense e.g. in enums or unions. Or it may at least be that some public funcs in an enum likely aren't zlua wrappable. In this case, requiring a struct and giving an error may guide the user of this library to the right path. OTOH, if you had some cool uses in mind, then being overly restrictive is not that great idea either!
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.
no, i think what you did was right! the reason for
comptimehere is actually to move it to a testable part of the API contract. sorry for also unrelatedly fiddling with the implementation a little—I liked proving to myself that my code was equivalent to yours even though it doesn't have an explicitlycomptimeblock.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.
Would you be willing to accept a PR that moves comptime back to ziglua so that users of this API don't need to explicitly add comptime? That seems to be the way it's usually done in std library at least.
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.
I would, if you insist, but I claim that you are misunderstanding what I am saying.
comptimekeyword in the caller here makes no difference and does not need to be done in consumer code.comptimekeyword in the test is so that in the future if the function body is altered to include runtime code, CI will failcomptimeblock. please read the function carefully: the main body of work that it does constructs a[]const FnRegby modifying acomptime var. All of the code up toconst final = funcs;therefore must be run at compile time.Uh oh!
There was an error while loading. Please reload this page.
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.
Oh nice! Thanks for clarifying and sorry for the confusion. I had indeed misunderstood what you said before. In this case there's no need to follow up with a PR. :)