diff options
Diffstat (limited to 'source/3rd-party/Luax')
| -rw-r--r-- | source/3rd-party/Luax/luax_class.hpp | 25 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_class.inl | 8 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_config.h | 2 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_enum.cpp | 2 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_enum.h | 2 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_state.cpp | 122 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_state.h | 33 | ||||
| -rw-r--r-- | source/3rd-party/Luax/luax_state.inl | 31 | 
8 files changed, 197 insertions, 28 deletions
| diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index ea1fab9..539ff1a 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -35,15 +35,32 @@ namespace Luax  	static const char* GetLuaxClassName() { return #type; }; \  	static bool IsLuaxClassSingleton() { return true; }; +	/// +	/// ʵֵĺꡣһL +	///  #define LUAX_IMPL_METHOD(type, f) int type::f(lua_State* L) +	/// +	/// Ӧóʵֵӿڡһstate +	///  #define LUAX_REGISTRY(type) void type::RegisterLuaxClass(Luax::LuaxState& state) -  #define LUAX_POSTPROCESS(type) void type::RegisterLuaxPostprocess(Luax::LuaxState& state) -#define LUAX_REGISTER_FACTORY(stt, type) stt.RegisterFactory<type>() - -#define LUAX_REGISTER_SINGLETON(stt, type) stt.RegisterSingleton<type>() +	/// +	/// עĺꡣ +	/// +#define LUAX_REGISTER_FACTORY(state, type) state.RegisterFactory<type>() +#define LUAX_REGISTER_SINGLETON(state, type) state.RegisterSingleton<type>() +#define LUAX_REGISTER_METHODS(state, ...) \ +	do{ \ +	luaL_Reg __m[] = {__VA_ARGS__,{0, 0}}; \ +	state.RegisterMethods(__m); \ +	}while(0) +#define LUAX_REGISTER_ENUM(state, name, ...) \ +	do{ \ +	Luax::LuaxEnum __e[] = {__VA_ARGS__,{0, 0}}; \ +	state.RegisterEnum(name, __e); \ +	}while(0)  	///  	/// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣڶ߳Ҫȷͷš diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl index 028d4f9..7a24896 100644 --- a/source/3rd-party/Luax/luax_class.inl +++ b/source/3rd-party/Luax/luax_class.inl @@ -206,7 +206,7 @@ namespace Luax  		assert(!mUserdata);  		// userdataջ -		state.PushPtrUserData(this); +		state.PushPtrUserdata(this);  		lua_newtable(state); // ref tableluaʣC  		lua_newtable(state); // member tableluaдĶԱ @@ -308,7 +308,7 @@ namespace Luax  	int LuaxNativeClass<T>::l___gc(lua_State* L)  	{  		LUAX_SETUP(L, "U"); -		T* self = state.GetLuaUserdata<T>(1); +		T* self = state.GetUserdata<T>(1);  		delete self;  		return 0;  	} @@ -324,7 +324,7 @@ namespace Luax  		// 1: userdata  		LUAX_STATE(L); -		T* self = state.GetLuaUserdata<T>(1); +		T* self = state.GetUserdata<T>(1);  		if (self)  		{  			cc8* classname = ""; @@ -464,7 +464,7 @@ namespace Luax  	int LuaxNativeClass<T>::l_GetRefTable(lua_State* L)  	{  		LUAX_STATE(L); -		T* self = state.GetLuaUserdata<T>(1); +		T* self = state.GetUserdata<T>(1);  		bool success = self->PushLuaxRefTable(state);  		if (!success)  			lua_pushnil(L); diff --git a/source/3rd-party/Luax/luax_config.h b/source/3rd-party/Luax/luax_config.h index c6562cc..d95ae8b 100644 --- a/source/3rd-party/Luax/luax_config.h +++ b/source/3rd-party/Luax/luax_config.h @@ -53,7 +53,7 @@ namespace Luax  #define LUAX_ENABLE_NATIVE_EXTEND 0  #define LUAX_ENABLE_PLAIN_CLASS 1 -#define LUAX_ENABLE_PLAIN_ENABLE 1 +#define LUAX_ENABLE_PLAIN_ENUM 1  } diff --git a/source/3rd-party/Luax/luax_enum.cpp b/source/3rd-party/Luax/luax_enum.cpp index 88bbab4..b054d98 100644 --- a/source/3rd-party/Luax/luax_enum.cpp +++ b/source/3rd-party/Luax/luax_enum.cpp @@ -35,7 +35,7 @@ namespace Luax  	}  	//-------------------------------------------------------------------------------------------------------------- -#if LUAX_ENABLE_PLAIN_ENABLE +#if LUAX_ENABLE_PLAIN_ENUM  	int LuaxPlainEnum::registry(lua_State* L)  	{  		// params: diff --git a/source/3rd-party/Luax/luax_enum.h b/source/3rd-party/Luax/luax_enum.h index 36f6bab..c385dc5 100644 --- a/source/3rd-party/Luax/luax_enum.h +++ b/source/3rd-party/Luax/luax_enum.h @@ -20,7 +20,7 @@ namespace Luax  	extern int l_rmt__newindex(lua_State* L);  	//-------------------------------------------------------------------------------------------------------------- -#if LUAX_ENABLE_PLAIN_ENABLE +#if LUAX_ENABLE_PLAIN_ENUM  	///  	/// luaö٣ĵtable  	/// diff --git a/source/3rd-party/Luax/luax_state.cpp b/source/3rd-party/Luax/luax_state.cpp index 881aaea..622f352 100644 --- a/source/3rd-party/Luax/luax_state.cpp +++ b/source/3rd-party/Luax/luax_state.cpp @@ -596,15 +596,6 @@ namespace Luax  		return value;  	} -	template<>  -	int LuaxState::GetValue<int>(int idx, int value) -	{ -		if (this->IsType(idx, LUA_TNUMBER)) { -			return (int)lua_tointeger(this->mState, idx); -		} -		return value; -	} -	  	template <>  	u16 LuaxState::GetValue < u16 >(int idx, const u16 value)  	{ @@ -641,7 +632,7 @@ namespace Luax  		return value;  	} -	void LuaxState::PushPtrUserData(void* ptr) { +	void LuaxState::PushPtrUserdata(void* ptr) {  		void** handle = (void**)lua_newuserdata(this->mState, sizeof(void*));  		assert(handle); @@ -725,7 +716,7 @@ namespace Luax  	}  #endif -#if LUAX_ENABLE_PLAIN_ENABLE +#if LUAX_ENABLE_PLAIN_ENUM  	void LuaxState::RegisterPlainEnumRegistry(cc8* name)  	{  		assert(lua_istable(mState, -1)); @@ -734,4 +725,113 @@ namespace Luax  	}  #endif +	int LuaxState::ErrorType(int idx, cc8* hint) +	{ +		return luaL_typerror(mState, idx, hint); +	} + +	template <>  +	bool LuaxState::CheckParam < bool >(int idx) +	{ +		bool b = false; +		if (lua_type(mState, idx) == LUA_TBOOLEAN) +		{ +			b = lua_toboolean(mState, idx); +		} +		else +		{ +			luaL_typerror(mState, idx, lua_typename(mState, LUA_TBOOLEAN)); +		} +		return b; +	} + +	template <>  +	cc8* LuaxState::CheckParam < cc8* >(int idx) +	{ +		return luaL_checkstring(mState, idx); +	} + +	template <>  +	double LuaxState::CheckParam < double >(int idx) +	{ +		return luaL_checknumber(mState, idx); +	} + +	template <>  +	float LuaxState::CheckParam < float >(int idx) +	{ +		return luaL_checknumber(mState, idx); +	} + +	template <>  +	s8 LuaxState::CheckParam < s8 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	s16 LuaxState::CheckParam < s16 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	s32 LuaxState::CheckParam < s32 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	s64 LuaxState::CheckParam < s64 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	u8 LuaxState::CheckParam < u8 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	u16 LuaxState::CheckParam < u16 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	u32 LuaxState::CheckParam < u32 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	u64	 LuaxState::CheckParam < u64 >(int idx) +	{ +		return luaL_checkinteger(mState, idx); +	} + +	template <>  +	std::string LuaxState::CheckParam < std::string >(int idx) +	{ +		return luaL_checkstring(mState, idx); +	} + +	/// +	/// check light userdata +	/// +	template <> +	const void* LuaxState::CheckParam < const void* >(int idx) +	{ +		if (IsType(idx, LUA_TLIGHTUSERDATA)) +		{ +			return GetValue<const void*>(idx, nullptr); +		} +		else +		{ +			luaL_typerror(mState, idx, "light userdata"); +			return nullptr; +		} +	} +  }
\ No newline at end of file diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h index fbe424b..564eba3 100644 --- a/source/3rd-party/Luax/luax_state.h +++ b/source/3rd-party/Luax/luax_state.h @@ -107,13 +107,17 @@ namespace Luax  		///  		/// void** ʽuserdataֵΪptr  		/// -		void PushPtrUserData(void* ptr); +		void PushPtrUserdata(void* ptr);  		void Pop(int n = 1);  		void Settop(int idx); -		template<typename T> T* GetLuaUserdata(int idx = 1); +		template<typename T> T* GetUserdata(int idx = 1); + +		//------------------------------------------------------------------------------------------------------------ + +		int ErrorType(int idx, cc8* hint);  		//------------------------------------------------------------------------------------------------------------ @@ -123,6 +127,9 @@ namespace Luax  		template<typename T> void SetField(int idx, cc8* key, T value);  		template<typename T> void SetFieldByIndex(int idx, int key, T value); +		template<typename T> T* CheckUserdata(int idx); +		template<typename T> T CheckParam(int idx); +  		//------------------------------------------------------------------------------------------------------------  		void DoString(const std::string& code); @@ -175,7 +182,7 @@ namespace Luax  		void RegisterPlainClassRegistry(cc8* name);  #endif -#if LUAX_ENABLE_PLAIN_ENABLE +#if LUAX_ENABLE_PLAIN_ENUM  		///  		/// עᴿluaö٣Էֹöֵ  		/// @@ -203,7 +210,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); @@ -219,8 +226,24 @@ namespace Luax  	template <> u64	 LuaxState::GetValue < u64 >(int idx, const u64 value);  	template <> std::string LuaxState::GetValue < std::string >(int idx, const std::string value);  	template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value); -	template <> int LuaxState::GetValue < int >(int idx, int value); +	//-------------------------------------------------------------------------------------------------------------- +	// CheckParamģʵ + +	template <> bool LuaxState::CheckParam < bool >(int idx); +	template <> cc8* LuaxState::CheckParam < cc8* >(int idx); +	template <> double LuaxState::CheckParam < double >(int idx); +	template <> float LuaxState::CheckParam < float >(int idx); +	template <> s8 LuaxState::CheckParam < s8 >(int idx); +	template <> s16 LuaxState::CheckParam < s16 >(int idx); +	template <> s32 LuaxState::CheckParam < s32 >(int idx); +	template <> s64 LuaxState::CheckParam < s64 >(int idx); +	template <> u8 LuaxState::CheckParam < u8 >(int idx); +	template <> u16 LuaxState::CheckParam < u16 >(int idx); +	template <> u32 LuaxState::CheckParam < u32 >(int idx); +	template <> u64	 LuaxState::CheckParam < u64 >(int idx); +	template <> std::string LuaxState::CheckParam < std::string >(int idx); +	template <> const void* LuaxState::CheckParam < const void* >(int idx);  	///  	/// ڳԱﴴLuaxStateԲм顣 diff --git a/source/3rd-party/Luax/luax_state.inl b/source/3rd-party/Luax/luax_state.inl index 06d9350..4af45a2 100644 --- a/source/3rd-party/Luax/luax_state.inl +++ b/source/3rd-party/Luax/luax_state.inl @@ -125,7 +125,7 @@ namespace Luax  	}  	template<typename T> -	T* LuaxState::GetLuaUserdata(int idx) +	T* LuaxState::GetUserdata(int idx)  	{  		void* p = nullptr; @@ -137,4 +137,33 @@ namespace Luax  		return static_cast<T*>(p);  	} +	template<typename T>  +	T* LuaxState::CheckUserdata(int idx) +	{ +		if (IsType(idx, LUA_TUSERDATA)) +		{ +			if (lua_getmetatable(mState, idx)) // ref table  +			{ +				if (lua_getmetatable(mState, -1)) // member table  +				{ +					if (lua_getmetatable(mState, -1)) // class table  +					{ +						T::PushLuaxClassTable(*this); // target class table +						if (lua_rawequal(mState, -1, -2)) +						{ +							Pop(4); // ref\member\class\target class +							T* udata = GetUserdata<T>(idx); +							return udata; // userdata +						} +						Pop(2); // target class table\class table +					} +					Pop(1); // member table  +				} +				Pop(1); // ref table +			} +		} +		luaL_typerror(mState, idx, T::GetLuaxClassName()); +		return nullptr; +	} +  }
\ No newline at end of file | 
