diff --git a/Examples/test-suite/lua/enums_runme.lua b/Examples/test-suite/lua/enums_runme.lua index 6211581fe..998f01cfc 100644 --- a/Examples/test-suite/lua/enums_runme.lua +++ b/Examples/test-suite/lua/enums_runme.lua @@ -19,4 +19,12 @@ assert(enums.globalinstance3==30) assert(enums.AnonEnum1==0) assert(enums.AnonEnum2==100) +-- In C enums from struct are exported without prefixing with struct name +-- In C++ they are prefixed. +-- We are emulating xor :) +assert(enums.BAR1 ~= enums.Foo_BAR1) -- It is either C style, or C++ style, but not both +assert((enums.BAR1 ~= nil ) or (enums.Foo_BAR1 ~= nil)) + +assert(enums.Phoo ~= enums.iFoo_Phoo) +assert((enums.Phoo == 50) or (enums.iFoo_Phoo == 50)) -- no point in checking fns, C will allow any value diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 75c94cc6b..116e6a26a 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -139,6 +139,7 @@ private: STATIC_FUNC, STATIC_VAR, STATIC_CONST, // enums and things like static const int x = 5; + ENUM_CONST, // This is only needed for backward compatibility in C mode STATES_COUNT }; @@ -1010,8 +1011,16 @@ public: bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0; if (make_v2_compatible) { - target_name_v2 = Swig_name_member(0, class_symname, target_name); - iname_v2 = Swig_name_member(0, class_symname, iname); + // Special handling for enums in C mode - they are not prefixed with structure name + if(!CPlusPlus && current[ENUM_CONST]) { + target_name_v2 = target_name; + DohIncref(target_name_v2); + iname_v2 = iname; + DohIncref(iname_v2); + } else { + target_name_v2 = Swig_name_member(0, class_symname, target_name); + iname_v2 = Swig_name_member(0, class_symname, iname); + } n_v2 = Copy(n); //Printf( stdout, "target name v2: %s, symname v2 %s\n", target_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE if (!luaAddSymbol(iname_v2, n, class_parent_nspace)) { @@ -1074,8 +1083,10 @@ public: virtual int enumDeclaration(Node *n) { current[STATIC_CONST] = true; + current[ENUM_CONST] = true; int result = Language::enumDeclaration(n); current[STATIC_CONST] = false; + current[ENUM_CONST] = false; return result; }