HoverRace  2.0
RegistryRef.h
Go to the documentation of this file.
1 
2 // RegistryRef.h
3 //
4 // Copyright (c) 2014, 2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
25 # ifdef MR_ENGINE
26 # define MR_DllDeclare __declspec( dllexport )
27 # else
28 # define MR_DllDeclare __declspec( dllimport )
29 # endif
30 #else
31 # define MR_DllDeclare
32 #endif
33 
34 namespace HoverRace {
35  namespace Script {
36  class Core;
37  }
38 }
39 
40 namespace HoverRace {
41 namespace Script {
42 
51 {
52 public:
53  constexpr RegistryRef(Core &scripting) noexcept :
54  scripting(&scripting), ref(LUA_NOREF) { }
55  RegistryRef(const RegistryRef &o) noexcept;
56  RegistryRef(RegistryRef &&o) noexcept :
57  scripting(o.scripting), ref(o.ref)
58  {
59  o.ref = LUA_NOREF;
60  }
61 
63  {
64  Clear();
65  }
66 
67  RegistryRef &operator=(const RegistryRef &o) noexcept;
69  {
70  scripting = o.scripting;
71  ref = o.ref;
72  o.ref = LUA_NOREF;
73  return *this;
74  }
75 
76  RegistryRef &operator=(const luabind::object &obj)
77  {
78  Set(obj);
79  return *this;
80  }
81 
82  operator bool() const noexcept
83  {
84  return ref != LUA_NOREF && ref != LUA_REFNIL;
85  }
86 
87 public:
88  Core &GetScripting() const noexcept { return *scripting; }
89 
90 public:
91  void Clear() noexcept;
92 
93  void SetFromStack() noexcept;
94  void Set(const luabind::object &obj);
95 
96  void Push() const noexcept;
97 
98 private:
100  int ref;
101 };
102 
103 } // namespace Script
104 } // namespace HoverRace
105 
106 #undef MR_DllDeclare
#define MR_DllDeclare
Definition: RegistryRef.h:31
constexpr RegistryRef(Core &scripting) noexcept
Definition: RegistryRef.h:53
RegistryRef & operator=(RegistryRef &&o) noexcept
Definition: RegistryRef.h:68
Encapsulates a ref to the registry.
Definition: RegistryRef.h:50
Core & GetScripting() const noexcept
Definition: RegistryRef.h:88
RegistryRef & operator=(const luabind::object &obj)
Definition: RegistryRef.h:76
Core * scripting
Definition: RegistryRef.h:99
int ref
Definition: RegistryRef.h:100
Definition: Announcement.h:24
~RegistryRef()
Definition: RegistryRef.h:62
RegistryRef(RegistryRef &&o) noexcept
Definition: RegistryRef.h:56
A script environment.
Definition: Core.h:66