I use the behavior of C ++ global variable constructors to easily run code at startup. This is a very simple concept, but a little difficult to explain, so let me just insert the code:
struct _LuaVariableRegistration
{
template<class T>
_LuaVariableRegistration(const char* lua_name, const T& c_name) {
}
};
However, manually creating an instance of this super ugly class every time you want to register a Lua global variable is cumbersome; so I created the following macro:
#define LUA_GLOBAL(lua_name, c_name) static Snow::_LuaVariableRegistration _____LuaGlobal ## c_name (lua_name, c_name);
So, all you have to do is put this in the global area of the cpp file and everything works fine:
LUA_GLOBAL("LuaIsCool", true);
Come here! Now in Lua there LuaIsCoolwill be a variable initialized to true!
But here is the problem:
LUA_GLOBAL("ACCESS_NONE", Access::None);
What will happen:
static Snow::_LuaVariableRegistration _____LuaGlobalAccess::None ("ACCESS_NONE", &Access::None);
: ((
c_name ; __LINE__, _____LuaGlobalAccess__LINE__ (.. ).
, - ?
PS: , , _, ; , , , - . , .