External strings are as good as internal ones

A '__mode' metafield and an "n" key both can be external strings.
This commit is contained in:
Roberto I
2025-11-11 14:40:30 -03:00
parent 81f4def54f
commit 5b7d998764
4 changed files with 28 additions and 6 deletions

6
lgc.c
View File

@@ -594,10 +594,10 @@ static void traversestrongtable (global_State *g, Table *h) {
*/
static int getmode (global_State *g, Table *h) {
const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
if (mode == NULL || !ttisshrstring(mode))
return 0; /* ignore non-(short)string modes */
if (mode == NULL || !ttisstring(mode))
return 0; /* ignore non-string modes */
else {
const char *smode = getshrstr(tsvalue(mode));
const char *smode = getstr(tsvalue(mode));
const char *weakkey = strchr(smode, 'k');
const char *weakvalue = strchr(smode, 'v');
return ((weakkey != NULL) << 1) | (weakvalue != NULL);