Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function name macro in C++

Tags:

c++

macros

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?

like image 734
Greta Avatar asked Aug 20 '26 19:08

Greta


1 Answers

Token concatenation:

#define lua_tpush(TYPE,L,n,f)  (lua_pushstring(L, n), lua_push##TYPE(L, f))
like image 114
Kerrek SB Avatar answered Aug 23 '26 08:08

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!