From 8d8c4ff1664625e7428d0d31cd798d9321680cb2 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 14 Mar 2019 09:08:07 +0800 Subject: *luax --- Source/3rdParty/Luax/luax_ref.cpp | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'Source/3rdParty/Luax/luax_ref.cpp') diff --git a/Source/3rdParty/Luax/luax_ref.cpp b/Source/3rdParty/Luax/luax_ref.cpp index e69de29..544861d 100644 --- a/Source/3rdParty/Luax/luax_ref.cpp +++ b/Source/3rdParty/Luax/luax_ref.cpp @@ -0,0 +1,69 @@ +#include "luax_runtime.h" +#include "luax_ref.h" + +namespace Luax +{ + + LuaxRef::LuaxRef(int mode) + : mRefID(LUA_NOREF) + , mMode(mode) + { + } + + LuaxRef::~LuaxRef() + { + } + + LuaxRef::operator bool() + { + return (mRefID != LUA_NOREF); + } + + bool LuaxRef::PushRef(LuaxState& state) + { + assert(mRefID != LUA_NOREF); + + LuaxRuntime& runtime = LuaxRuntime::Get(); + + if (mMode == STRONG_REF) + { + LuaxRefTable& table = runtime[state.GetHandle()].strongRefTable; + table.PushRef(state, mRefID); + } + else if (mMode == WEAK_REF) + { + LuaxRefTable& table = runtime[state.GetHandle()].weakRefTable; + table.PushRef(state, mRefID); + } + else + { + return false; + } + } + + void LuaxRef::SetRef(LuaxState& state, int idx) + { + LuaxRuntime& runtime = LuaxRuntime::Get(); + if (mMode == STRONG_REF) + { + LuaxRefTable& table = runtime[state.GetHandle()].strongRefTable; + mRefID = table.Ref(state, idx); + } + else if (mMode == WEAK_REF) + { + LuaxRefTable& table = runtime[state.GetHandle()].weakRefTable; + mRefID = table.Ref(state, idx); + } + } + + LuaxStrongRef::LuaxStrongRef() + : LuaxRef(STRONG_REF) + { + } + + LuaxWeakRef::LuaxWeakRef() + : LuaxRef(WEAK_REF) + { + } + +} -- cgit v1.1-26-g67d0