According to the LuaBridge readme, LuaBridge does not support "Enumerated constants", which I assume is just enums
. Since sf::Event
is almost entirely enums
, is there any way I can expose the class? Currently the only other solution I can come up with is detect key presses in C++, then send a string to Lua, that describes the event. Obviously, there are around 100+ keys on a modern keyboard, which would cause a massive, ugly segment of just if statements.
For those who haven't used SFML: Link to sf::Event class source code
After attempting to create the function outlined in my question, I discovered that it don't work anyway, because you can't return more than one string in C++, so most events are ignored.
Example Source (doesn't work):
std::string getEvent()
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {window.close(); return "";}
else if (event.type == sf::Event::GainedFocus) {return "GainedFocus";}
else if (event.type == sf::Event::LostFocus) {return "LostFocus";}
else if (event.type == sf::Event::Resized) {return "Resized";}
else if (event.type == sf::Event::TextEntered)
{
if ((event.text.unicode < 128) && (event.text.unicode > 0)) {return "" + static_cast<char>(event.text.unicode);}
}
else if (event.type == sf::Event::KeyPressed)
{
//If else for all keys on keyboard
}
else if (event.type == sf::Event::KeyReleased)
{
//If else for all keys on keyboard
}
else {return "";}
}
return "";
}
Since this question has received zero comments or answers, I've decided not to rule out other libraries. So, if there is a C++ library that supports enums, I will accept it
Since this question has received zero comments or answers, I've decided not to rule out other libraries. So, if there is a C++ library that supports enums, I will accept it
The Thor library, an SFML extension, supports conversions between SFML key types and strings. This would help you serialize enumerators and pass them as strings to Lua -- and back if you need.