Git Product home page Git Product logo

Comments (6)

kunitoki avatar kunitoki commented on June 25, 2024

Should be possible by accessing class metatable and using the internal keys luabridge use. Will try to provide some working snippets as soon as i'm back to the laptop.

from luabridge3.

kunitoki avatar kunitoki commented on June 25, 2024

Do you need to access them from lua or c++ ?

from luabridge3.

kunitoki avatar kunitoki commented on June 25, 2024
    luabridge::setHideMetatables(false);

    luabridge::getGlobalNamespace(L)
        .addFunction("getMetatableClass", [](const luabridge::LuaRef& ref) -> luabridge::LuaRef
        {
            if (!ref.isTable())
                return luabridge::LuaRef(ref.state());

            ref.push();
            luabridge::lua_rawgetp(ref.state(), -1, luabridge::detail::getClassKey());

            auto mt = luabridge::LuaRef::fromStack(ref.state(), 1);

            for (const auto& p : luabridge::pairs(mt))
                std::cout << p.first << " " << p.second << std::endl;

            return mt;
        })
        .beginClass<ExampleStringifiableClass>("ExampleStringifiableClass")
            .addConstructor<void(*) ()>()
            .addFunction("nonConstMethod", [](ExampleStringifiableClass*) {})
            .addFunction("constMethod", [](const ExampleStringifiableClass*) {})
        .endClass();

    runLua(R"(
        local t = ExampleStringifiableClass()
        local mt = getmetatable(t)

        getMetatableClass(mt)
    )");

this will print:

userdata: 0xc07 table: 0x6000017084c0
"__gc" function: 0x600000c09aa0
"nonConstMethod" function: 0x600001708780
userdata: 0x71 "ExampleStringifiableClass"
userdata: 0x5e7 table: 0x600001708600
userdata: 0x6e7 table: 0x6000017085c0
"__newindex" function: 0x600000c09ad0
"__index" function: 0x600000c09b00
"constMethod" function: 0x600001708800

Will provide some facilities to extract this kind of information in a more straight forward way

from luabridge3.

rpatters1 avatar rpatters1 commented on June 25, 2024

I need to access them from Lua. It is a powerful tool for verifying the correctness of the LuaBridge implementation, as well as presenting the class framework to users as a learning aid.

from luabridge3.

kunitoki avatar kunitoki commented on June 25, 2024

We can design a specific help table for that. So registering a method could push an entry in the table with the description of the method and argument type as seen from c++ (but not name) registered in the class

from luabridge3.

rpatters1 avatar rpatters1 commented on June 25, 2024

Pre-2019, instead of hard-coded usersdata values the tables above had string keys, _class, _propget, _propset, and _static. (They may have been a _const key too, but if so I never used it.) I only need to be able to iterate them and get their names. I don't need to modify or call the values.

I am currently doing exactly what you suggested and adding helper tables as I register the classes. I use refl-cpp to reflect the C++ classes at compile time so that all of my registrations use the same code. The challenge with refl-cpp is that lack of useful support for overloaded methods. The current support would require me to know and hardcode the function signatures in the central routine where I'm processing them rather than in the lists where I list them, so right now I can't use refl-cpp for everything.

from luabridge3.

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.