7 #ifndef __lua_LuaType_h__ 8 #define __lua_LuaType_h__ 15 class LuaBaseType :
public Counted
19 virtual ~LuaBaseType(
void) {}
21 virtual void putMetaTable(
void) = 0;
22 virtual void pushMetaTable(
void) = 0;
24 lua_State *state(
void) {
return m_pContext->state(); }
25 LuaContext *context(
void) {
return m_pContext; }
27 void setMethod(
const String &name, lua_CFunction f)
31 bool pushMethod(String &name)
33 std::map<String, lua_CFunction>::iterator i_methods =
35 if(i_methods == m_methods.end()) {
return false; }
36 lua_pushcfunction(state(), i_methods->second);
42 const String& name(
void)
const {
return m_mtname; }
43 const String verboseName(
void)
const;
47 LuaContext *m_pContext;
49 std::map<String, lua_CFunction> m_methods;
52 inline const String LuaBaseType::verboseName(
void)
const 54 return "LuaBaseType " + name();
57 template<
class T,
class Obj>
58 class LuaType :
public LuaBaseType
61 LuaType(LuaContext *pContext,
const String &mtname)
64 m_pContext = pContext;
68 virtual ~LuaType(
void) {}
69 virtual void pushMetaTable(
void)
71 lua_getglobal(m_pContext->state(), m_mtname.c_str());
73 virtual void putMetaTable(
void)
75 lua_rawgeti(m_pContext->state(),
76 LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
77 lua_pushstring(m_pContext->state(), m_mtname.c_str());
79 lua_settable(m_pContext->state(), -3);
80 lua_pop(m_pContext->state(), 1);
82 virtual void pushNewMetaTable(
void)
84 lua_State *pLuaState = m_pContext->state();
87 luaL_newmetatable(pLuaState,m_mtname.c_str());
89 lua_pushstring(pLuaState,
"__gc");
90 lua_pushcfunction(pLuaState, Obj::destroy);
91 lua_settable(pLuaState, -3);
94 lua_pushstring(pLuaState,
"__index");
95 lua_pushcfunction(pLuaState, Obj::index);
96 lua_settable(pLuaState, -3);
kernel
Definition: namespace.dox:3