I am trying to access from C++ file members from a type I defined in a script. The problem is that Boxed_Value::get_attr
always return a null value.
Here is my C++ file:
#include <chaiscript/chaiscript.hpp>
#include <iostream>
int main()
{
chaiscript::ChaiScript chai;
chaiscript::Boxed_Value test_value = chai.eval_file("script.chai");
chaiscript::Boxed_Value number = test_value.get_attr("number");
std::cout << chaiscript::boxed_cast<int>(number) << std::endl;
}
And script.chai:
class MyType
{
attr number
def MyType
{
this.number = 30
}
}
MyType()
I expected it to print 30, but instead it throwed a bad_boxed_cast
exception. During my investingation I found that number.is_null()
is true.
I obviously did something wrong, but I can't find my mistake.
Or maybe it is not intended to be used this way ?