ChaiScript / ChaiScript
1
// This file is distributed under the BSD License.
2
// See "license.txt" for details.
3
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4
// Copyright 2009-2018, Jason Turner (jason@emptycrate.com)
5
// http://www.chaiscript.com
6

7
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
8
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9

10

11
#ifndef CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_
12
#define CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_
13

14
#include "proxy_functions.hpp"
15

16
namespace chaiscript
17
{
18
  namespace dispatch
19
  {
20
    namespace detail
21
    {
22
      template<typename Class, typename ... Params  >
23 1
        Proxy_Function build_constructor_(Class (*)(Params...))
24
        {
25
          auto call = [](auto && ... param){
26
            return Class(std::forward<decltype(param)>(param)...);
27
          };
28

29
          return Proxy_Function(
30 1
            chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Callable_Impl<Class (Params...), decltype(call)>>(call));
31
        }
32
    }
33
  }
34

35

36
  /// \brief Generates a constructor function for use with ChaiScript
37
  /// 
38
  /// \tparam T The signature of the constructor to generate. In the form of: ClassType (ParamType1, ParamType2, ...)
39
  /// 
40
  /// Example:
41
  /// \code
42
  ///    chaiscript::ChaiScript chai;
43
  ///    // Create a new function that creates a MyClass object using the (int, float) constructor
44
  ///    // and call that function "MyClass" so that it appears as a normal constructor to the user.
45
  ///    chai.add(constructor<MyClass (int, float)>(), "MyClass");
46
  /// \endcode
47
  template<typename T>
48 1
    Proxy_Function constructor()
49
    {
50 1
      T *f = nullptr;
51 1
      return (dispatch::detail::build_constructor_(f));
52
    }
53

54
}
55

56
#endif
57

Read our documentation on viewing source code .

Loading