RE: Implicit casting issues when binding to C++

  • From: "Janis Britals" <jbritals@xxxxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Tue, 10 Jul 2012 15:56:43 +0200

Some more thoughts on enums:

If I start boxing enums in structs to preserve their type, there remains the
issue of casting them back to int. Many functions expect int arguments,
where you can supply an enum or not. If enum is now boxed, I would need to
cast it implicitly to int, but we just agreed to rule out "source" based
implicit conversions. The situation could possibly be mitigated if we could
easily obtain the int value of such boxed enum, but tonumber(struct) doesn't

Could it be an idea to introduce a '__tonumber' metamethod along the same
lines as '__tostring'? Otherwise it feels strange, that an expression
tonumber(enumconst) yields nil. And it could be used as default conversion
method for numeric "dest" types. I know, it contradicts the rule of no
"source" based conversions, but in this case it just maybe would cause no
harm, since "dest" types do not have metatypes, so there is no "dest" based
conversion, and "source" type is not numeric, so it would fail with an error

-- Janis

Other related posts: