xLua icon indicating copy to clipboard operation
xLua copied to clipboard

Deal with Array/List indexes with xLua

Open mrpierrot opened this issue 1 year ago • 3 comments

Hi.

I would like to know how to correctly manage indexes of array/list instanced from CS ? In CS : array/list indexes start at 0. In Lua : table indexes start at 1.

If I have a function that return an CS array in lua, this is a mess to iterate over. And in my code, I can use lua table and CS array for equivalent usage. That is a big mess.

What do you recommand for that ? Convert manually array/list in lua table (in CS or lua env ? What the best practices for that ?

Thank you

mrpierrot avatar Aug 30 '24 09:08 mrpierrot

for idx, val in ipairs(cshap_array_or_lua_array) do
end

chexiongsheng avatar Sep 02 '24 11:09 chexiongsheng

That don't works with csharp array : I will have an error like that : LuaException: xlua/util.lua:36: index out of range! i =4, array.Length=4

mrpierrot avatar Sep 04 '24 15:09 mrpierrot

That don't works with csharp array : I will have an error like that : LuaException: xlua/util.lua:36: index out of range! i =4, array.Length=4

use pairs instead of ipairs

FalleverX avatar Sep 06 '24 02:09 FalleverX