如何让编译器根据版本跳过一个函数?

How to make compiler skip a function based on the version?

我正在尝试根据版本信息向编译器公开一个函数。

我有这个版本信息。

#define LUA_VERSION_NUM     503

并且我只想在版本等于或小于501

时包含以下功能
static void lua_len(lua_State *L, int i) 
{
    //do something
}

这在 C++ 中如何实现?

#if LUA_VERSION_NUM <= 501
static void lua_len(lua_State *L, int i) 
{
    //do something
}
#endif

您可能希望为 501 以上的版本提供一个空 lua_len 以防止编译错误:

#if LUA_VERSION_NUM <= 501
static void lua_len(lua_State *L, int i) 
{
    //do something
}
#else
static void lua_len(lua_State *L, int i) {}
#endif