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

Deal with Lua's implicit number to string conversion in some clean way. #18

Open
Possseidon opened this issue Feb 8, 2021 · 0 comments
Assignees
Labels
dang-lua enhancement New feature or request

Comments

@Possseidon
Copy link
Owner

The main problem here, is that numbers are implicitly converted to strings, which has to actually replace the value on the Lua stack in-place, which can lead to all kinds of trouble. It also prevents their respective wrapper functions from being marked as const, even though only this single conversion actually has this problem.

Plan A would be to add new functions checkExact and atExact/toExact, that only work for exact types. The state and index wrapper functions can be marked as const.

The only real difference would be, that it prevents these implicit conversions:

  • number <-> string
  • any -> boolean

of which only number to string is actually posing problems.

Additionally, maybe something like this could make sense:

void func(dlua::exact<std::string> must_be_string) {}
void func(dlua::exact<bool> must_be_boolean) {}

... but I'm not a 100% sure yet if that would be a great idea.

Plan B would be to ALWAYS use these exact conversions, since implicit conversions are rarely used like this anyways.

This also raises the question, if only the problematic number to string conversion should be disabled, or also string to number, which does not pose a problem. At the very least, any to boolean conversion should probably stay.

@Possseidon Possseidon added enhancement New feature or request dang-lua labels Feb 8, 2021
@Possseidon Possseidon self-assigned this Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dang-lua enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant