简体   繁体   中英

Behaviour of lua_pushlightuserdata metatables across different modules in c

I have been tinkering with the Lua C API and I have stumbled on something that I can't quite figure out on my own.

Well , I am aware that you cannot have multiple lighuserdata with different metatables , but is it possible to have lightuserdata in different C modules with individual mettables even if the pointer is of the same type?

eg.

Module A : lightuserdata points to integer type + Metatable A Module B : lightuserdata pointes to integer type + Metatable B

I hope that Module B wont overwrite the metatable on the lightuserdata in Module A.

Anyone know if this will happen?

Lightuserdata cannot have individual metatables: all lightuserdata values have the same metatable, which is initially nil. If you give a metatable to a lightuserdata value, it will be set to all lightuserdata values.

Having individual metatables is the purpose of ordinary, full userdata. Just use full userdata and don't think twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM