Tencent / xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.
Other
9.4k stars 2.45k forks source link

Deal with Array/List indexes with xLua #1158

Open mrpierrot opened 2 months ago

mrpierrot commented 2 months ago

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

chexiongsheng commented 2 months ago
for idx, val in ipairs(cshap_array_or_lua_array) do
end
mrpierrot commented 2 months ago

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

Philofallever commented 2 months ago

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