LuaBridge3 icon indicating copy to clipboard operation
LuaBridge3 copied to clipboard

No arg error thrown for bool stack get

Open Mellnik opened this issue 2 years ago • 4 comments

Stack<bool>::get does not check whether an actual value exists on stack. This results in LuaBridge silently treating a no value as a valid bool and not throwing any error.

See for example Stack<float> which has a check and reports if a non-float value (or no value) is on stack.

Mellnik avatar Mar 31 '23 12:03 Mellnik

Thanks for reporting, should be pretty trivial to fix.

kunitoki avatar Apr 01 '23 07:04 kunitoki

This poses a question, is LUA_TNIL castable to bool ? Much like how you would cast a pointer to bool to check its validity, this could be debatable.

We might want a strict mode for Stack get, but this will also make it more complex.

kunitoki avatar Apr 01 '23 18:04 kunitoki

Hm, in such case I would always check what the default Lua behavior is.

http://lua-users.org/wiki/ExpressionsTutorial Logical operators

Mellnik avatar Apr 02 '23 23:04 Mellnik

My code expects absent bools (i.e., LUA_TNONE) to get passed into C++ as false. This is LB2 behavior, and it is standard Lua behavior. If you are going to implement a fix, I would request an opt-out.

That said, I have one or two constructors where I would really like to be able to force the programmer to supply the boolean. But I can do that with a proxy constructor.

rpatters1 avatar Apr 03 '23 21:04 rpatters1