1 //------------------------------------------------------------------------------
3 https://github.com/vinniefalco/LuaBridge
5 Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
6 Copyright 2007, Nathan Reed
8 License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 This file incorporates work covered by the following copyright and
32 Copyright (c) 2001 by Andrei Alexandrescu
33 This code accompanies the book:
34 Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
35 Patterns Applied". Copyright (c) 2001. Addison-Wesley.
36 Permission to use, copy, modify, distribute and sell this software for any
37 purpose is hereby granted without fee, provided that the above copyright
38 notice appear in all copies and that both that copyright notice and this
39 permission notice appear in supporting documentation.
40 The author or Addison-Welsey Longman make no representations about the
41 suitability of this software for any purpose. It is provided "as is"
42 without express or implied warranty.
44 //==============================================================================
47 None type means void parameters or return value.
51 template <typename Head, typename Tail = None>
57 A TypeList with actual values.
59 template <typename List>
62 static std::string const tostring (bool)
69 TypeListValues recursive template definition.
71 template <typename Head, typename Tail>
72 struct TypeListValues <TypeList <Head, Tail> >
75 TypeListValues <Tail> tl;
77 TypeListValues (Head hd_, TypeListValues <Tail> const& tl_)
82 static std::string const tostring (bool comma = false)
89 s = s + typeid (Head).name ();
91 return s + TypeListValues <Tail>::tostring (true);
95 // Specializations of type/value list for head types that are references and
96 // const-references. We need to handle these specially since we can't count
97 // on the referenced object hanging around for the lifetime of the list.
99 template <typename Head, typename Tail>
100 struct TypeListValues <TypeList <Head&, Tail> >
103 TypeListValues <Tail> tl;
105 TypeListValues (Head& hd_, TypeListValues <Tail> const& tl_)
110 static std::string const tostring (bool comma = false)
117 s = s + typeid (Head).name () + "&";
119 return s + TypeListValues <Tail>::tostring (true);
123 template <typename Head, typename Tail>
124 struct TypeListValues <TypeList <Head const&, Tail> >
127 TypeListValues <Tail> tl;
129 TypeListValues (Head const& hd_, const TypeListValues <Tail>& tl_)
134 static std::string const tostring (bool comma = false)
141 s = s + typeid (Head).name () + " const&";
143 return s + TypeListValues <Tail>::tostring (true);
147 //==============================================================================
149 Subclass of a TypeListValues constructable from the Lua stack.
152 template <typename List, int Start = 1>
158 struct ArgList <None, Start> : public TypeListValues <None>
165 template <typename Head, typename Tail, int Start>
166 struct ArgList <TypeList <Head, Tail>, Start>
167 : public TypeListValues <TypeList <Head, Tail> >
169 ArgList (lua_State* L)
170 : TypeListValues <TypeList <Head, Tail> > (Stack <Head>::get (L, Start),
171 ArgList <Tail, Start + 1> (L))