summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindState.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-22 23:59:54 +0800
committerchai <chaifix@163.com>2021-10-22 23:59:54 +0800
commit4dafefe46a72ba47468b13d011f8299055081b0f (patch)
tree2a85835ec4d74fecf3815397b384cefe39d31f56 /Runtime/Lua/LuaBind/LuaBindState.h
parent1f18d2afec632aa9361079ca3bcb5a7f2d73db3a (diff)
*LuaBind
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindState.h')
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.h43
1 files changed, 2 insertions, 41 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h
index 9028583..e5b8f6c 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.h
+++ b/Runtime/Lua/LuaBind/LuaBindState.h
@@ -27,6 +27,7 @@ namespace LuaBind
// userdata
// 从userdata通过getmetatable获取上级metatable。除此之外还有一个class table注册在对应
// 的名称空间里。
+ // 把LuaState理解成执行栈
LUA_BIND_API class State
{
public:
@@ -151,9 +152,6 @@ namespace LuaBind
// 注册工厂,适用于普通类,有New方法
template<class TYPE> void RegisterFactory();
- // 注册单例,没有New方法
- template<class TYPE> void RegisterSingleton();
-
// 注册枚举
void RegisterEnum(cc8* name, Enum* enums);
@@ -315,44 +313,7 @@ namespace LuaBind
TYPE::SetClassTableRef(state, -1);
- SetField(top, type);
-
- // reset top
- lua_settop(L, top);
-
- // 后处理
- TYPE::RegisterPostprocess(state);
- }
-
- // 注册单例
- template<typename TYPE>
- void State::RegisterSingleton()
- {
- lua_State* L = mState;
- State& state = *this;
-
- int top = lua_gettop(L); // namespace table
- assert(lua_istable(L, top));
-
- // class table.
- lua_newtable(L);
- TYPE::RegisterClassShared(state);
- TYPE::RegisterSingletonClass(state);
- TYPE::RegisterClass(state);
-
- TYPE::SetClassTableRef(state, -1);
-
- lua_pushvalue(state, -1);
- lua_setfield(state, -2, "__index");
-
-#if LUA_BIND_ENABLE_NATIVE_EXTEND
- // .Extend()
- lua_pushvalue(state, -1); // class table
- lua_pushcclosure(state, TYPE::_ExtendSingleton, 1);
- lua_setfield(state, -2, "Extend");
-#endif
-
- cc8* type = TYPE::GetSingletonName();
+ // namespace[type] = class
SetField(top, type);
// reset top