Skip to content

Deprecate string.lower in favor of ll.ToLower#77

Open
tapple wants to merge 1 commit intosecondlife:mainfrom
tapple:deprecate-string.lower
Open

Deprecate string.lower in favor of ll.ToLower#77
tapple wants to merge 1 commit intosecondlife:mainfrom
tapple:deprecate-string.lower

Conversation

@tapple
Copy link
Copy Markdown
Contributor

@tapple tapple commented Mar 13, 2026

@tapple
Copy link
Copy Markdown
Contributor Author

tapple commented Apr 4, 2026

string.lower uses 7 fewer bytes than ll.ToLower and runs twice as fast. Is that reason enough to keep it around? I dunno. Tested on Luau 2026-03-24.23471922914

for i = 1, 600 do local _ = ll.ToLower("hElLo WoRlD") end
print(os.clock(), ll.GetUsedMemory() - 2302) -- 0.0030    76
for i = 1, 1300 do local _ = ("hElLo WoRlD"):lower() end
print(os.clock(), ll.GetUsedMemory() - 2302) -- 0.0029    69

@HaroldCindy
Copy link
Copy Markdown
Collaborator

I can see some potential usecases for string.lower() if you expect to only be normalizing ascii text, but in general ll.ToLower() and ll.ToUpper() are preferred for internationalization reasons. That said, I don't know how easy it would be to deprecate in practice given that it's also accessible via the string metatable. Do the linters have support for that case?

@tapple tapple marked this pull request as draft April 9, 2026 14:02
@tapple
Copy link
Copy Markdown
Contributor Author

tapple commented Apr 9, 2026

I added this to the d.luau file:

declare extern type string with
  @[deprecated {use='ll.ToLower', reason='Unicode support.'}] function lower(self): string
end

It seems to work with variables, but not literals, and causes other problems with literals in strict mode:

--!strict
local _ = string.lower("HELLO")
local s: string = "HELLO"
local _ = tostring(NULL_KEY):lower()
local _ = URL_REQUEST_DENIED:lower()
local _ = s:lower()
image
$ ../../secondlife/luau-lsp/build/luau-lsp analyze --defs sl-vscode-plugin/slua_fixes.d.luau string_test.luau 
[INFO] Loading definitions file: @roblox - sl-vscode-plugin/slua_fixes.d.luau
[INFO] sourcemap is disabled - automatic updating on sourcemap changes disabled
string_test.luau(2,24): TypeError: Expected this to be 'string', but got 'string'
string_test.luau(3,1): TypeError: Expected this to be 'string', but got 'string'
string_test.luau(2,11): DeprecatedApi: Member 'string.lower' is deprecated, use 'll.ToLower' instead. Unicode support.
string_test.luau(5,11): DeprecatedApi: Member 'URL_REQUEST_DENIED.lower' is deprecated, use 'll.ToLower' instead. Unicode support.
string_test.luau(6,11): DeprecatedApi: Member 'lower' is deprecated, use 'll.ToLower' instead. Unicode support.

Issues:

  1. False error Expected this to be 'string', but got 'string' on lines 2 and 3 (only with --!strict)
  2. Missing DeprecatedApi error on lines 3 and 4

This works for regular extern types, just not string:

declare extern type uuid with
  @[deprecated {use="logic", reason="reason"}] function randomize(self): uuid
end
image

string seems to be magic, which isn't terribly surprising

@tapple tapple marked this pull request as ready for review April 9, 2026 14:31
@tapple tapple force-pushed the deprecate-string.lower branch from 6605dd5 to 9d804f8 Compare April 9, 2026 14:33
@tapple tapple force-pushed the deprecate-string.lower branch from 9d804f8 to 6518c13 Compare April 13, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants