OrocosComponentLibrary  2.8.3
LuaStateHandle.cpp
1 #include "LuaStateHandle.hpp"
2 
3 namespace OCL
4 {
5 
6  LuaStateHandle::LuaStateHandle()
7  : L(0), m(0)
8  {}
9 
10  LuaStateHandle::LuaStateHandle(lua_State *L, RTT::os::MutexInterface &mutex)
11  : L(L), m(&mutex)
12  {
13  m->lock();
14  }
15 
16  LuaStateHandle::LuaStateHandle(const LuaStateHandle &other)
17  : L(other.L), m(other.m)
18  {
19  // take ownership of the mutex lock
20  other.m = 0;
21  }
22 
23  LuaStateHandle::~LuaStateHandle()
24  {
25  if (m) m->unlock();
26  }
27 
28  LuaStateHandle &LuaStateHandle::operator=(const LuaStateHandle &other)
29  {
30  if (this == &other) return *this;
31  if (m) m->unlock();
32 
33  this->L = other.L;
34  this->m = other.m;
35 
36  // take ownership of the mutex lock
37  other.m = 0;
38 
39  return *this;
40  }
41 
42  lua_State *LuaStateHandle::get() const
43  {
44  return L;
45  }
46 
47 } // namespace OCL
The Orocos Component Library.
Definition: Component.hpp:43