Permalink
Browse files

Added the luabind copy policy to some functions where the return valu…

…es would otherwise behave unexpected in Lua (could not be changed, which is somewhat normal for const references, but strange in lua)
  • Loading branch information...
1 parent 72e5252 commit f8ae001b9a5fb6a544e02c84b15b1363c6afd6dc @mrwonko committed May 26, 2012
@@ -9,6 +9,7 @@
#include <SFML/Window/Mouse.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Image.hpp>
+#include <luabind/copy_policy.hpp>
namespace jar
{
@@ -39,9 +40,9 @@ void RenderWindow::Luabind(lua_State* L)
[
luabind::class_<sf::RenderTarget>("RenderTarget")
.def("SetView", &sf::RenderTarget::setView)
- .def("GetView", &sf::RenderTarget::getView)
- .def("GetDefaultView", &sf::RenderTarget::getDefaultView)
- .def("GetSize", &sf::RenderTarget::getSize)
+ .def("GetView", &sf::RenderTarget::getView, luabind::copy(luabind::result))
+ .def("GetDefaultView", &sf::RenderTarget::getDefaultView, luabind::copy(luabind::result))
+ .def("GetSize", &sf::RenderTarget::getSize, luabind::copy(luabind::result))
.def("Draw", &RenderTargetDraw)
.def("Draw", (void(sf::RenderTarget::*)(const sf::Drawable&, const sf::RenderStates&))&sf::RenderTarget::draw),
@@ -16,6 +16,7 @@
#include <luabind/operator.hpp>
#include <luabind/out_value_policy.hpp>
#include <luabind/return_reference_to_policy.hpp>
+#include <luabind/copy_policy.hpp>
#include <luabind/wrapper_base.hpp>
namespace jar
@@ -184,10 +185,11 @@ void BindSFMLGraphics(lua_State* L)
.def("SetSize", (void(sf::View::*)(float, float))&sf::View::setSize)
.def("Move", (void(sf::View::*)(const sf::Vector2f&))&sf::View::move)
.def("Move", (void(sf::View::*)(float, float))&sf::View::move)
- .def("GetCenter", &sf::View::getCenter)
- .def("GetSize", &sf::View::getSize)
+ .def("GetCenter", &sf::View::getCenter, luabind::copy(luabind::result))
+ .def("GetSize", &sf::View::getSize, luabind::copy(luabind::result))
.def("Zoom", &sf::View::zoom)
- .def("SetViewport", &sf::View::setViewport),
+ .def("SetViewport", &sf::View::setViewport)
+ .def("GetViewport", &sf::View::getViewport, luabind::copy(luabind::result)),
luabind::class_<sf::Transformable>("Transformable2D")
.def("SetPosition", (void(sf::Transformable::*)(float, float))&sf::Transformable::setPosition)
@@ -199,10 +201,10 @@ void BindSFMLGraphics(lua_State* L)
.def("SetOrigin", (void(sf::Transformable::*)(float, float))&sf::Transformable::setOrigin)
.def("SetOrigin", (void(sf::Transformable::*)(const sf::Vector2f&))&sf::Transformable::setOrigin)
.def("SetRotation", &sf::Transformable::setRotation)
- .def("GetPosition", &sf::Transformable::getPosition)
- .def("GetScale", &sf::Transformable::getScale)
- .def("GetOrigin", &sf::Transformable::getOrigin)
- .def("GetRotation", &sf::Transformable::getRotation)
+ .def("GetPosition", &sf::Transformable::getPosition, luabind::copy(luabind::result))
+ .def("GetScale", &sf::Transformable::getScale, luabind::copy(luabind::result))
+ .def("GetOrigin", &sf::Transformable::getOrigin, luabind::copy(luabind::result))
+ .def("GetRotation", &sf::Transformable::getRotation, luabind::copy(luabind::result))
.def("Move", (void(sf::Transformable::*)(float, float))&sf::Transformable::move)
.def("Move", (void(sf::Transformable::*)(const sf::Vector2f&))&sf::Transformable::move)
.def("Scale", (void(sf::Transformable::*)(float, float))&sf::Transformable::scale)
@@ -229,9 +231,9 @@ void BindSFMLGraphics(lua_State* L)
.def("SetFillColor", &sf::Shape::setFillColor)
.def("SetOutlineColor", &sf::Shape::setOutlineColor)
.def("SetOutlineThickness", &sf::Shape::setOutlineThickness)
- .def("GetFillColor", &sf::Shape::getFillColor)
- .def("GetOutlineColor", &sf::Shape::getOutlineColor)
- .def("GetOutlineThickness", &sf::Shape::getOutlineThickness),
+ .def("GetFillColor", &sf::Shape::getFillColor, luabind::copy(luabind::result))
+ .def("GetOutlineColor", &sf::Shape::getOutlineColor, luabind::copy(luabind::result))
+ .def("GetOutlineThickness", &sf::Shape::getOutlineThickness, luabind::copy(luabind::result)),
luabind::class_<sf::CircleShape, sf::Shape>("CircleShape")
.def(luabind::constructor<float>())
@@ -242,7 +244,7 @@ void BindSFMLGraphics(lua_State* L)
luabind::class_<sf::RectangleShape, sf::Shape>("RectangleShape")
.def(luabind::constructor<sf::Vector2f>())
.def("SetSize", &sf::RectangleShape::setSize)
- .def("GetSize", &sf::RectangleShape::getSize),
+ .def("GetSize", &sf::RectangleShape::getSize, luabind::copy(luabind::result)),
luabind::class_<sf::Texture>("Texture")
.def(luabind::constructor<>())
@@ -256,8 +258,8 @@ void BindSFMLGraphics(lua_State* L)
.def("SetTexture", &sf::Sprite::setTexture)
.def("GetTexture", &sf::Sprite::getTexture)
.def("SetTextureRect", &sf::Sprite::setTextureRect)
- .def("GetTextureRect", &sf::Sprite::getTextureRect)
- .def("GetGlobalBounds", &sf::Sprite::getGlobalBounds)
+ .def("GetTextureRect", &sf::Sprite::getTextureRect, luabind::copy(luabind::result))
+ .def("GetGlobalBounds", &sf::Sprite::getGlobalBounds, luabind::copy(luabind::result))
.def("SetColor", &sf::Sprite::setColor)
.def("GetColor", &sf::Sprite::getColor)

0 comments on commit f8ae001

Please sign in to comment.