Skip to content

Conversation

@mdxwzl
Copy link
Contributor

@mdxwzl mdxwzl commented Feb 9, 2025

  • Implemented CFX Lua as a feature flag - cfxlua
    • Compound Operators: +=, -=, *=, /=, <<=, >>=, &=, |=, and ^=
    • Safe Navigation e.g. t?.x?.y == nil
    • In Unpacking e.g. local a, b, c = t is equivalent to local a, b, c = t.a, t.b, t.c
    • Set Constructors e.g. t = { .x, .y } is equivalent to t = { x = true, y = true }
    • C-Style Comments (single & multiline) e.g. /* comment */
    • Compile Time Jenkins' Hashes e.g. `Hello, World!` -> 1395890823

@mdxwzl
Copy link
Contributor Author

mdxwzl commented Feb 9, 2025

Some of the tests dont pass in the workflow, I'll look into it tmrw

@mdxwzl mdxwzl marked this pull request as ready for review February 9, 2025 19:43
@mdxwzl mdxwzl force-pushed the main branch 2 times, most recently from b1ac9c0 to 942e98d Compare February 10, 2025 07:28
@mdxwzl
Copy link
Contributor Author

mdxwzl commented Feb 10, 2025

Would be glad if someone can look over it. I tested the workflows locally with Docker, and it keeps changing up the bytes, line & character values in the AST. Somehow, they are not the same in the workflow environment as on my Windows machine.

@mdxwzl
Copy link
Contributor Author

mdxwzl commented Feb 20, 2025

Test should run now

Copy link
Collaborator

@JohnnyMorganz JohnnyMorganz left a comment

Choose a reason for hiding this comment

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

Thanks for this! I had an initial look - I haven't looked deep into the parser / tokenizer changes yet, I will do this in a follow up

}
/*
CompoundOp and CompoundAssignment have been moved to `compound.rs´, since CfxLua makes use of them as well.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we re-export the types here? To reduce the breaking change on downstream users

SlashEqual(TokenReference),
CaretEqual(TokenReference),

// luau sepcific
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these be gated via cfg(feature = "luau") flags if they are only available in luau?

Some with the below for CfxLua

Comment on lines 26 to 29
LeftShift(TokenReference),
RightShift(TokenReference),
BitwiseAndAssignment(TokenReference),
BitwiseOrAssignment(TokenReference),
Copy link
Collaborator

Choose a reason for hiding this comment

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

To align with the other options. We try to make the names represent the characters rather than the logic, since in future >>= could mean something other than right shift operator for a different Lua dialect

Suggested change
LeftShift(TokenReference),
RightShift(TokenReference),
BitwiseAndAssignment(TokenReference),
BitwiseOrAssignment(TokenReference),
DoubleLessThanEqual(TokenReference),
DoubleGreaterThanEqual(TokenReference),
AmpersandEqual(TokenReference),
PipeEqual(TokenReference),

#[cfg(any(feature = "lua52", feature = "luajit"))]
pub mod lua52;
#[cfg(feature = "lua54")]
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since cfxlua already extends lua54, we don't need to change this config since lua54 should always be enabled

Suggested change
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
#[cfg(feature = "lua54")]

/// A goto statement, such as `goto label`
/// Only available when the "lua52" or "luajit" feature flag is enabled.
#[cfg(any(feature = "lua52", feature = "luajit"))]
#[cfg(any(feature = "lua52", feature = "luajit", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above and in the other cases, I think this can be left alone

Suggested change
#[cfg(any(feature = "lua52", feature = "luajit", feature = "cfxlua"))]
#[cfg(any(feature = "lua52", feature = "luajit"))]

visit_attribute => Attribute,
}

#[cfg(all(feature = "cfxlua", not(feature = "luau")))] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this condition.

We can remove the visit_compound_assignment from the Luau section above and then use any

Suggested change
#[cfg(all(feature = "cfxlua", not(feature = "luau")))] {
#[cfg(any(feature = "cfxlua", feature = "luau"))] {

visit_number,
visit_single_line_comment,
visit_string_literal,
visit_c_style_comment,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be gated by a cfxlua check

#[cfg(any(feature = "lua52", feature = "luajit"))]
use crate::ast::lua52::*;
#[cfg(feature = "lua54")]
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
#[cfg(feature = "lua54")]

/// A set constructor field, such as .a inside { .a } which is equivalent to { a = true }
#[display("{dot}{name}")]
#[cfg(feature = "cfxlua")]
SetConstructorField {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are already in Field, we don't need Field at the end of the name

Suggested change
SetConstructorField {
SetConstructor {

};

#[cfg(any(feature = "cfxlua", feature = "luau"))]
use super::Var;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this was introduced by your IDE.

You should reference it through ast::Var instead, which is already exported

Resolve flaws with CFXLua feature
@Kuuzoo
Copy link
Contributor

Kuuzoo commented Apr 4, 2025

Hi @JohnnyMorganz,
Thank you for your feedback!

I’ve just implemented the suggested changes last night and verified that Clippy is now passing too.

Let me know if there’s anything else you’d like to see.
Thanks again for reviewing!

Comment on lines 14 to 18
PlusEqual(TokenReference),
MinusEqual(TokenReference),
StarEqual(TokenReference),
SlashEqual(TokenReference),
CaretEqual(TokenReference),
Copy link
Owner

Choose a reason for hiding this comment

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

IMO for this and the checks you should do #[cfg(any(feature = "luau", feature = "cfxlua"))]--it makes it clear when adding more what's actually supported by Lua itself (nothing) and what isn't.

#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
#[deprecated(
since = "full-moon 0.18.0",
Copy link
Owner

Choose a reason for hiding this comment

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

We're way past this already, IMO I would ditch since entirely since it doesn't add much value

Comment on lines 627 to 628


Copy link
Owner

Choose a reason for hiding this comment

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

Nit: Remove these

// If the vector length is 0 or there is at least one Some -> false
#[cfg(feature = "luau")]
#[allow(clippy::ptr_arg)]
pub fn no_luau_usage<T>(vec: &Vec<Option<T>>) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is a good name--vec_empty_or_all_none?

@Kampfkarren Kampfkarren merged commit 87d68b2 into Kampfkarren:main Apr 21, 2025
2 checks passed
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.

4 participants