This may be a newbie question, but I have not been able to find an answer with web searching that will even help me get started. I have a container class that at heart is a C-style array. For simplicity, let's depict it as this:
int *myArray = new int[mySize];
With LuaBridge
we can assume I have successfully registered it as my_array
in the global namespace. I would like to iterate over it from Lua like this:
for n in each(my_array) do
... -- do something with n
end
I'm guessing I probably need to register a function each
in the global namespace. The problem is, I don't know what that function should look like in C++.
<return-type> DoForEach (<function-signature that includes luabridge::LuaRef>)
{
// execute callback using luabridge::LuaRef, which I think I know how to do
return <return-type>; //what do I return here?
}
This would perhaps have been easier if the code had used std::vector
but I am trying to create a Lua interface to an existing code base that is complicated to change.