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

passing std::string ref from lua to c++ function #66

Closed
badetwiler opened this issue Feb 15, 2015 · 6 comments
Closed

passing std::string ref from lua to c++ function #66

badetwiler opened this issue Feb 15, 2015 · 6 comments

Comments

@badetwiler
Copy link

I'm calling a c++ class member function from lua that has a std::string& argument. Once called an empty string is passed in. The correct string is passed in if I change the function's argument to accept std::string rather than std::string&. Is there any way around this by registering std::string somehow?

@jeremyong
Copy link
Owner

Can you try changing the function signature to const std::string& and see if it still happens?

@badetwiler
Copy link
Author

changing the function signature from std::string& to std::string fixes the issue. It happens to be a 3rd partly library I'm trying to wrap, so I was trying to avoid modifying it. But it's not a huge deal. Thanks for your quick response.

@jeremyong
Copy link
Owner

Well I think this might be a bug since I am handling functions with parameter type "const std::string &" in a special way. Again, does the adding the const qualifier fix it or does the function mutate the string?

@badetwiler
Copy link
Author

sorry I didn't state this previously; the function argument is specifically "const std::string&". When called from lua I'm seeing just an empty string passed in. Changing the argument to pass by value rather than reference fixes the issue.

@jeremyong
Copy link
Owner

Looks like I have tests for returning strings from class member functions but not sending them :P. Let's leave this open in case I have time to address it and add a new test case. Thanks!

@badetwiler
Copy link
Author

great, thanks for the help, maybe I'll try sometime as well just to give myself a sanity check

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

2 participants