Skip to content
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

Allow boolean literals in enums #120

Merged
merged 10 commits into from
Jul 14, 2024

Conversation

gaymeowing
Copy link
Contributor

This pr adds support for boolean literals in enums, a pattern that is useful for result types

ex:

event EVENTI_RESULT = {
	from: Server,
	type: Reliable,
	call: ManyAsync,
	data: enum "succeeded" {
		true {
			from_action: enum { SCHEDULE, END, REMOVE, START, TELEPORT }
		},
		false {
			from_action: enum { SCHEDULE, END, REMOVE, START, TELEPORT },
			error: string,
		}
	},
}

@sasial-dev
Copy link
Collaborator

I'm still unconvinced with this PR, can you explain to me more around the motivation of this PR and why you can't persue the current alternatives?

@gaymeowing
Copy link
Contributor Author

I'm still unconvinced with this PR, can you explain to me more around the motivation of this PR and why you can't persue the current alternatives?

The motivation is that it'd be an easy way to support result types for usecases of reporting datastore errors, roblox api errors, ect, to the client. Plus this is more intended to be a quick fix, as I'd like to not have to use "false" and "true" strings. That don't even atleast coerce into booleans in luau. And this can be replaced with a better syntax in the rewrite, and I'd like to not fully properly implement a solution as this can be just made better in the rewrite.

@sasial-dev
Copy link
Collaborator

sasial-dev commented Jul 14, 2024 via email

zap/src/irgen/mod.rs Outdated Show resolved Hide resolved
zap/src/irgen/mod.rs Outdated Show resolved Hide resolved
@gaymeowing
Copy link
Contributor Author

Probably a result type, something like

result<value_on_sucess, value_on_fail>

that'd then serialize into

type MyResult = {
     success: true,
     -- whatever is included in value_on_sucess, if value_on_sucess is just like a singular type ie u8 or u8 then it will create a value field
} | {
   success: false,
   -- same as the success side but using value_on_fail
}

gaymeowing and others added 2 commits July 13, 2024 21:42
Co-authored-by: Sasial <44125644+sasial-dev@users.noreply.github.com>
Co-authored-by: Sasial <44125644+sasial-dev@users.noreply.github.com>
@gaymeowing gaymeowing requested a review from sasial-dev July 14, 2024 01:43
@jackdotink
Copy link
Member

result types like that will not be happening in rewrite

Copy link
Collaborator

@sasial-dev sasial-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR doesn't fix the typings emitted in both lua and TS. They are "true" and "false" atm

@sasial-dev sasial-dev self-assigned this Jul 14, 2024
Copy link
Collaborator

@sasial-dev sasial-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sasial-dev sasial-dev merged commit 841948a into red-blox:0.6.x Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants