diff options
author | chai <chaifix@163.com> | 2021-11-09 19:22:13 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-09 19:22:13 +0800 |
commit | d8417b03b9c2a820d3d3be0dfa80841b4d1f4c04 (patch) | |
tree | 7d036d283bd7a626d56c5c5a725733df439c8368 /Runtime/Lua/LuaBind | |
parent | 13f477664c07826c92eac774f0035994c460c057 (diff) |
*misc
Diffstat (limited to 'Runtime/Lua/LuaBind')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBind.h | 1 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.cpp | 8 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.h | 3 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindLClass.h | 16 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.cpp | 7 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 4 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindTable.h | 2 |
7 files changed, 36 insertions, 5 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBind.h b/Runtime/Lua/LuaBind/LuaBind.h index b6c5870..2a73c98 100644 --- a/Runtime/Lua/LuaBind/LuaBind.h +++ b/Runtime/Lua/LuaBind/LuaBind.h @@ -12,5 +12,6 @@ #include "LuaBindState.inc" #include "LuaBindInvoker.h" #include "LuaBindTable.h" +#include "LuaBindLClass.h" #endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp index debebf8..a95ef5c 100644 --- a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp @@ -76,12 +76,18 @@ namespace LuaBind ++argc; } - void MemberInvoker::AddTable(INativeTable& tb) + void MemberInvoker::AddTable(const INativeTable& tb) { tb.CastToTable(state); ++argc; } + void MemberInvoker::AddLuaObject(const ILuaClass& obj) + { + obj.CastToLuaObject(state); + ++argc; + } + void MemberInvoker::AddMember(MemberRef member) { owner->PushMemberRef(state, member); diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h index 8ea57a2..edb0725 100644 --- a/Runtime/Lua/LuaBind/LuaBindInvoker.h +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h @@ -56,7 +56,8 @@ namespace LuaBind void AddNil(); void AddBool(bool b); void AddString(const char* str); - void AddTable(INativeTable& tb); + void AddTable(const INativeTable& tb); + void AddLuaObject(const ILuaClass& obj); template<class T> void AddUserdata(NativeClass<T>& udata) { udata.PushUserdata(state); diff --git a/Runtime/Lua/LuaBind/LuaBindLClass.h b/Runtime/Lua/LuaBind/LuaBindLClass.h new file mode 100644 index 0000000..9f4c959 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindLClass.h @@ -0,0 +1,16 @@ +#pragma once
+
+namespace LuaBind
+{
+
+ class State;
+
+ // 需要转成lua class对象的实现这个接口,创建一个lua的对象,放在栈顶
+ class ILuaClass
+ {
+ public:
+ virtual void CastToLuaObject(State&) const = 0 ;
+
+ };
+
+}
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp index 676c19c..92e46cd 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.cpp +++ b/Runtime/Lua/LuaBind/LuaBindState.cpp @@ -196,7 +196,12 @@ namespace LuaBind } } - void State::PushTable(INativeTable& tb) + void State::PushLuaObject(const ILuaClass& lc) + { + lc.CastToLuaObject(*this); + } + + void State::PushTable(const INativeTable& tb) { tb.CastToTable(*this); } diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index 24bd092..aaad952 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -7,6 +7,7 @@ #include "LuaBindRefTable.h" #include "LuaBindGlobalState.h" #include "LuaBindTable.h" +#include "LuaBindLClass.h" namespace LuaBind { @@ -101,7 +102,8 @@ namespace LuaBind bool HasField(int idx, int name, int type); bool HasKeys(int idx); - void PushTable(INativeTable& tb); + void PushLuaObject(const ILuaClass& lc); + void PushTable(const INativeTable& tb); void PushNil(); void Push(bool value); void Push(cc8* value); diff --git a/Runtime/Lua/LuaBind/LuaBindTable.h b/Runtime/Lua/LuaBind/LuaBindTable.h index 3a6ec6c..a3822d3 100644 --- a/Runtime/Lua/LuaBind/LuaBindTable.h +++ b/Runtime/Lua/LuaBind/LuaBindTable.h @@ -9,7 +9,7 @@ namespace LuaBind struct INativeTable { // 将结构转换为table并留在栈顶 - virtual void CastToTable(State& state) = 0; + virtual void CastToTable(State& state) const = 0; }; }
\ No newline at end of file |