lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Nov 8, 2019 at 11:02 AM Chris Smith <space.dandy@icloud.com> wrote:

> - Strings are immutable in Lua, but not in C.  C code can directly modify a Lua string and those changes will be reflected in all identical Lua String objects.  This is now defined behaviour

Not according to the ISO C standard.

> - Is there any real difference between Userdata and String objects?  Are Strings simply Userdata whose content is cached and on which string functions can be called?

While one could say that ultimately both just hold a bunch of bytes, the Lua string type is specialized and optimized for the semantics prescribed by Lua. User data have much looser semantics and behaviors. A notable difference is that every single user datum can have a metatable.

Cheers,
V.