Rawiter

From GiderosMobile

Available since: Gideros 2025.2
Class: (global)

Description

Iterates keys in a table, without invoking any metamethod. table must be a table, key may be any value.

(key),(value),(nextindex) = rawiter(table,index)

Lua next() and pairs() calls work on keys, which means that Luau have to lookup the previous key to find the next one on each iteration. Enabling optimizations with the above call enables a fast path for 'for' loops with a 'pairs' call, but nothing is done if you use them outside a 'for' loop.

But Luau 'C' API had a lua_rawiter() call which allowed to keep an internal index during key/value pairs iterations, it is now available to Lua code.

Parameters

table: (table) table to iterate
index: (number) index in the table

Return values

Returns (any) the table key
Returns (any) the table value
Returns (number) the table next index