I have used sqrat to bind several C++ classes to squirrel, some of which are used in other classes.
Whenever an instance of a class is initialized in squirrel, I am unable to set any nested native variables after the first level (however, they do return their values).
This just provides an example, it's not actual code:
Pseudocode Example:
C++ Classes:
:::C++
class Point2D{
float X = 5;
float Y = 5;
};
class Window{
string Name = "Default";
Point2D Position = Point2D();
};
int main()
{
[...]
RootTable().Bind("Point2D",Class<Point2D>()
.Var("X",&Point2D::X));
RootTable().Bind("Window",Class<Window>()
.Var("Position",&Window::Position)
.Var("Name",&Window::Name));
}
Squirrel Implementation:
:::squirrel
function OnInit()
{
local Win = Window();
Win.Name = "New";
Win.Position = Point2D();
::print(Win.Name); //Correctly Prints "New"
::print(Win.Position.X); //Correctly prints 5 (default value)
Win.Name = "Other"; //Tries to set non-nested variable
Win.Position.X = 11; //Tries to set nested variable
::print(Win.Name); //Correctly prints "Other"
::print(Win.Position.X); //Incorrectly still prints 5
}
Any ideas what the issue may be, or how to fix it?
Nothing immediately strikes me as being wrong in the way you are using Sqrat.
This might be a compiler optimization issue where no variable is being created.
To test for this, try the following substitution
Other than that, I'll have to check to see if its a problem with Sqrat over the weekend.
I use Sqrat in a similar way, but I always set the value of the position,
and it is never default.
Last edit: Wizzard 2014-02-26
I changed the class definition as per your request, and it had no effect on the output
The Definitions are now as follows (this is slightly different, as the original post was not real code):
C++:
Squirrel:
Forgot to include this in my post, however I am compiling in the following environment:
Yeah. I'll try to investigate this over the weekend. Hmm...
Fixed in commit [d1cb7d]
There was an issue where Sqrat was not returning references in its get metamethod for classes
Related
Commit: [d1cb7d]
Awesome, thank you :D