Skip to content

LuaMember AllowNil support#312

Open
ashtonmeuser wants to merge 2 commits into
nuskey8:mainfrom
ashtonmeuser:nil-support
Open

LuaMember AllowNil support#312
ashtonmeuser wants to merge 2 commits into
nuskey8:mainfrom
ashtonmeuser:nil-support

Conversation

@ashtonmeuser
Copy link
Copy Markdown
Contributor

Allows LuaMembers that hold LuaObjects to accept nil assignment from Lua via [LuaMember("my_prop", AllowNil = true)]. This aligns with the C# concept of said LuaObjects being reference types, and thus, accepting null

[LuaObject]
public partial class AllowNilReferencedObject
{
    [LuaMember("label")]
    public string Label { get; set; } = "";
}

[LuaObject]
public partial class AllowNilMemberContainer
{
    [LuaMember("optionalObject", AllowNil = true)]
    public AllowNilReferencedObject OptionalObject { get; set; } = null!;

    [LuaMember("requiredObject")]
    public AllowNilReferencedObject RequiredObject { get; set; } = null!;
}

state.Environment["target"] = new AllowNilMemberContainer();
state.Environment["reference"] = new AllowNilReferencedObject();
target.optionalObject = reference -- Works
target.optionalObject = nil -- Works
target.requiredObject = reference -- Works
target.requiredObject = nil -- Fails

In C#, state.Environment["target"]. OptionalObject is null.

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.

1 participant