diff options
Diffstat (limited to 'Runtime/Lua')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindClass.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindClass.hpp b/Runtime/Lua/LuaBind/LuaBindClass.hpp index 1da8513..aed4741 100644 --- a/Runtime/Lua/LuaBind/LuaBindClass.hpp +++ b/Runtime/Lua/LuaBind/LuaBindClass.hpp @@ -81,6 +81,8 @@ namespace LuaBind protected: + // 延后绑定VM + NativeClass(); // 需要指明对象所属的虚拟机 NativeClass(LuaBind::VM* vm); virtual ~NativeClass(); @@ -108,6 +110,9 @@ namespace LuaBind // 创建userdata,绑定实例到state。 void BindToLua(State& state); + // 延后绑定VM,在BindToLua中设置 + void LateBindVM(VM* vm); + //------------------------------------------------------------------------------// // 公共内容 @@ -196,6 +201,12 @@ namespace LuaBind } template<class TYPE, class BASE> + void NativeClass<TYPE, BASE>::LateBindVM(VM* vm) + { + mOwner = vm; + } + + template<class TYPE, class BASE> void NativeClass<TYPE, BASE>::PushClassTable(State& state) { LuaBind::VM* vm = state.GetVM(); @@ -203,6 +214,17 @@ namespace LuaBind } template<class TYPE, class BASE> + NativeClass<TYPE, BASE>::NativeClass() + : mWatchDog() + , mUserdata(NULL) + , mOwner(NULL) +#if LUA_BIND_PROFILER + , mSafer(false) +#endif + { + } + + template<class TYPE, class BASE> NativeClass<TYPE, BASE>::NativeClass(LuaBind::VM* vm) : mWatchDog() , mUserdata(vm) @@ -341,6 +363,11 @@ namespace LuaBind { assert(!mUserdata);
+ if (mOwner == NULL)
+ {
+ LateBindVM(state.GetVM());
+ }
+
// 创建userdata并留在栈顶,注意地址要转换为TYPE*,直接用this可能会导致多重继承的类丧失多态。
// 如果直接传this进去,在多重继承情况下,是拿不到另一头的虚函数表的。所以这里需要将this
// 转换为整个对象的低地址,这样可以拿到另一个基类的虚函数表,通过另一个基类实现多态。
|