Using references for container parameters
Hello,
Suppose I have this function in C++ :
void ShaderSetUniformF(ShaderID ID, const std::string& name, std::vector<float> values);
Now in lua, if I write:
ShaderSetUniformF(shader_multi,"col",{0.1, 0.1, 0.4, 1.0})
Things work as expected.
My question is if this is not the best way to do this, as I am using the values parameter by, erm, value, and if there is any better way. I'm asking this because, for instance,
void ShaderSetUniformF(ShaderID ID, const std::string& name, std::vector<float>& values);
doesn't work (I get an error).
So, is there a good way to pass containers around by reference and still work?
Could you try passing by const reference instead:
void ShaderSetUniformF(ShaderID ID, const std::string& name, const std::vector<float>& values);
Lua tables are far from being C++ std::vectors. Also Lua uses doubles and your std::vector contains floats, so vector references can't possibly point to the original table.