简体   繁体   中英

How to pass lua table to the c++ class Constructor using luaBridge?

This is what i want to make.

int lua:

object1 = MyObjectClass({1,2,3});

in c++

class MyObjectClass
{
public:
    MyObjectClass(/*How to passed lua table here?*/)
    {
    
    }
    void printmynum()
    {

    }
};


getGlobalNamespace(L)
    .beginClass<MyObjectClass>("MyObjectClass")
    .addConstructor<>()//???
    .addFunction("printmynum",&MyObjectClass::printmynum)
    .endClass();

I am sorry about the weak English skills.

I want to receive the table of lua from the constructor of MyObjectClass.

solved

class MyObjectClass
{
public:
    MyObjectClass(lua_State* L)
    {
        LuaRef param = LuaRef::fromStack(L, 2);
        if (param.isTable())
        {
            cout << param[1] << endl;
        }
    }
    void printmynum()
    {

    }
};


getGlobalNamespace(L)
.beginClass<MyObjectClass>("MyObjectClass")
    .addConstructor<void (*)(lua_State*)>()
    .addFunction("printmynum",&MyObjectClass::printmynum)
    .endClass();
    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM