From 53a5ca3bf1272c6bec411a4c41b41c693df78590 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 27 Feb 2023 12:30:33 -0800 Subject: [PATCH] Correct table.getn/foreach deprecation RFC (#848) It looks like all three functions actually have been deprecated in Lua 5.1, and removed in Lua 5.2. We do not plan to remove them to retain backwards compatibility, but the RFC should be more precise. --- docs/deprecate-table-getn-foreach.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/deprecate-table-getn-foreach.md b/docs/deprecate-table-getn-foreach.md index 4ce9d46..c6c889d 100644 --- a/docs/deprecate-table-getn-foreach.md +++ b/docs/deprecate-table-getn-foreach.md @@ -6,12 +6,10 @@ Mark table.getn/foreach/foreachi as deprecated ## Motivation -`table.getn` was deprecated in Lua 5.1 that Luau is based on. +`table.getn`, `table.foreach` and `table.foreachi` were deprecated in Lua 5.1 that Luau is based on, and removed in Lua 5.2. `table.getn(x)` is equivalent to `rawlen(x)` when `x` is a table; when `x` is not a table, `table.getn` produces an error. It's difficult to imagine code where `table.getn(x)` is better than either `#x` (idiomatic) or `rawlen(x)` (fully compatible replacement). However, `table.getn` is slower and provides yet another way to perform an operation, leading new users of the language to use it unknowingly. -`table.foreach` and `table.foreachi` were deprecated in Lua 5.2. - `table.foreach` is equivalent to a `for .. pairs` loop; `table.foreachi` is equivalent to a `for .. ipairs` loop; both may also be replaced by generalized iteration. Both functions are significantly slower than equivalent `for` loop replacements, are more restrictive because the function can't yield, and result in new users (particularly coming from JS background) unknowingly using these thus producing non-idiomatic non-performant code. In both cases, the functions bring no value over other library or language alternatives, and thus just serve as a distraction.