Skip to content

Assigning a value to a table with a metatable with __newindex function causes the table reference to become nilΒ #218

@Charanor

Description

@Charanor

Version: 0.4.2 AND 0.5-dev (cloned branch)
Issue: Assigning a value to a table with a metatable containing a __newindex function causes the table reference to become nil. If __newindex is a table or nil then there are no issues.

Runnable C# MVCE:

try
{
	var luaState = LuaState.Create();
	luaState.OpenBasicLibrary();
	await luaState.DoStringAsync("""
	                             local tbl = setmetatable({}, { __newindex = function() end })
	                             print(tbl)
	                             tbl.value = 0
	                             print(tbl)
	                             """);
}
catch (LuaRuntimeException e)
{
	// ...
}

Reproducible Lua code:

local tbl = setmetatable({}, { __newindex = function() end })
print(tbl) -- table: <hash>
tbl.value = 0
print(tbl) -- nil

Without __newindex there are no issues:

local tbl = {}
print(tbl) -- table: <hash>
tbl.value = 0
print(tbl) -- table: <hash>

Also no issues if __newindex is a table:

local tbl = setmetatable({}, { __newindex = {} })
print(tbl) -- table: <hash>
tbl.value = 0
print(tbl) -- table: <hash>

Maybe it's related to #72?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions