cephalo
Deity
I would like to make a table that stores map data in an array, but automatically converts a zero based index to a 1 based index under the hood for library functions like printing and sorting. Dealing with map data, especially when it wraps in the X direction requires alot of modulus arithmetic on the indexes and I'm used to doing things a certain way that can be complicated sometimes, and I want to simplify it for myself.
I'm learning about metatables, and it seems from the documentation that the _index metatable method is only called when a table access fails to find the index. If I try to use that to add 1 to my index, it needs to happen every time not just during failure or the wrong data will be accessed.
Anyone have any advice on how to do this? In order to do index math in the way that I'm accustomed to without a massive struggle with 1-off data errors, I'd like to create a zero based array that is also compatible with the lua library functions.
I'm learning about metatables, and it seems from the documentation that the _index metatable method is only called when a table access fails to find the index. If I try to use that to add 1 to my index, it needs to happen every time not just during failure or the wrong data will be accessed.
Anyone have any advice on how to do this? In order to do index math in the way that I'm accustomed to without a massive struggle with 1-off data errors, I'd like to create a zero based array that is also compatible with the lua library functions.