lua-users home
lua-l archive

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




On 30 Sep 2022, at 20:35, Max De Marzi <maxdemarzi@hotmail.com> wrote:

The code below runs just fine on both of these online Lua websites.
local tab = {} 
tab[938388893] = "hi" 
tab[987383332] = "Hello"
for k,v in pairs(tab) do
 print(k) 
print (v) 
end

But when I try it using the Sol2 library (embedded in C++) it eats all my memory. 
It seems to create a giant table with the array part full of mostly empty values and just those two strings in their corresponding array slots.

Is it a Sol2 issue or a C Lua binding issue? Anybody know?

I’d say probably Sol. It’s a matter of modelling the data. I’ve seen the same issue with JSON encoders that check a table for integer-only keys, and then assume the thing is to be encoded as an array. This obviously ends up as one massive JSON blob.

I don’t know Sol, but maybe add a dummy-key (non-integer) to the table, to force it to not encode as an array?

Thijs