lua-users home
lua-l archive

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


On Thu, Mar 22, 2018 at 12:17 PM, Petri Häkkinen wrote:
here are the results of my experiment with adding arrays to Lua.Any feedback, critique, questions, comments etc. are welcome!

Wow!  That's strong arrays!

Will concatenation operator be available out-of-the-box?
[1, nil] .. [nil, 4]  --> [1, nil, nil, 4]

How about default arrays' metatable?
([1, nil, 3]):sub(-2)  --> [nil, 3]
([]):append(42, 33, nil):remove(2)  --> [42, nil]

Now consuming all Lua VM memory is much easier than before :-)
([])[1e8]=0

How to stop writing [[ when I want to create 2D-array?
[ [1], 2] -- ok
[[1], 2] -- syntax error
[[1],[2]] -- syntactically correct, but not a 2D-array! :-)


Could we sometimes create an array without actually creating an array?
function f(...)
   local arr = [...]
   -- if the code of this function doesn't modify arr (and doesn't pass arr somewhere else)
   -- then data should be stored on the stack, no array actually should be created
   -- access to arr[k] and #arr should be emulated
   for k = 1, #arr do print(k, arr[k]) end
end