MX2 Extern Enum Import Problem
Community Forums/Monkey2 Talk/MX2 Extern Enum Import Problem
| ||
Noticed a small thing last night: When importing external enumerations like: Extern Enum Style = "sf::Style" None Titlebar Resize Close Fullscreen End MX2 somehow does not emit correct code for it. If I use Style.Fullscreen somewhere in my code, I get a C++ compiler error because only "Fullscreen" was emitted. Example MX2 code where I use Style.Fullscreen: Local win := New RenderWindow( New VideoMode(1024,600), New sfString("SFML with MX2"), Style.Fullscreen ) I get the following C++ build-error: /[...snip...]/SFML_SFML.cpp:14:127: error: use of undeclared identifier 'Fullscreen'; did you mean 'sf::Style::Fullscreen'? sf::RenderWindow* l_win=new sf::RenderWindow(sf::VideoMode(1024,600,32),sf::String(bbWString(BB_T("SFML with MX2"))),bbUInt(Fullscreen),sf::ContextSettings()); ^~~~~~~~~~ sf::Style::Fullscreen /[...snip...]/../../../include/Window/WindowStyle.h:44:9: note: 'sf::Style::Fullscreen' declared here Fullscreen = 1 << 3, ///< Fullscreen mode (this flag and all others are mutually exclusive) ^ 1 error generated. ***** Fatal mx2cc error ***** Build error. MX2 emits only "bbUInt(Fullscreen)" and C++ does not know this global 'Fullscreen' identifier. As a workaround, I always use full name qualifiers with Enum Imports: Extern Enum Style = "sf::Style" None = "sf::Style::None" Titlebar = "sf::Style::Titlebar" Resize = "sf::Style::Resize" Close = "sf::Style::Close" Fullscreen = "sf::Style::Fullscreen" DefaultStyle = "sf::Style::Default" End No problem, but maybe this could be changed/automated and we could save some time. Could MX2 automate this, so instead of emitting "Fullscreen" it could emit "sf::Style::Fullscreen" - if ' = "sf::Style" ' is already given for the Enum? It's not a problem with Enums only, the following shows the same problem: Extern Struct Color = "sf::Color" Global Black:Color = "sf::Color::Black" Global White:Color = "sf::Color::White" Global Red:Color = "sf::Color::Red" Global Green:Color = "sf::Color::Green" Global Blue:Color = "sf::Color::Blue" Global Yellow:Color = "sf::Color::Yellow" Global Magenta:Color = "sf::Color::Magenta" Global Cyan:Color = "sf::Color::Cyan" Global Transparent:Color = "sf::Color::Transparent" End Without all the ' = "sf::Color::Yellow" ' etc., MX2 emits: l_win->clear(Yellow); But 'Yellow' is no global identifier in C++. MX2 should emit 'l_win->clear(sf::Color::Yellow);' |
| ||
Ok, that's one clever/messed up enum! What they've done here is: namespace WindowStyle{ enum{ Blah, Etc, }; } This is a 'typeless' enum - there is no 'WindowStyle' type, so you can't declare any vars of type 'WindowStyle'. They use uint instead in the interfaces, and must store them internally that way too. Will have to look at this later. Globals/functions in structs/classes should be an easy fix though. |