Difference between revisions of "Rawiter"

From GiderosMobile
(wip)
Line 8: Line 8:
 
(any) = rawiter(table,key)
 
(any) = rawiter(table,key)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
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 ===
 
=== Parameters ===

Revision as of 07:48, 6 February 2025

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.

(any) = rawiter(table,key)

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
key: (any) key value in the table

Return values

Returns (any) value from the table