Tomasu / LuaGlue

C++11 Lua 5.2 Binding Library
zlib License
79 stars 22 forks source link

LuaGlueClass::prop doesn't accept const ref #22

Closed JMLX42 closed 10 years ago

JMLX42 commented 10 years ago

Hello,

I just you added LuaGlueClass::prop() to handle properties through proper getter/setter. Thank you for that!

One problem we have though is that it won't work with const arguments. Yet a setter/setter is likely to get const arguments or return a const value.

How can we fix this?

Tomasu commented 10 years ago

Probably just another override.

JMLX42 commented 10 years ago

Probably. And it looks like it doesn't work with std::shared_ptr either. Here is my stub class:

class LuaStub
{
public:
  LuaStub() {}

  std::shared_ptr<input::Mouse> mouse;

  std::shared_ptr<input::Mouse>
  getMouse()
  {
    return mouse;
  }
};

This doesn't work:

    _state
        .Class<LuaStub>(name)
            .prop("mouse", &LuaStub::mouse)
        .end()
        .glue();

but this works:

    _state
        .Class<LuaStub>(name)
            .method("getMouse", &LuaStub::getMouse)
        .end()
        .glue();

Any idea? Is it relevant to create another issue or is it another missing override?

Tomasu commented 10 years ago

hm, I probably need to add some code to handle static properties that are wrapped in a shared_ptr. didn't think about that.

Tomasu commented 10 years ago

if you want to use the mouse member with a getter and setter, you have to use the prop("name", &Class::getProp, &Class::setProp) override.

JMLX42 commented 10 years ago

I know. But I actually wanted to skip the getter/setter for this one. I will create a separate issue.

On Sun, Dec 15, 2013 at 8:39 PM, Thomas Fjellstrom <notifications@github.com

wrote:

if you want to use the mouse member with a getter and setter, you have to use the prop("name", &Class::getProp, &Class::setProp) override.

— Reply to this email directly or view it on GitHubhttps://github.com/Tomasu/LuaGlue/issues/22#issuecomment-30618284 .

Jean-Marc Le Roux

Founder and CEO of Aerys (http://aerys.in)

Blog: http://blogs.aerys.in/jeanmarc-leroux Cell: (+33)6 20 56 45 78 Phone: (+33)9 72 40 17 58

JMLX42 commented 10 years ago

Any update on the ref. issue?

Tomasu commented 10 years ago

It may or may not work now. I did fix some const/ref stuff in the last push. but I didn't specifically test it.

Tomasu commented 10 years ago

I just added support for the getter being a const method. seems to work here.

Tomasu commented 10 years ago

When you get a chance to test, let me know how you fare. I'd like to get these const/ref issues fixed. :) thanks.

Tomasu commented 10 years ago

I'm assuming this is fixed now. Re-open if it isn't.