[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: C API - lua_next traversal of "array" table
- From: "Liam Devine" <liamdevine@...>
- Date: Fri, 19 Aug 2016 09:01:53 +0100
On 19/08/2016 01:48, ThePhD wrote:
Well, I looked into this deeper after everyone gave me the
conventional wisdom to NOT depend on `lua_next`'s iteration order and
pray for no breaking changes.
It turns out that the correct wisdom -- iterate using an index value
-- seems to also be the most performant wisdom from the C++ or C side.
 compares the performance of calling `lua_next()` in a while loop
and assuming it iterates in the right order, pushing a table and
calling `lua_geti` with the indices (and knowing the size and indices
before hand), and the other measures the doing a lua_pushinteger +
lua_gettable. Measured in a computer with an i7 Intel chip, lots of
ram, Windows 10, Lua 5.3.3 compiled as a DLL.
Interestingly, the pushinteger + gettable method is about equal to the
lua_next implementation. So, for Lua 5.2 and lower, since there's no
lua_geti intrinsically built into the API, the correct way is equal in
performance to the UB way.
There is however a lua_rawgeti method that you can use.