-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
43 lines (34 loc) · 1.1 KB
/
test.cpp
File metadata and controls
43 lines (34 loc) · 1.1 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
#include <luapp/luapp.hpp>
#include <cassert>
#include <iostream>
#include <string>
using namespace std;
static int cpp_func (lua_State *ll)
{
luapp::lua l (ll);
double a, b;
l >> a >> b;
l << (a >= b ? a : b);
return 1;
}
int main () {
luapp::lua l;
l.load_libs ();
l.load ("print('testing luapp')");
luapp::table t (l, "t");
t.create ();
l.load ("io.write('testing getting/setting field to table ...')");
luapp::value<int> (t, "v").set (1);
assert (luapp::value<int> (t, "v").get () == 1);
l.load ("print(' \033[01;32mpassed\033[0m')");
l.load ("io.write('testing getting/setting array entry to table ...')");
luapp::value<string> (t, 2).set ("2");
assert (luapp::value<string> (t, 2).get () == "2");
l.load ("print(' \033[01;32mpassed\033[0m')");
l.load ("io.write('testing defining/calling c++ functions ...')");
luapp::function (t, "f").define (&cpp_func);
assert (luapp::function (t, "f").call<int> (2.0, 3) == 3);
l.load ("print(' \033[01;32mpassed\033[0m')");
l.load ("print('all tests passed :-)')");
return 0;
}