I'm trying to bind a free function, as a non-static member function of a foreign class.
Here is my Wren code:
foreign class MyData {
foreign value
foreign value=(rhs)
foreign twiceValue
toString { "MyData(%(value))" }
}
// Some where else
class Player {
// ...
static puts(obj) {
System.print("Putting: %(obj)")
System.print("Putting twice: %(obj.twiceValue)")
}
}
And here is my C++ code (module names are handled correctly):
class MyData
{
public:
double value;
};
double twiceValue(MyData& self)
{
return self.value * 2;
}
// *m_VM is a thin wrapper around `wrenpp::WrenVM` which provides `beginModule` as a wrapper around wrenpp`s version of it.
m_VM->beginModule("src/wren/lib/components")
.bindClass<MyData>("MyData")
.bindGetter<decltype(MyData::value), &MyData::value>("value")
.bindSetter<decltype(MyData::value), &MyData::value>("value=(_)")
.bindMethod<decltype(twiceValue), twiceValue>(false, "twiceValue")
.endClass()
.endModule();
// Loading modules...
m_VM->GetWrenpp().method("src/wren/test", "Player", "puts(_)")(MyData{12});
When I run it, I get:
And then it segfaults.
Using a static function (binding twiceValue as static and passing instance as its first parameter) or a member function works fine.
I'm trying to bind a free function, as a non-static member function of a foreign class.
Here is my Wren code:
And here is my C++ code (module names are handled correctly):
When I run it, I get:
And then it segfaults.
Using a static function (binding
twiceValueas static and passing instance as its first parameter) or a member function works fine.