lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

This is just for seeing if I can get the size early. In the case of getting an array back in C or C++, this saves me having to re-allocate if I run out of space in the receiving array (and all that implies in C++), because I can allocate space early.

On Thu, Aug 18, 2016 at 9:25 PM, Daurnimator <> wrote:
On 19 August 2016 at 11:22, ThePhD <> wrote:
> I don't suppose sneaking in some kind of ridiculous key name that includes
> null characters and other things that are vastly improbable for a real Lua
> user to use (something like "\0.not.touch\xE2\x98\xA2.size") for
> when I push the table and then pop the table, and using that MAYBE as a
> shortcut if it's present, and otherwise falling back to iterating until I
> hit a `nil` might be worth it...?

Aren't you already iterating? and hence the cost is the `nil` check...
(with lua_isnil).
If you're already checking the lua_type of your values, it would be 'free'.