-
Notifications
You must be signed in to change notification settings - Fork 53
/
boolean.hpp
42 lines (34 loc) · 1019 Bytes
/
boolean.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
#pragma once
namespace lua {
namespace detail {
template <typename T>
struct boolean {
// Booleans are ints in Lua
typedef int write_type;
typedef typename std::remove_reference<T>::type read_type;
inline static bool type_matches(::lua::state s, int idx) {
return s.isboolean(idx);
}
inline static read_type get_unsafe(::lua::state s, int idx) {
return s.toboolean(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.pushboolean(write_type(value));
if (idx != 0) s.replace(idx - 1);
}
};
}
template <>
struct type_policy<bool> : public detail::boolean<bool> {
};
template <>
struct type_policy<const bool> : public detail::boolean<const bool> {
};
template <>
struct type_policy<const bool&> : public detail::boolean<const bool&> {
};
}