GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
register_function.hpp
Go to the documentation of this file.
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-2017, 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_REGISTER_FUNCTION_HPP_
12#define CHAISCRIPT_REGISTER_FUNCTION_HPP_
13
14#include <type_traits>
15
16#include "bind_first.hpp"
17#include "proxy_functions.hpp"
18
19namespace chaiscript
20{
21
42 template<typename T>
50
51
52 template<typename Ret, typename ... Param>
53 Proxy_Function fun(Ret (*func)(Param...))
54 {
55 auto fun_call = dispatch::detail::Fun_Caller<Ret, Param...>(func);
56
57 return Proxy_Function(
59
60 }
61
62 template<typename Ret, typename Class, typename ... Param>
63 Proxy_Function fun(Ret (Class::*t_func)(Param...) const)
64 {
65 auto call = dispatch::detail::Const_Caller<Ret, Class, Param...>(t_func);
66
67 return Proxy_Function(
69 }
70
71 template<typename Ret, typename Class, typename ... Param>
72 Proxy_Function fun(Ret (Class::*t_func)(Param...))
73 {
74 auto call = dispatch::detail::Caller<Ret, Class, Param...>(t_func);
75
76 return Proxy_Function(
77 chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Callable_Impl<Ret (Class &, Param...), decltype(call)>>(call));
78
79 }
80
81 template<typename T, typename Class /*, typename = typename std::enable_if<std::is_member_object_pointer<T>::value>::type*/>
82 Proxy_Function fun(T Class::* m /*, typename std::enable_if<std::is_member_object_pointer<T>::value>::type* = 0*/ )
83 {
85 }
86
87// only compile this bit if noexcept is part of the type system
88//
89#if (defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510) || (defined(_NOEXCEPT_TYPES_SUPPORTED) && _MSC_VER >= 1912)
90 template<typename Ret, typename ... Param>
91 Proxy_Function fun(Ret (*func)(Param...) noexcept)
92 {
93 auto fun_call = dispatch::detail::Fun_Caller<Ret, Param...>(func);
94
95 return Proxy_Function(
96 chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Callable_Impl<Ret (Param...), decltype(fun_call)>>(fun_call));
97
98 }
99
100 template<typename Ret, typename Class, typename ... Param>
101 Proxy_Function fun(Ret (Class::*t_func)(Param...) const noexcept)
102 {
103 auto call = dispatch::detail::Const_Caller<Ret, Class, Param...>(t_func);
104
105 return Proxy_Function(
107 }
108
109 template<typename Ret, typename Class, typename ... Param>
110 Proxy_Function fun(Ret (Class::*t_func)(Param...) noexcept)
111 {
112 auto call = dispatch::detail::Caller<Ret, Class, Param...>(t_func);
113
114 return Proxy_Function(
116
117 }
118#endif
119
120
121
122
141 template<typename T, typename Q>
142 Proxy_Function fun(T &&t, const Q &q)
143 {
144 return fun(detail::bind_first(std::forward<T>(t), q));
145 }
146
147
148}
149
150
151#endif
152
P func(int c, EveryApi &ev)
Definition test.cpp:59
Object call(Vector t_params) const
Calls the function with the given set of parameters and returns the value;.
Attribute getter Proxy_Function implementation.
Definition proxy_functions.hpp:724
Definition proxy_functions.hpp:196
For any callable object.
Definition proxy_functions.hpp:637
auto bind_first(Ret(*f)(P1, Param...), O &&o)
Definition bind_first.hpp:34
Namespace chaiscript contains every API call that the average user will be concerned with.
std::shared_ptr< dispatch::Proxy_Function_Base > Proxy_Function
Common typedef used for passing of any registered function in ChaiScript.
Definition proxy_functions.hpp:317
Proxy_Function fun(const T &t)
Creates a new Proxy_Function object from a free function, member function or data member.
Definition register_function.hpp:43
std::shared_ptr< B > make_shared(Arg &&... arg)
Definition chaiscript_defines.hpp:87
@ Class
Definition chaiscript_common.hpp:69
Definition parser.cc:9
Definition GameApi.h:70
Definition GameApi_bm.cc:4579
Definition GameApi.h:42
Function_Signature< decltype(&T::operator())>::Signature Signature
Definition callable_traits.hpp:99
Definition callable_traits.hpp:53
Definition callable_traits.hpp:27
Definition callable_traits.hpp:40