News for hackers. Stuff that matters.
Re:Berry is a ultra-lightweight dynamically typed embedded s... by norir on Saturday October 07, 2023 @01:31PM (#37803672)
This is somewhat inefficient but zero indexed strings can easily be simulated in lua:

  local array = function(backing)
    local res = { len = function() return #backing end }
    setmetatable(res, {
      __index = function(_, k) return backing[k + 1] end,
      __newindex = function(_, k, v) backing[k + 1] = v end
    })
    return res
  end
  local x = array { 1, 2, 3 }
  print(x[0]) -- 1
  x[1] = 5
  x[x.len()] = 6
  for i = 0, x.len() - 1 do print(x[i]) end -- 1\n5\n3\n6

There are no comments on this comment yet.