diff options
Diffstat (limited to 'source/3rd-party/Luax/luax_runtime.cpp')
| -rw-r--r-- | source/3rd-party/Luax/luax_runtime.cpp | 89 | 
1 files changed, 89 insertions, 0 deletions
diff --git a/source/3rd-party/Luax/luax_runtime.cpp b/source/3rd-party/Luax/luax_runtime.cpp new file mode 100644 index 0000000..b45d36a --- /dev/null +++ b/source/3rd-party/Luax/luax_runtime.cpp @@ -0,0 +1,89 @@ +#ifndef __LUAX_RUNTIME_H_ +#define __LUAX_RUNTIME_H_ + +#include "luax_runtime.h" + +using namespace std; + +namespace Luax +{ + +	LuaxRuntime* LuaxRuntime::mRuntime = nullptr; + +	LuaxRuntime::LuaxRuntime() {}; +	LuaxRuntime::~LuaxRuntime() {}; + +	LuaxRuntime& LuaxRuntime::Get() +	{ +		if (mRuntime == nullptr) +			mRuntime = new LuaxRuntime(); + +		return *mRuntime; +	} + +	lua_State* LuaxRuntime::Open() +	{ +		lua_State* L = lua_open(); +		assert(L); + +		// 1)  +		mContexts.insert(pair<lua_State*, LuaxContext>(L, LuaxContext(L))); +		// 2) ʼcontext +		(*this)[L].Setup(); + +		return L; +	} + +	void LuaxRuntime::Close(lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		if (it != mContexts.end()) +		{ +			lua_close(it->second.state); +			mContexts.erase(it); +		} +	} + +	bool LuaxRuntime::HasLuaxState(lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		return it != mContexts.end(); +	} + +	LuaxState& LuaxRuntime::GetLuaxState(lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		if (it != mContexts.end()) +		{ +			return it->second.state; +		} +	} + +	LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		if (it != mContexts.end()) +		{ +			return it->second.strongRefTable; +		} +	} + +	LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		if (it != mContexts.end()) +		{ +			return it->second.weakRefTable; +		} +	} + +	LuaxContext& LuaxRuntime::operator[](lua_State* L) +	{ +		map<lua_State*, LuaxContext>::iterator it = mContexts.find(L); +		assert(it != mContexts.end()); +		return it->second; +	} + +} + +#endif
\ No newline at end of file  | 
