LuaBridge3 icon indicating copy to clipboard operation
LuaBridge3 copied to clipboard

Compile error with Cfunc property getter/setter

Open rpatters1 opened this issue 11 months ago • 2 comments

I am getting a compiler error from the following addProperty call:


class foo
{
   int value{};

public:
   int get_value_cfunc(lua_State* L) const
   {
      luabridge::Stack<int>::push(L, value).throw_on_error();
      return 1;
   }
   int set_value_cfunc(lua_State *L)
   {
      value = luabridge::Stack<int>::get(L, 2).value();
      return 0;
   }
};

   luabridge::getGlobalNamespace(L)
      .beginClass<foo>("foo")
         .addProperty("value", &foo::get_value_cfunc, &foo::set_value_cfunc)
      .endClass();

I am guessing it may be because the getter and setter cfuncs are class members. There is no similar problem with addFunction. Should this be allowed?

rpatters1 avatar Mar 05 '24 15:03 rpatters1

I guess it could easily be fixed by making the cfuncs static. If that is sufficient solution for you, go ahead and close this issue.

rpatters1 avatar Mar 05 '24 15:03 rpatters1

I think that addProperty might miss overloads for member cfunctions (addFunction should have them). Will add them

kunitoki avatar Mar 05 '24 15:03 kunitoki