-
Notifications
You must be signed in to change notification settings - Fork 53
/
floating.hpp
56 lines (42 loc) · 1.26 KB
/
floating.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
namespace lua {
namespace detail {
template <typename T>
struct floating {
typedef T write_type;
typedef typename std::remove_reference<T>::type read_type;
inline static bool type_matches(::lua::state s, int idx) {
return s.isnumber(idx);
}
inline static read_type get_unsafe(::lua::state s, int idx) {
return read_type(s.tonumber(idx));
}
template <typename F>
inline static void apply_unsafe(::lua::state s, int idx, F f) {
f(s, idx);
}
inline static void set(::lua::state s, int idx, T value) {
s.pushnumber(write_type(value));
if (idx != 0) s.replace(idx - 1);
}
};
}
template <>
struct type_policy<double> : public detail::floating<double> {
};
template <>
struct type_policy<const double> : public detail::floating<const double> {
};
template <>
struct type_policy<const double&> : public detail::floating<const double&> {
};
template <>
struct type_policy<float> : public detail::floating<float> {
};
template <>
struct type_policy<const float> : public detail::floating<const float> {
};
template <>
struct type_policy<const float&> : public detail::floating<const float&> {
};
}