Giter VIP home page Giter VIP logo

Comments (5)

Unril avatar Unril commented on July 19, 2024

And this example:

struct NcTest {
  NcTest() { printf("NcTest()\r\n"); }

  NcTest(const NcTest &other) { printf("NcTest(const NcTest& other)\r\n"); }

  NcTest(NcTest &&other) noexcept { printf("NcTest(NcTest&& other)\r\n"); }

  NcTest &operator=(const NcTest &other) {
    printf("NcTest& operator=(const NcTest& other)\r\n");
    return *this;
  }

  NcTest &operator=(NcTest &&other) {
    printf("NcTest& operator=(NcTest&& other)\r\n");
    return *this;
  }

  auto foo() -> NcTest &{
    printf("foo()\r\n");
    return *this;
  }
};

auto const ncTestMt =
    kaguya::UserdataMetatable<NcTest>().setConstructors<NcTest()>().addFunction(
        "foo", &NcTest::foo);

int main() {
  kaguya::State state;
  state["T"].setClass(ncTestMt);
  state("a = T.new()");
  state("a:foo():foo()");

  return 0;
}

outputs

foo()
NcTest(const NcTest& other)
foo()
NcTest(const NcTest& other)

Though there shouldn't be any copying.

from kaguya.

satoren avatar satoren commented on July 19, 2024

I don’t like implicit (unsafe)reference return .

from kaguya.

Unril avatar Unril commented on July 19, 2024

But it

  • makes great part of previous c++/lua codebases incompatible
  • makes fluent interfaces impossible
  • hurts performance in unexpected places due to unnecessary copying
  • doen't correspond to default c++ behaviour
  • counterintuitive

from kaguya.

satoren avatar satoren commented on July 19, 2024

Ok, changed.

from kaguya.

satoren avatar satoren commented on July 19, 2024

Ummm reverted.
This case is can you make pointer function?
e.g.

.addStaticFunction("foo", [](NcTest* self){return &self->foo();})

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.