diff options
Diffstat (limited to 'Runtime/Scripting/LuaBindRef.cpp')
-rw-r--r-- | Runtime/Scripting/LuaBindRef.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Runtime/Scripting/LuaBindRef.cpp b/Runtime/Scripting/LuaBindRef.cpp new file mode 100644 index 0000000..f6ff8a1 --- /dev/null +++ b/Runtime/Scripting/LuaBindRef.cpp @@ -0,0 +1,72 @@ +#include "LuaBindVM.h" +#include "LuaBindRef.h" + +namespace LuaBind +{ + + LuaBindRef::LuaBindRef(int mode) + : mRefID(LUA_NOREF) + , mMode(mode) + { + } + + LuaBindRef::~LuaBindRef() + { + } + + LuaBindRef::operator bool() + { + return (mRefID != LUA_NOREF); + } + + bool LuaBindRef::PushRef(LuaBindState& state) + { + assert(mRefID != LUA_NOREF); + + LuaBindVM* vm = state.GetVM(); + if (!vm) return false; + if (mMode == STRONG_REF) + { + LuaBindRefTable& table = vm->GetStrongRefTable(); + table.PushRef(state, mRefID); + } + else if (mMode == WEAK_REF) + { + LuaBindRefTable& table = vm->GetWeakRefTable(); + table.PushRef(state, mRefID); + } + else + { + state.PushNil(); + return false; + } + return true; + } + + void LuaBindRef::SetRef(LuaBindState& state, int idx) + { + LuaBindVM* vm = state.GetVM(); + if (!vm) return; + if (mMode == STRONG_REF) + { + LuaBindRefTable& table = vm->GetStrongRefTable(); + mRefID = table.Ref(state, idx); + } + else if (mMode == WEAK_REF) + { + LuaBindRefTable& table = vm->GetWeakRefTable(); + mRefID = table.Ref(state, idx); + } + } + + LuaBindStrongRef::LuaBindStrongRef() + : LuaBindRef(STRONG_REF) + { + } + + LuaBindWeakRef::LuaBindWeakRef() + : LuaBindRef(WEAK_REF) + { + } + +} |