-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluapp_stackops.cpp
More file actions
71 lines (66 loc) · 1.4 KB
/
luapp_stackops.cpp
File metadata and controls
71 lines (66 loc) · 1.4 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/// luapp_stackops.cpp -- cpp wrapper for lua stack operators
/// Author: Zhang Yichao <echaozh@gmail.com>
/// Created: 2011-08-21
///
#include "luapp.hpp"
using namespace std;
namespace luapp
{
lua &operator << (lua &l, bool b)
{
lua_pushboolean (l.l (), b);
return l;
}
lua &operator << (lua &l, ptrdiff_t n)
{
lua_pushinteger (l.l (), n);
return l;
}
lua &operator << (lua &l, double d)
{
lua_pushnumber (l.l (), d);
return l;
}
lua &operator << (lua &l, const string &s)
{
lua_pushstring (l.l (), s.c_str ());
return l;
}
lua &operator << (lua &l, lua_CFunction f)
{
lua_pushcfunction (l.l (), f);
return l;
}
lua &operator >> (lua &l, bool &b)
{
b = lua_toboolean (l.l (), -1);
l.pop ();
return l;
}
lua &operator >> (lua &l, ptrdiff_t &n)
{
n = lua_tointeger (l.l (), -1);
l.pop ();
return l;
}
lua &operator >> (lua &l, double &d)
{
d = lua_tonumber (l.l (), -1);
l.pop ();
return l;
}
lua &operator >> (lua &l, float &f)
{
double d;
l >> d;
f = d;
return l;
}
lua &operator >> (lua &l, std::string &s)
{
const char *cp = lua_tostring (l.l (), -1);
s = cp ?: "";
l.pop ();
return l;
}
}