Spinning Topp Logo BlackTopp Studios
inc
lua51scriptargument.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _lua51scriptargument_h
41 #define _lua51scriptargument_h
42 
43 /// @file
44 /// @brief This file has the definition of the Script Arguments for Lua 51
45 
46 #include "datatypes.h"
47 
48 #ifdef MEZZLUA51
49 
51 #include "Scripting/script.h"
53 
54 /// @brief Forward declaration to enable pointer parameters
55 class lua_State;
56 
57 namespace Mezzanine
58 {
59  namespace Scripting
60  {
61  namespace Lua
62  {
63  /// @brief Lua51IntegerArgument returns this value when checking GetTypeData() const.
65  /// @brief Lua51RealArgument returns this value when checking GetTypeData() const.
67  /// @brief Lua51WholeArgument returns this value when checking GetTypeData() const.
69  /// @brief Lua51StringArgument returns this value when checking GetTypeData() const.
71  /// @brief Lua51BoolArgument returns this value when checking GetTypeData() const.
73  /// @brief Lua51NilArgument returns this value when checking GetTypeData() const.
75 
76  /// @brief The ScriptArgumentGeneric<T> needs just a bit of Lua specific functionality so we add push/pop for the LuaScript to call.
78  {
79  public:
80  /// @brief Handle the details of putting this data onto Lua's Stack.
81  /// @param TargetState The state with the stack to push the data onto.
82  /// @return Whatever the Lua return code of the first failing lua call, or the last successful call.
83  virtual void Push(lua_State* TargetState) const = 0;
84 
85  /// @brief Handle the details of pulling data from Lua's Stack into this.
86  /// @param TargetState The state with the stack to pull the data from.
87  /// @return Whatever the Lua return code of the first failing lua call, or the last successful call.
88  virtual void Pop(lua_State* TargetState) = 0;
89 
90  /// @brief Virtual deconstructor
91  virtual ~LuaArgument() {}
92 
93  /// @brief Get a pointer to the most Derived type of this class
94  /// @return A pointer of the most derived pointing to this.
96  { return this; }
97  };
98 
99  /// @brief The implementations in the ScriptArgumentGeneric<Integer> will cover most of what this needs
101  {
102  public:
103 
104  /// @brief Implicit constructor
105  /// @param InitialValue Defaults to 0 and is the actual data to pass into Lua
106  /// @note This is intentionally not explicit. This should make it easier to work with in situations where the creation of this is less important.
107  Lua51IntegerArgument(Integer InitialValue = 0) : ScriptArgumentGeneric<Integer>(InitialValue)
108  {}
109 
110  virtual void Push(lua_State* TargetState) const;
111 
112  virtual void Pop(lua_State* TargetState);
113 
114  /// @brief Virtual deconstructor
116 
117  /// @brief Get a pointer to the most Derived type of this class
118  /// @return A pointer of the most derived pointing to this.
120  { return this; }
121  };
122 
123  /// @brief A Real that can readily be passed into lua scripts
125  : public LuaArgument, public ScriptArgumentGeneric<Real>
126  {
127  public:
128  /// @brief Initializing constructor
129  /// @param InitialValue Deafaults to 0.0
130  Lua51RealArgument(Real InitialValue = 0.0)
131  : ScriptArgumentGeneric<Real>(InitialValue)
132  {}
133 
134  virtual void Push(lua_State* TargetState) const;
135 
136  virtual void Pop(lua_State* TargetState);
137 
138  /// @brief Virtual deconstructor
139  virtual ~Lua51RealArgument() {}
140 
141  /// @brief Get a pointer to the most Derived type of this class
142  /// @return A pointer of the most derived pointing to this.
144  { return this; }
145  };
146 
147  /// @brief No special care is required for Whole number Lua Arguments, so a simple typedef is used.
149  {
150  public:
151  /// @brief Initializing Constructor
152  /// @param InitialValue Defaults to 0.
153  Lua51WholeArgument(Whole InitialValue = 0)
154  : ScriptArgumentGeneric<Whole>(InitialValue)
155  {}
156 
157  virtual void Push(lua_State* TargetState) const;
158 
159  virtual void Pop(lua_State* TargetState);
160 
161  /// @brief Virtual deconstructor
162  virtual ~Lua51WholeArgument() {}
163 
164  /// @brief Get a pointer to the most Derived type of this class
165  /// @return A pointer of the most derived pointing to this.
167  { return this; }
168  };
169 
170  /// @brief No special care is required for String Lua Arguments, so a simple typedef is used.
172  {
173  public:
174  Lua51StringArgument(String InitialValue = String()) : ScriptArgumentGeneric<String>(InitialValue)
175  {}
176 
177  virtual void Push(lua_State* TargetState) const;
178 
179  virtual void Pop(lua_State* TargetState);
180 
181  /// @brief Virtual deconstructor
182  virtual ~Lua51StringArgument() {}
183 
184  /// @brief Get a pointer to the most Derived type of this class
185  /// @return A pointer of the most derived pointing to this.
187  { return this; }
188  };
189 
190  /// @brief No special care is required for Bool Lua Arguments, so a simple typedef is
191  /// used.
193  : public LuaArgument, public ScriptArgumentGeneric<Boole>
194  {
195  public:
196  /// @brief Setting Constructor
197  /// @param InitialValue Defaults to false
198  Lua51BoolArgument(Boole InitialValue = false)
199  : ScriptArgumentGeneric<Boole>(InitialValue)
200  {}
201 
202  virtual void Push(lua_State* TargetState) const;
203 
204  virtual void Pop(lua_State* TargetState);
205 
206  /// @brief Virtual deconstructor
207  virtual ~Lua51BoolArgument() {}
208 
209  /// @brief Get a pointer to the most Derived type of this class
210  /// @return A pointer of the most derived pointing to this.
212  { return this; }
213  };
214 
215  /// @brief Represents not much of anything but will insert and retrieves Nils from Lua51.
216  class MEZZ_LIB Lua51NilArgument : public LuaArgument, public ScriptArgumentGeneric<NullArgument>
217  {
218  public:
220  {}
221 
222  virtual void Push(lua_State* TargetState) const;
223 
224  virtual void Pop(lua_State* TargetState);
225 
226  /// @brief Virtual deconstructor
227  virtual ~Lua51NilArgument() {}
228 
229  /// @brief Get Nil as a String.
230  /// @return The string "Nil"
231  virtual String GetString() const
232  { return "Nil"; }
233 
234  /// @brief Get a pointer to the most Derived type of this class
235  /// @return A pointer of the most derived pointing to this.
237  { return this; }
238  };
239 
240  } // Lua
241  } // Scripting
242 
243  /// @brief Marks LuaArgument for internal reference counting if a CountedPtr checks
244  template <>
245  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::LuaArgument>
246  {
247  public:
248  /// @brief The type that maintains the Reference count for LuaArgument with be LuaArgument itself
250 
251  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
252  /// @param Target A pointer to a Scripting::Lua::LuaArgument that will simply be returned
253  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
254  static RefCountType* ConstructionPointer(RefCountType* Target)
255  { return Target; }
256 
257  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
258  enum { IsCastable = CastDynamic };
259  };
260 
261  /// @brief Marks Lua51IntegerArgument for internal reference counting if a CountedPtr checks
262  template <>
263  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51IntegerArgument>
264  {
265  public:
266  /// @brief The type that maintains the Reference count for Lua51IntegerArgument with be Lua51IntegerArgument itself
268 
269  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
270  /// @param Target A pointer to a Scripting::Lua::Lua51IntegerArgument that will simply be returned
271  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
272  static RefCountType* ConstructionPointer(RefCountType* Target)
273  { return Target; }
274 
275  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
276  enum { IsCastable = CastDynamic };
277  };
278 
279  /// @brief Marks Lua51RealArgument for internal reference counting if a CountedPtr checks
280  template <>
281  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51RealArgument>
282  {
283  public:
284  /// @brief The type that maintains the Reference count for Lua51RealArgument with be Lua51RealArgument itself
286 
287  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
288  /// @param Target A pointer to a Scripting::Lua::Lua51RealArgument that will simply be returned
289  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
290  static RefCountType* ConstructionPointer(RefCountType* Target)
291  { return Target; }
292 
293  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
294  enum { IsCastable = CastDynamic };
295  };
296 
297  /// @brief Marks Lua51WholeArgument for internal reference counting if a CountedPtr checks
298  template <>
299  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51WholeArgument>
300  {
301  public:
302  /// @brief The type that maintains the Reference count for Lua51WholeArgument with be Lua51WholeArgument itself
304 
305  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
306  /// @param Target A pointer to a Scripting::Lua::Lua51WholeArgument that will simply be returned
307  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
308  static RefCountType* ConstructionPointer(RefCountType* Target)
309  { return Target; }
310 
311  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
312  enum { IsCastable = CastDynamic };
313  };
314 
315  /// @brief Marks Lua51StringArgument for internal reference counting if a CountedPtr checks
316  template <>
317  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51StringArgument>
318  {
319  public:
320  /// @brief The type that Lua51StringArgument the Reference count for Lua51StringArgument with be Lua51StringArgument itself
322 
323  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
324  /// @param Target A pointer to a Scripting::Lua::Lua51StringArgument that will simply be returned
325  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
326  static RefCountType* ConstructionPointer(RefCountType* Target)
327  { return Target; }
328 
329  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
330  enum { IsCastable = CastDynamic };
331  };
332 
333  /// @brief Marks Lua51BoolArgument for internal reference counting if a CountedPtr checks
334  template <>
335  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51BoolArgument>
336  {
337  public:
338  /// @brief The type that maintains the Reference count for Lua51BoolArgument with be Lua51BoolArgument itself
340 
341  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
342  /// @param Target A pointer to a Scripting::Lua::Lua51BoolArgument that will simply be returned
343  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
344  static RefCountType* ConstructionPointer(RefCountType* Target)
345  { return Target; }
346 
347  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
348  enum { IsCastable = CastDynamic };
349  };
350 
351  /// @brief Marks Lua51NilArgument for internal reference counting if a CountedPtr checks
352  template <>
353  class MEZZ_LIB ReferenceCountTraits <Scripting::Lua::Lua51NilArgument>
354  {
355  public:
356  /// @brief The type that maintains the Reference count for Lua51NilArgument with be Lua51NilArgument itself
358 
359  /// @brief Given a pointer to the raw object this will return a pointer to an initialized reference count
360  /// @param Target A pointer to a Scripting::Lua::Lua51NilArgument that will simply be returned
361  /// @return This returns whatever was passed into target because it already is a valid Reference Counter
362  static RefCountType* ConstructionPointer(RefCountType* Target)
363  { return Target; }
364 
365  /// @brief This uses dynamic casting when resolving casts inside the CountedPtr
366  enum { IsCastable = CastDynamic };
367  };
368 
369 
370 
371 } // Mezzanine
372 
373 
374 #endif // MEZZLUA51
375 #endif // \_scriptinglua_h
virtual Lua51IntegerArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
const Integer LuaReal
Lua51RealArgument returns this value when checking GetTypeData() const.
Returned from GetTypeData() const when a ScriptArgumentGeneric is specialized as an Integer...
Scripting::Lua::Lua51WholeArgument RefCountType
The type that maintains the Reference count for Lua51WholeArgument with be Lua51WholeArgument itself...
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual Lua51StringArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
Returned from GetTypeData() const when a ScriptArgumentGeneric is specialized as an Bool...
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
All the definitions for datatypes as well as some basic conversion functions are defined here...
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Returned from GetTypeData() const when a ScriptArgumentGeneric is specialized as an Real...
This file has the interfaces for Scripts and tag derived classes.
Returned from GetTypeData() const when a ScriptArgumentGeneric is intended as NullPtr, SQL Null, Lua Nil, Ruby nil, etc...
virtual Lua51BoolArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
Scripting::Lua::Lua51NilArgument RefCountType
The type that maintains the Reference count for Lua51NilArgument with be Lua51NilArgument itself...
Scripting::Lua::Lua51StringArgument RefCountType
The type that Lua51StringArgument the Reference count for Lua51StringArgument with be Lua51StringArgu...
No special care is required for Whole number Lua Arguments, so a simple typedef is used...
virtual ~Lua51StringArgument()
Virtual deconstructor.
virtual ~LuaArgument()
Virtual deconstructor.
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
A dynamic cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:64
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
virtual String GetString() const
Get Nil as a String.
Lua51BoolArgument(Boole InitialValue=false)
Setting Constructor.
Scripting::Lua::LuaArgument RefCountType
The type that maintains the Reference count for LuaArgument with be LuaArgument itself.
Lua51RealArgument(Real InitialValue=0.0)
Initializing constructor.
virtual ~Lua51IntegerArgument()
Virtual deconstructor.
const Integer LuaWhole
Lua51WholeArgument returns this value when checking GetTypeData() const.
No special care is required for String Lua Arguments, so a simple typedef is used.
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
Definition: countedptr.h:87
Returned from GetTypeData() const when a ScriptArgumentGeneric is specialized as an String...
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
The implementations in the ScriptArgumentGeneric will cover most of what this needs...
virtual ~Lua51BoolArgument()
Virtual deconstructor.
Returned from GetTypeData() const when a ScriptArgumentGeneric is specialized as an Whole...
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
A String implementation of a ScriptArgument that is suitable for primitive types in most situations...
const Integer LuaString
Lua51StringArgument returns this value when checking GetTypeData() const.
const Integer LuaInteger
Lua51IntegerArgument returns this value when checking GetTypeData() const.
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...
Lua51IntegerArgument(Integer InitialValue=0)
Implicit constructor.
virtual ~Lua51WholeArgument()
Virtual deconstructor.
The ScriptArgumentGeneric needs just a bit of Lua specific functionality so we add push/pop for th...
virtual Lua51RealArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
This file has the interfaces for Script Arguments and the associated dependency chain.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
No special care is required for Bool Lua Arguments, so a simple typedef is used.
Scripting::Lua::Lua51RealArgument RefCountType
The type that maintains the Reference count for Lua51RealArgument with be Lua51RealArgument itself...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
virtual LuaArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
A generic implementation of a ScriptArgument that is suitable for primitive types in most situations...
const Integer LuaBool
Lua51BoolArgument returns this value when checking GetTypeData() const.
virtual Lua51WholeArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
virtual ~Lua51RealArgument()
Virtual deconstructor.
Lua51WholeArgument(Whole InitialValue=0)
Initializing Constructor.
virtual ~Lua51NilArgument()
Virtual deconstructor.
const Integer LuaNil
Lua51NilArgument returns this value when checking GetTypeData() const.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
A Real that can readily be passed into lua scripts.
virtual Lua51NilArgument * GetMostDerived()
Get a pointer to the most Derived type of this class.
Represents not much of anything but will insert and retrieves Nils from Lua51.
Scripting::Lua::Lua51BoolArgument RefCountType
The type that maintains the Reference count for Lua51BoolArgument with be Lua51BoolArgument itself...
Scripting::Lua::Lua51IntegerArgument RefCountType
The type that maintains the Reference count for Lua51IntegerArgument with be Lua51IntegerArgument its...
This file has the interfaces for Scripting managers and the associated dependency chain...
static RefCountType * ConstructionPointer(RefCountType *Target)
Given a pointer to the raw object this will return a pointer to an initialized reference count...