gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
308 stars 21 forks source link

Godot Array Indexing #6

Closed bojjenclon closed 2 years ago

bojjenclon commented 2 years ago

Currently, an object constructed from the Array wrapper in Lua requires zero-indexing to access its elements. This looks wrong next to Lua's one-indexing, and can lead to some odd logic that requires checking types and adding/subtracting one to avoid OBO errors. Should Array be changed to one based indexing?

gilzoide commented 2 years ago

Hmm, that's a good question. I think most of the time people won't be calling the same functions with both tables and Arrays/Pool*Arrays, but now that I'm thinking better about it, I guess making both work with 1-based indexing will do more good than harm. Anyone wanting 0-based indexing with Arrays can still call get/set or safe_get/safe_set if they know they have an Array/Pool*Array in hand.

In this case, I think we should also change Array.__ipairs to return indices starting from 1.

bojjenclon commented 2 years ago

An example where you may use both Lua tables and Godot Arrays is using a LuaRocks library to perform some data manipulations then converting it into a specific Godot Array indexing scheme.

I agree about ipairs though.

gilzoide commented 2 years ago

Good point, thanks for the insight! Ok then, I'll make it happen =]