We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have this enum:
enum class Scaling{ FITWIDTH, FITHEIGHT, LETTERBOX, CROP, STRETCH };
And these C++ functions:
static void setScalingMode(Scaling scalingMode); static Scaling getScalingMode();
Lua bindings:
luabridge::getGlobalNamespace(L) .beginNamespace("Scaling") .addProperty("FITWIDTH", Scaling::FITWIDTH) .addProperty("FITHEIGHT", Scaling::FITHEIGHT) .addProperty("LETTERBOX", Scaling::LETTERBOX) .addProperty("CROP", Scaling::CROP) .addProperty("STRETCH", Scaling::STRETCH) .endNamespace(); luabridge::getGlobalNamespace(L) .beginClass<Engine>("Engine") .addStaticFunction("setScalingMode", &Engine::setScalingMode) .addStaticProperty("scalingMode", &Engine::getScalingMode, &Engine::setScalingMode) .endClass();
Code in Lua:
Engine.setScalingMode(Scaling.CROP) -- not working Engine.scalingMode = Scaling.CROP -- not working
None of them are working. Is there anyway to get these enum working in function argument?
The text was updated successfully, but these errors were encountered:
Answering my own question. I did this just by specializing luabridge::Stack.
template <class T> struct EnumWrapper { static auto push(lua_State* L, T value, std::error_code& ec) -> std::enable_if_t<std::is_enum_v<T>, bool> { lua_pushnumber(L, static_cast<std::size_t>(value)); return true; } static auto get(lua_State* L, int index) -> std::enable_if_t<std::is_enum_v<T>, T> { return static_cast<T>(lua_tointeger(L, index)); } }; namespace luabridge { template<> struct Stack<Supernova::Scaling> : EnumWrapper<Supernova::Scaling>{}; }
And works!
Sorry, something went wrong.
No branches or pull requests
I have this enum:
And these C++ functions:
Lua bindings:
Code in Lua:
None of them are working. Is there anyway to get these enum working in function argument?
The text was updated successfully, but these errors were encountered: