Move a forward declaration (for class ArdourVSpacer) so that MSVC can also use it
[ardour.git] / libs / lua / LuaBridge / LuaBridge.h
1 //------------------------------------------------------------------------------
2 /*
3   https://github.com/vinniefalco/LuaBridge
4
5   Copyright 2016, Robin Gareus <robin@gareus.org>
6   Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
7   Copyright 2007, Nathan Reed
8
9   License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
10
11   Permission is hereby granted, free of charge, to any person obtaining a copy
12   of this software and associated documentation files (the "Software"), to deal
13   in the Software without restriction, including without limitation the rights
14   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15   copies of the Software, and to permit persons to whom the Software is
16   furnished to do so, subject to the following conditions:
17
18   The above copyright notice and this permission notice shall be included in all
19   copies or substantial portions of the Software.
20
21   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27   SOFTWARE.
28 */
29 //==============================================================================
30
31 #ifndef LUABRIDGE_LUABRIDGE_HEADER
32 #define LUABRIDGE_LUABRIDGE_HEADER
33
34 // All #include dependencies are listed here
35 // instead of in the individual header files.
36 //
37 #include <cassert>
38 #include <sstream>
39 #include <stdexcept>
40 #include <string>
41 #include <typeinfo>
42
43 #include <bitset>
44 #include <list>
45 #include <map>
46 #include <set>
47 #include <vector>
48
49 #include <inttypes.h>
50 #include <boost/type_traits.hpp>
51 #include <boost/shared_ptr.hpp>
52
53 #include "lua/luastate.h"
54
55 #define LUABRIDGE_MAJOR_VERSION 2
56 #define LUABRIDGE_MINOR_VERSION 0
57 #define LUABRIDGE_VERSION 200
58
59 namespace luabridge
60 {
61
62 // Forward declaration
63 //
64 template <class T>
65 struct Stack;
66
67 #include "detail/LuaHelpers.h"
68
69 #include "detail/TypeTraits.h"
70 #include "detail/TypeList.h"
71 #include "detail/FuncTraits.h"
72 #include "detail/Constructor.h"
73 #include "detail/Stack.h"
74 #include "detail/ClassInfo.h"
75
76 class LuaRef;
77
78 #include "detail/LuaException.h"
79 #include "detail/LuaRef.h"
80 #include "detail/Iterator.h"
81 #include "detail/FuncArgs.h"
82
83 //------------------------------------------------------------------------------
84 /**
85     security options.
86 */
87 class Security
88 {
89 public:
90   static bool hideMetatables ()
91   {
92     return getSettings().hideMetatables;
93   }
94
95   static void setHideMetatables (bool shouldHide)
96   {
97     getSettings().hideMetatables = shouldHide;
98   }
99
100 private:
101   struct Settings
102   {
103     Settings () : hideMetatables (true)
104     {
105     }
106
107     bool hideMetatables;
108   };
109
110   static Settings& getSettings ()
111   {
112     static Settings settings;
113     return settings;
114   }
115 };
116
117 //------------------------------------------------------------------------------
118
119 #ifdef LUABINDINGDOC
120 class LuaBindingDoc
121 {
122 public:
123         static bool printBindings ()
124         {
125                 return getSettings().print_bindings;
126         }
127
128         static void setPrintBindings (bool en)
129         {
130                 getSettings().print_bindings = en;
131         }
132
133 private:
134         struct Settings
135         {
136                 Settings () : print_bindings (false) { }
137                 bool print_bindings;
138         };
139
140         static Settings& getSettings ()
141         {
142                 static Settings settings;
143                 return settings;
144         }
145 };
146 #endif
147
148 //------------------------------------------------------------------------------
149
150
151 #include "detail/Userdata.h"
152 #include "detail/CFunctions.h"
153 #include "detail/Namespace.h"
154
155 //------------------------------------------------------------------------------
156 /**
157     Push an object onto the Lua stack.
158 */
159 template <class T>
160 inline void push (lua_State* L, T t)
161 {
162   Stack <T>::push (L, t);
163 }
164
165 //------------------------------------------------------------------------------
166 /**
167   Set a global value in the lua_State.
168
169   @note This works on any type specialized by `Stack`, including `LuaRef` and
170         its table proxies.
171 */
172 template <class T>
173 inline void setGlobal (lua_State* L, T t, char const* name)
174 {
175   push (L, t);
176   lua_setglobal (L, name);
177 }
178
179 //------------------------------------------------------------------------------
180 /**
181   Change whether or not metatables are hidden (on by default).
182 */
183 inline void setHideMetatables (bool shouldHide)
184 {
185   Security::setHideMetatables (shouldHide);
186 }
187
188 #ifdef LUABINDINGDOC
189 inline void setPrintBindings (bool en)
190 {
191   LuaBindingDoc::setPrintBindings (en);
192 }
193 #endif
194
195 } // end Namespace
196
197 #endif