Giter VIP home page Giter VIP logo

Comments (8)

satoren avatar satoren commented on August 19, 2024

Yes.
Can use lambda,functor,static function if first argument is same type.

state["A"].setClass(kaguya::UserdataMetatable<A>()
    .setConstructors<A()>()
    .addStaticFunction("lambdafn", [](A* self,int v){self->setValue(v);})
    );
local a = ABC.new()
a:lambdafn(3) --equal setValue(3)
a.lambdafn(a,3) --equal to above

from kaguya.

aster2013 avatar aster2013 commented on August 19, 2024

addStaticFunction may not the best name for it situation. I prefer to addMemberFunction.

from kaguya.

satoren avatar satoren commented on August 19, 2024

If implement addMemberFunction for global function, need first argument type check.
but it implement for C++03 is difficult.

from kaguya.

aster2013 avatar aster2013 commented on August 19, 2024

Yes, another question:
When class has setter and getter function, can I treat it as property?

class Class
{
    void SetValue(int value);
    int GetValue() const;
};

.addProperty("value", &Class::GetValue, &Class::SetValue)

from kaguya.

satoren avatar satoren commented on August 19, 2024

Can not now. Try to make because it is easy.

from kaguya.

aster2013 avatar aster2013 commented on August 19, 2024

Thinks, but as convention, it is better make getter as first argumention.

template<typename GetType, typename SetType>
        UserdataMetatable& addProperty(const char* name, GetType(class_type::*getter)()const, void (class_type::*setter)(SetType) ) {}

from kaguya.

satoren avatar satoren commented on August 19, 2024

It's changed.

from kaguya.

aster2013 avatar aster2013 commented on August 19, 2024

Great!, but

template<typename SetType, typename GetType>
UserdataMetatable& addProperty(const char* name, GetType(class_type::*getter)()const, void (class_type::*setter)(SetType))

First template arguments is SetType, It is misleading.

from kaguya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.