Greta
Greta

Reputation: 93

Function name macro in C++

I have a c++ macro that looks like this

#define lua_tpushstring(L,n,f) \
            (lua_pushstring(L, n), lua_pushstring(L, f))

I want to modify it so it works like this

#define lua_tpush(TYPE,L,n,f) \
            (lua_pushstring(L, n), lua_pushTYPE(L, f))

lua_tpush(boolean, L, "a", true);
lua_tpush(string, L, "a", "");

What is the simple change?

Upvotes: 2

Views: 685

Answers (2)

iammilind
iammilind

Reputation: 70088

Just put ## before TYPE.

#define lua_tpush(TYPE,L,n,f) \
            (lua_pushstring(L, n), lua_push##TYPE(L, f))
                     ^^^^^^ did you wanted ##TYPE here

Upvotes: 3

Kerrek SB
Kerrek SB

Reputation: 477504

Token concatenation:

#define lua_tpush(TYPE,L,n,f)  (lua_pushstring(L, n), lua_push##TYPE(L, f))

Upvotes: 6

Related Questions