Binding static const member variables with luabind
I just tried to bind static const member variables of a class, and was a bit puzzled why scope and/or def_readonly wouldn’t work. Silly me! turns out I don’t have to bind, just put them in the global table at the appropriate place. Here’s an interesting article that also mentions some nice macros. Since my lua states are seldom called L, I present my improved variants of said macros:
#define LUA_CONST_START( class, state ) { luabind::object g = luabind::globals(state); luabind::object table = g[#class];
#define LUA_CONST( class, name ) table[#name] = class::name;
#define LUA_CONST_END }
which helps you bind
struct MouseEvent
{
static const std::string MOUSE_UP;
}
to your Lua state like so:
LUA_CONST_START(MouseEvent, state)
LUA_CONST(MouseEvent, MOUSE_UP)
LUA_CONST_END
No comments
Jump to comment form | comments rss [?] | trackback uri [?]