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

Incorrect function overloading #10

Closed
Xottab-DUTY opened this issue Sep 10, 2018 · 3 comments
Closed

Incorrect function overloading #10

Xottab-DUTY opened this issue Sep 10, 2018 · 3 comments
Labels

Comments

@Xottab-DUTY
Copy link
Member

If you have function with default arguments, like this:

void Kill(CScriptGameObject* who, bool bypass_actor_check = false);

It would be exported to Lua as a functions that accepts two arguments, but not one. If you will try to call it with one argument it will crash.

In the previous luabind version you could use casts to fix the problem:

.def("kill", (void (CScriptGameObject::*)(CScriptGameObject*))&CScriptGameObject::Kill)
.def("kill", (void (CScriptGameObject::*)(CScriptGameObject*, bool))(&CScriptGameObject::Kill))

In this new version this doesn't help. The second parameter will be filled with trash.

@Xottab-DUTY
Copy link
Member Author

#13 is definitely related to this issue. But I don't remember if it fully fixes it or there are problems remain. Sorry, @qweasdd136963 can you remind me?

@qweasdd136963
Copy link

qweasdd136963 commented Feb 21, 2019

частично исправил. Теперь, если при вызове не указывать аргумент по умолчанию, вылета не будет. но вместо этого вместо него будут посланы нуль или false. Но опять же, вылета не будет только на релизе.

@Xottab-DUTY
Copy link
Member Author

Fixable only with constructions like this:

.def("kill", &CScriptGameObject::Kill) // lua:kill(who, true)
.def("kill", +[](CScriptGameObject* thisPtr, CScriptGameObject* who) { thisPtr->Kill(who); }) // lua:kill(who)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants