From 60b6599e8322dd93e3b33c9496ff035a1c45552f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 15 Jul 2025 14:40:27 -0300 Subject: Short strings can be external, too That complicates a little object equality (and therefore table access for long strings), but the old behavior was somewhat weird. (Short strings, a concept otherwise absent from the manual, could not be external.) --- testes/attrib.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'testes/attrib.lua') diff --git a/testes/attrib.lua b/testes/attrib.lua index 8a3462ea..f4156086 100644 --- a/testes/attrib.lua +++ b/testes/attrib.lua @@ -300,12 +300,6 @@ else assert(_ENV.x == "lib2-v2" and _ENV.y == DC"lib2-v2") assert(lib2.id("x") == true) -- a different "id" implementation - for _, len in ipairs{0, 10, 39, 40, 41, 1000} do - local str = string.rep("a", len) - local str1 = lib2.newstr(str) - assert(str == str1) - end - -- test C submodules local fs, ext = require"lib1.sub" assert(_ENV.x == "lib1.sub" and _ENV.y == DC"lib1") @@ -314,11 +308,11 @@ else _ENV.x, _ENV.y = nil end + _ENV = _G -- testing preload - do local p = package package = {} @@ -337,6 +331,26 @@ do assert(type(package.path) == "string") end + +do print("testing external strings") + package.cpath = DC"?" + local lib2 = require"lib2-v2" + local t = {} + for _, len in ipairs{0, 10, 39, 40, 41, 1000} do + local str = string.rep("a", len) + local str1 = lib2.newstr(str) + assert(str == str1) + assert(not T or T.hash(str) == T.hash(str1)) + t[str1] = 20; assert(t[str] == 20 and t[str1] == 20) + t[str] = 10; assert(t[str1] == 10) + local tt = {[str1] = str1} + assert(next(tt) == str1 and next(tt, str1) == nil) + assert(tt[str] == str) + local str2 = lib2.newstr(str1) + assert(str == str2 and t[str2] == 10 and tt[str2] == str) + end +end + print('+') end --] -- cgit v1.2.3-55-g6feb