Skip to content

Commit

Permalink
fix #5648 (macros...)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Jul 14, 2017
1 parent 3ff8f21 commit 0b3d408
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rts/Lua/LuaOpenGL.cpp
Expand Up @@ -212,10 +212,12 @@ bool LuaOpenGL::PushEntries(lua_State* L)
{
LuaOpenGLUtils::ResetState();

#define REGISTER_LUA_CFUNC(x) \
lua_pushstring(L, #x); \
lua_pushcfunction(L, x); \
lua_rawset(L, -3)
#define REGISTER_LUA_CFUNC(x) \
do { \
lua_pushstring(L, #x); \
lua_pushcfunction(L, x); \
lua_rawset(L, -3); \
} while (false)

REGISTER_LUA_CFUNC(HasExtension);
REGISTER_LUA_CFUNC(GetNumber);
Expand Down

5 comments on commit 0b3d408

@gajop
Copy link
Member

@gajop gajop commented on 0b3d408 Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff should be posted on sites on why not to use macros.

@RedwanFox
Copy link

@RedwanFox RedwanFox commented on 0b3d408 Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAT. Why not use curly braces only?

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent
if(DONT_PUT_MACRO_HERE())

@sprunk
Copy link
Contributor

@sprunk sprunk commented on 0b3d408 Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ( {stuff} ) is already forbidden.

Consider how just braces would behave here though:

if (condition)
    MACRO();
else
    // stuff

The ; would finish the if statement, orphaning the else.

@12345swordy
Copy link
Contributor

@12345swordy 12345swordy commented on 0b3d408 Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abomination macro code like this is the reason why templates are created and why using marco in general is greatly discouraged.

Seriously though, I have encounter c++ violations being made by the macros that the compiler fails to capture.

Please sign in to comment.