Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with Array/List indexes with xLua #1158

Open
mrpierrot opened this issue Aug 30, 2024 · 3 comments
Open

Deal with Array/List indexes with xLua #1158

mrpierrot opened this issue Aug 30, 2024 · 3 comments

Comments

@mrpierrot
Copy link

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
Copy link
Collaborator

for idx, val in ipairs(cshap_array_or_lua_array) do
end

@mrpierrot
Copy link
Author

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
Copy link

Philofallever commented Sep 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants