My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
#include <chaiscript/utility/utility.hpp>

template<typename LHS, typename RHS>
void assert_equal(const LHS &lhs, const RHS &rhs)
{
if (lhs==rhs)
{
return;
} else {
std::cout << "Got: " << lhs << " expected " << rhs << std::endl;
exit(EXIT_FAILURE);
}
}

int main()
{

chaiscript::ChaiScript chai;

chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()");

chaiscript::Dynamic_Object &mydo = chai.eval<chaiscript::Dynamic_Object &>("x");

assert_equal(mydo.get_type_name(), "bob");

assert_equal(chaiscript::boxed_cast<int>(mydo.get_attr("z")), 10);

chai("x.z = 15");

assert_equal(chaiscript::boxed_cast<int>(mydo.get_attr("z")), 15);

int &z = chaiscript::boxed_cast<int&>(mydo.get_attr("z"));

assert_equal(z, 15);

z = 20;

assert_equal(z, 20);

assert_equal(chaiscript::boxed_cast<int>(chai("x.z")), 20);

return EXIT_SUCCESS;

}

Change log

r510 by lefticus on Jul 25, 2010   Diff
Add test of dynamic object attribute
access shared between c++ and chaiscript
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 897 bytes, 44 lines
Powered by Google Project Hosting