how should I pass and iterate a list of objects from C# to Lua?
My example with an array of int
, when I use custom classes I get the same result:
state_ = new Lua();
state_.LoadCLRPackage();
var candidates = new int[] { 0, 1, 2, 3, 4, 5 };
state_["Candidates"] = candidates;
state_.DoString(script);
var b = state_["Candidates"] as int[];
return toRetrun;
Where the script is
-- Iterate each candidate
for k,v in ipairs(Candidates) do
print(k, Candidates[k])
end
The output is:
1 1
2 2
3 3
4 4
5 5
It skips the first one and I get the exception: "Index was outside the bounds of the array." What's wrong with my code?