Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chaiscript/chaiscript.hpp>
- using namespace std;
- using namespace chaiscript;
- class B
- {
- public:
- B() { value = 1; }
- ~B() {}
- void setValue(int val) { value = val; }
- int getValue() const { return value; }
- private:
- int value;
- };
- class A
- {
- public:
- A() {}
- ~A() {}
- void setB(B* b) { b_ = b; }
- B* getB() const { return b_; }
- private:
- B* b_;
- };
- void
- chaiInit(ChaiScript &chai)
- {
- chai.add(user_type<A>(), "A");
- chai.add(constructor<A()>(), "A");
- chai.add(constructor<A(const A&)>(), "A");
- chai.add(fun(&A::operator=), "=");
- chai.add(fun(&A::getB), "getB");
- chai.add(user_type<B>(), "B");
- chai.add(constructor<B()>(), "B");
- chai.add(constructor<B(const B&)>(), "B");
- chai.add(fun(&B::operator=), "=");
- chai.add(fun(&B::getValue), "getValue");
- chai.add(fun(&B::setValue), "setValue");
- }
- int main()
- {
- ChaiScript chai;
- chaiInit(chai);
- A a;
- B b;
- a.setB(&b);
- chai.add(var(&a), "a");
- chai.add(var(&b), "b");
- cout << "Script output: " << endl;
- chai.eval_file("chai.chai");
- cout << "Other output" << endl;
- cout << "B->value: " << b.getValue() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement