[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: String metatable and string.len
- From: Halalaluyafail3 <luigighiron@...>
- Date: Sun, 22 Mar 2020 21:44:30 -0400
Strings have a metatable with __index set to the string library so you can call methods directly on strings. (e.g str:sub(1,2)) Is there any reason for this, and why is this only done for strings? Threads and numbers could implement this similarly to how strings do it. (so num:floor(), thread:resume(), etc) Even if it were to be implemented on threads and numbers, it would still feel somewhat inconsistent since tables wouldn't get a metatable. (because each table gets its own metatable)
string.len exists, even though the length operator exists. Isn't it redundant to have a function to have a function which is equivalent to simply using the length operator? table.getn was deprecated and removed, but string.len wasn't. Curious as to why string.len isn't removed by now.