summaryrefslogtreecommitdiff
path: root/source/3rd-party
diff options
context:
space:
mode:
Diffstat (limited to 'source/3rd-party')
-rw-r--r--source/3rd-party/Luax/luax_class.hpp65
-rw-r--r--source/3rd-party/Luax/luax_class.inl30
-rw-r--r--source/3rd-party/Luax/luax_ref.h2
-rw-r--r--source/3rd-party/Luax/luax_state.cpp5
-rw-r--r--source/3rd-party/Luax/luax_state.h7
-rw-r--r--source/3rd-party/Luax/luax_state.inl14
6 files changed, 88 insertions, 35 deletions
diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp
index 539ff1a..3d7ede6 100644
--- a/source/3rd-party/Luax/luax_class.hpp
+++ b/source/3rd-party/Luax/luax_class.hpp
@@ -62,28 +62,47 @@ namespace Luax
state.RegisterEnum(name, __e); \
}while(0)
+#define LUAX_PREPARE(L, T) \
+ LUAX_STATE(L); \
+ T* self = state.GetUserdata<T>(1);
+
+ ///
+ /// ࣬Ϊʵֶ̬ҪЩӿڵⲿҪ̳д֮࣬оͻöӦʵķע̳д
+ /// ʱʵķʵLuaxNativeClassУʵֻᵼ¶ԡ
+ ///
+ class ILuaxNativeAccessor
+ {
+ public:
+
+ ///
+ /// Աùʵref tableáȡ
+ ///
+ virtual bool PushLuaxMemberRef(LuaxState& state, int refID) { assert(false); return false; };
+
+ };
+
///
/// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣڶ߳Ҫȷͷš
///
template<class T>
- class LuaxNativeClass
+ class LuaxNativeClass : public virtual ILuaxNativeAccessor
{
public:
+ static bool IsTypeOf(ILuaxNativeAccessor);
+
///
- /// userdataΪkeyref tableuserdataһãάuserdataڡ
+ /// userdataΪkeyref tableuserdataһãάuserdataڡȽmember ref
+ /// ʵᱻαͬʵõƵЩʵ壬luaƵĵgc⡣
///
- template<class U> void LuaRetain(LuaxState& state, U* userdata);
+ template<class U> void LuaxRetain(LuaxState& state, U* userdata);
///
/// userdataһref tableԳԻuserdata
///
- template<class U> void LuaRelease(LuaxState& state, U* userdata);
+ template<class U> void LuaxRelease(LuaxState& state, U* userdata);
- protected:
-
- LuaxNativeClass();
- virtual ~LuaxNativeClass();
+ bool PushLuaxMemberRef(LuaxState& state, int refID) override;
///
/// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջһá
@@ -92,12 +111,17 @@ namespace Luax
bool PushLuaxMemberTable(LuaxState& state);
bool PushLuaxRefTable(LuaxState& state);
+ protected:
+
///
/// Աùʵref tableáȡ
///
- void SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx);
- bool PushMemberRef(LuaxState& state, LuaxMemberRef& memRef);
- void ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef);
+ void SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx);
+ bool PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
+ void ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
+
+ LuaxNativeClass();
+ virtual ~LuaxNativeClass();
private:
@@ -122,14 +146,16 @@ namespace Luax
///
void BindToLua(LuaxState& state);
- //------------------------------------------------------------------------------------------------------------
-
///
- /// LuaxNativeClass<T>͵ʵ
+ /// class table͵С
+ ///
+ static LuaxStrongRef mClassTable;
///
- static LuaxStrongRef mClassTable; // class table͵
- static LuaxStrongRef mSingletonRefTable; // ǵsingletonijԱԱ֤ᱻͨ
- // ref tableijԱȫڵģֱ_LUAX_STRONGREF_TABLE
+ /// ǵsingletonùϵԱ֤ᱻͨref tableijԱȫڵģ
+ /// ֱ_LUAX_STRONGREF_TABLEuserdataLuaxRetain\LuaxReleasemember refʱ͹ʵͬ
+ /// Ǵref tableģtable_LUAX_STRONGREF_TABLE
+ ///
+ static LuaxStrongRef mSingletonRefTable;
///
/// ͨuserdataõ:
@@ -141,16 +167,12 @@ namespace Luax
public:
- //------------------------------------------------------------------------------------------------------------
//
-
LUAX_DECL_METHOD( l___tostring );
LUAX_DECL_METHOD( l_GetClass );
LUAX_DECL_METHOD( l_GetClassName );
- //------------------------------------------------------------------------------------------------------------
//
-
LUAX_DECL_METHOD( l___gc );
#if LUAX_ENABLE_NATIVE_EXTEND
LUAX_DECL_METHOD( l_ExtendFactory );
@@ -158,7 +180,6 @@ namespace Luax
LUAX_DECL_METHOD( l_GetRefTable );
LUAX_DECL_METHOD( l_New );
- //------------------------------------------------------------------------------------------------------------
//
#if LUAX_ENABLE_NATIVE_EXTEND
LUAX_DECL_METHOD( l_ExtendSingleton );
diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl
index 7a24896..e2b8de8 100644
--- a/source/3rd-party/Luax/luax_class.inl
+++ b/source/3rd-party/Luax/luax_class.inl
@@ -87,7 +87,7 @@ namespace Luax
template<typename T>
template<typename U>
- void LuaxNativeClass<T>::LuaRetain(LuaxState& state, U* userdata)
+ void LuaxNativeClass<T>::LuaxRetain(LuaxState& state, U* userdata)
{
if (PushLuaxRefTable(state))
{
@@ -105,7 +105,7 @@ namespace Luax
template<typename T>
template<typename U>
- void LuaxNativeClass<T>::LuaRelease(LuaxState& state, U* userdata)
+ void LuaxNativeClass<T>::LuaxRelease(LuaxState& state, U* userdata)
{
if (PushLuaxRefTable(state))
{
@@ -157,7 +157,7 @@ namespace Luax
}
}
}
- state.SetTop(top);
+ lua_settop(state, top);
lua_pushnil(state);
return false;
}
@@ -250,9 +250,9 @@ namespace Luax
/// Աù
///
template<typename T>
- void LuaxNativeClass<T>::SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx)
+ void LuaxNativeClass<T>::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx)
{
- ClearMemberRef(state, memRef);
+ ClearLuaxMemberRef(state, memRef);
if (!lua_isnil(state, idx))
{
idx = state.AbsIndex(idx);
@@ -266,7 +266,7 @@ namespace Luax
}
template<typename T>
- bool LuaxNativeClass<T>::PushMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ bool LuaxNativeClass<T>::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
{
if (memRef)
{
@@ -285,8 +285,24 @@ namespace Luax
return false;
}
+ template<typename T>
+ bool LuaxNativeClass<T>::PushLuaxMemberRef(LuaxState& state, int refID)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ lua_rawgeti(state, -1, refID);
+ lua_replace(state, -2); // ref table
+ if (lua_isnil(state, -1))
+ goto failed;
+ return true;
+ }
+ lua_pushnil(state);
+ failed:
+ return false;
+ }
+
template<typename T>
- void LuaxNativeClass<T>::ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ void LuaxNativeClass<T>::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
{
if (memRef)
{
diff --git a/source/3rd-party/Luax/luax_ref.h b/source/3rd-party/Luax/luax_ref.h
index b7aabe5..d0001f2 100644
--- a/source/3rd-party/Luax/luax_ref.h
+++ b/source/3rd-party/Luax/luax_ref.h
@@ -14,7 +14,7 @@ namespace Luax
{
public:
- enum
+ enum RefMode
{
STRONG_REF,
WEAK_REF
diff --git a/source/3rd-party/Luax/luax_state.cpp b/source/3rd-party/Luax/luax_state.cpp
index 622f352..8c30c00 100644
--- a/source/3rd-party/Luax/luax_state.cpp
+++ b/source/3rd-party/Luax/luax_state.cpp
@@ -171,6 +171,11 @@ namespace Luax
lua_pushlightuserdata(mState, (void*)value);
}
+ void LuaxState::Push(std::string value)
+ {
+ Push(value.c_str());
+ }
+
void LuaxState::PushValues(int idx, int n)
{
idx = AbsIndex(idx);
diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h
index 564eba3..d675c7c 100644
--- a/source/3rd-party/Luax/luax_state.h
+++ b/source/3rd-party/Luax/luax_state.h
@@ -98,6 +98,7 @@ namespace Luax
void Push(lua_CFunction value);
void Push(void* data, size_t size);
void Push(const void* value);
+ void Push(std::string value);
///
/// idxʼnpushջidxᱻȡn
@@ -210,7 +211,7 @@ namespace Luax
};
//--------------------------------------------------------------------------------------------------------------
- // GetValue()ģʵ
+ // GetValue()ģػ
template <> bool LuaxState::GetValue < bool >(int idx, const bool value);
template <> cc8* LuaxState::GetValue < cc8* >(int idx, const cc8* value);
@@ -228,7 +229,7 @@ namespace Luax
template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value);
//--------------------------------------------------------------------------------------------------------------
- // CheckParamģʵ
+ // CheckParamģػ
template <> bool LuaxState::CheckParam < bool >(int idx);
template <> cc8* LuaxState::CheckParam < cc8* >(int idx);
@@ -254,7 +255,7 @@ namespace Luax
if(!state.CheckParams(1, params)) return 0
#define LUAX_STATE(L) \
- LuaxState& state = LuaxRuntime::Get().GetLuaxState(L)
+ Luax::LuaxState& state = Luax::LuaxRuntime::Get().GetLuaxState(L)
}
diff --git a/source/3rd-party/Luax/luax_state.inl b/source/3rd-party/Luax/luax_state.inl
index 4af45a2..20d132c 100644
--- a/source/3rd-party/Luax/luax_state.inl
+++ b/source/3rd-party/Luax/luax_state.inl
@@ -25,8 +25,7 @@ namespace Luax
assert(IsType(-1, LUA_TFUNCTION)); \
Pop();
- _assertmethod(-1, "New");
- //_assertmethod(-1, "__gc");
+ //_assertmethod(-1, "New");
#undef _assertmethod
@@ -104,6 +103,17 @@ namespace Luax
}
}
+ template<typename T>
+ void LuaxState::SetFieldByIndex(int idx, int key, T value)
+ {
+ if (IsTableOrUserdata(idx))
+ {
+ idx = AbsIndex(idx);
+ this->Push(value);
+ lua_rawseti(mState, idx, key);
+ }
+ }
+
template<typename T>
T LuaxState::GetField(int idx, cc8* key, T value)
{