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; };
+
+ };
+
///
/// ÐèÒª±©Â¶¸øluaµÄnative classÐèÒª¼Ì³Ð´ËÀࡣͨ¹ýlua¹ÜÀíµÄʵÀýҪȷ±£ÒýÓüÆÊýµÄÕýÈ·ÐÔ£¬ÔÚ¶à¸öÏß³ÌÖÐÐèҪȷ¶¨²»»áÎóÊÍ·Å¡£
///
template<class T>
- class LuaxNativeClass
+ class LuaxNativeClass : public virtual ILuaxNativeAccessor
{
public:
+ static bool IsTypeOf(ILuaxNativeAccessor);
+
///
- /// ½«userdata×÷Ϊkey£¬ÔÚref tableÀï¶ÔuserdataÌí¼ÓÒ»¸öÒýÓã¬ÒÔά³ÖuserdataµÄÉúÃüÖÜÆÚ¡£
+ /// ½«userdata×÷Ϊkey£¬ÔÚref tableÀï¶ÔuserdataÌí¼ÓÒ»¸öÒýÓã¬ÒÔά³Ö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; // Èç¹ûÀàÊǵ¥Àý£¬Õâ¸öÓÃÀ´±£´æsingletonµÄ³ÉÔ±£¬ÒÔ±£Ö¤²»»á±»»ØÊÕÀàËÆÆÕͨÀàµÄ
- // ref table¡£µ¥ÀýµÄ³ÉÔ±ÊÇÈ«ÉúÃüÖÜÆÚµÄ£¬ËùÒÔÖ±½ÓÔÚ_LUAX_STRONGREF_TABLE
+ /// Èç¹ûÀàÊǵ¥Àý£¬Õâ¸öÓÃÀ´±£´æsingletonµÄÒýÓùØÏµ£¬ÒÔ±£Ö¤²»»á±»»ØÊÕÀàËÆÆÕͨÀàµÄref table¡£µ¥ÀýµÄ³ÉÔ±ÊÇÈ«ÉúÃüÖÜÆÚµÄ£¬
+ /// ËùÒÔÖ±½ÓÔÚ_LUAX_STRONGREF_TABLE¡£µ¥Àý¶Ôuserdata½øÐÐLuaxRetain\LuaxReleaseºÍmember 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¿ªÊ¼µÄn¸öpushµ½Õ»¶¥£¬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)
{