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

typeof() not functioning correctly for lightuserdata with a metatable #1335

Closed
forenoonwatch opened this issue Jul 18, 2024 · 0 comments · Fixed by #1346
Closed

typeof() not functioning correctly for lightuserdata with a metatable #1335

forenoonwatch opened this issue Jul 18, 2024 · 0 comments · Fixed by #1346
Assignees
Labels
bug Something isn't working

Comments

@forenoonwatch
Copy link

When creating a lightuserdata with a metatable and defining the __type tag, calling typeof() on the resultant object prints userdata, while it functions normally with a normal userdata object.

Code to reproduce:

lua_pushlightuserdata(L, anyValue);

if (luaL_newmetatable(L, "MyType")) {
  lua_pushstring(L, "MyType");
  lua_setfield(L, -2, "__type");
}

lua_setmetatable(L, -2);

lua_setglobal(L, "obj");
table.foreach(getmetatable(obj), print) -- metatable is not nil and correctly prints __type  MyType
print(typeof(obj)) -- prints userdata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants