我正在尝试从我在脚本中定义的类型中访问 C++ 文件成员。问题是Boxed_Value::get_attr
总是返回一个空值。
这是我的 C++ 文件:
#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;
}
和script.chai:
class MyType
{
attr number
def MyType
{
this.number = 30
}
}
MyType()
我希望它打印30,但它却抛出了bad_boxed_cast
异常。在我的投资过程中,我发现这number.is_null()
是真的。我显然做错了什么,但我找不到我的错误。
或者也许它不打算以这种方式使用?