LuaMember AllowNil support - #312
Conversation
|
I am wondering if it should be applied automatically with nullable in nullable enable context. |
I considered this and originally used nullable annotations to determine whether or not |
|
I am also uncertain about consistency. |
|
Good point. Although, with a large usage share not having nullable context, there's really only so much you can do. Wholesale accepting |
17836fa to
c4bdbef
Compare
|
@akeit0 Any chance we can get this merged? I know you raised the issue of This PR provides a minimal change that is opt in only. I'd love to see this merged. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Adds AllowNil support for LuaObject reference-type members, allowing Lua nil assignments to map to C# null while preserving required-member validation.
Changes:
- Adds
AllowNilattribute and metadata support. - Generates nullable assignment handling.
- Adds diagnostics and tests for allowed and rejected
nilassignments.
| File | Description |
|---|---|
tests/Lua.Tests/LuaObjectTests.cs |
Tests optional and required LuaObject members. |
src/Lua.SourceGenerator/PropertyMetadata.cs |
Reads AllowNil metadata. |
src/Lua.SourceGenerator/LuaObjectGenerator.Emit.cs |
Emits nullable assignment handling. |
src/Lua.SourceGenerator/DiagnosticDescriptors.cs |
Adds invalid-use diagnostics. |
src/Lua.Annotations/Attributes.cs |
Adds the AllowNil attribute property. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Thanks! |
|
@ashtonmeuser Any thoughts on this? |
That's great to hear! That will be a very welcome feature.
That's fine by me if that's your preference. It's a bit of a judgement call as it's "nil" in Lua and "null" in C#. |
Allows
LuaMembers that holdLuaObjects to acceptnilassignment from Lua via[LuaMember("my_prop", AllowNil = true)]. This aligns with the C# concept of saidLuaObjects being reference types, and thus, acceptingnullIn C#,
state.Environment["target"]. OptionalObjectisnull.