1

I have a question by using luabridge, it change C++ value fail, for exam:

//c++ files

struct Coor3D_1 {
    int lon;
};
class ETALink{
public:
ETALink()
{

}
Coor3D_1 coor3D_1;
};

bind code is below:

luabridge::getGlobalNamespace(L)
.beginNamespace("test")
.beginClass<Coor3D_1>("Coor3D_1")
.addData("lon", &Coor3D_1::lon)
.endClass()

.beginClass<ETALink>("ETALink")
.addConstructor<void(*) (void)>()
.addData("coor3D_1", &ETALink::coor3D_1)
.endClass()
.endNamespace();

lua files is below:

eta = test.ETALink();
print("---- ", eta.coor3D_1.lon); //this is OK, I can see eta.coor3D_1.lon
eta.coor3D_1.lon = 11 //?? this is not OK, I print  eta.coor3D_1.lon is not 11

now my question is why eta.coor3D_1.lon = 11 not work? I find that double "." will not work....

Jon B
  • 51,025
  • 31
  • 133
  • 161
zhengzheng
  • 11
  • 2

1 Answers1

0

This happens because your class field member (coor3D_1) is passed to Lua as a copy, so when you change its value you change the copy, and the original object is not affected.

Probably you can solve the issue one on these ways:

  • Add an ETALink property which directly operates on the lon field.
  • Make coor3D_1 a property returning a pointer to the Coor3D_1 structure.
Dmitry T.
  • 673
  • 7
  • 7