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

Using references for container parameters #1452

Open
vdweller84 opened this issue Feb 7, 2023 · 2 comments
Open

Using references for container parameters #1452

vdweller84 opened this issue Feb 7, 2023 · 2 comments

Comments

@vdweller84
Copy link

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?

@deadlocklogic
Copy link
Contributor

Could you try passing by const reference instead:

void ShaderSetUniformF(ShaderID ID, const std::string& name, const std::vector<float>& values);

@roman-orekhov
Copy link

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.

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