12-18-2014, 11:02 AM
I've found the source of the bug. When generating the min and max I assumed we would only ever assign literal numbers to enum values, not other constexpr values. So when generating the range check it uses the tonumber of the text strings to generate the max. I'm not sure how to solve this because tolua does not have the awareness of the c++ code to solve this problem generally. To solve the problem generally would require a full c++ parser/type checker, due to templates and c++11 constexpr. (If you're willing to bundle/require clang and the rust runtime, I might write an alternative to tolua that can provide the general solution)
In the special case of using enum values in the global namespace where the enum values are exposed to the lua API, this could possibly be solved by having tolua lookup the values. This would involve exposing the E_META_SPAWNEGG enum values to lua, admittedly documented as not part of the API.
An alternate solution that would require more significant changes to tolua internally would be to implement the previous solution and also add a marker to allow tolua to parse an enum, but not to generate bindings for it. This would solve the special case of using enum values in the global namespace.
In the special case of using enum values in the global namespace where the enum values are exposed to the lua API, this could possibly be solved by having tolua lookup the values. This would involve exposing the E_META_SPAWNEGG enum values to lua, admittedly documented as not part of the API.
An alternate solution that would require more significant changes to tolua internally would be to implement the previous solution and also add a marker to allow tolua to parse an enum, but not to generate bindings for it. This would solve the special case of using enum values in the global namespace.