Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by IshKebab

1 year ago

> I'm not sure if I missed a point you were getting at with this? Lua array table indexes start at 1.

The code example is

    mt = {}          -- create the matrix
    for i=1,N do
      for j=1,M do
        mt[i*M + j] = 0
      end
    end

What index do I use to access the first element in mt? It isn't 1!

If this was written using 0-based indices then the answer would be zero.

0 comments

IshKebab

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities