Skip to content

sol::table:size() #63

@iganinja

Description

@iganinja

Hi

I am very new to github so please forgive my noobness: I started using Sol and managed to integrate it (it's very easy, no problem here) in my test program. I tried the following: load a lua file which has a generateDungeon function which returns a 4096 elements table. Then in C++ I do the following:

sol::function dungeonFunc = luaVM.get<sol::function>("generateDungeon");
sol::table dungeon = dungeonFunc.call<sol::table>();

Everything works flawlessly but when I want to read all the values from table:

for(std::size_t i = 1; i <= dungeon.size(); ++ i)
{
    const auto value = dungeon.get<int>(i);

    // etc...
}

loop finishes but I have seg fault errors in random places. I tested commenting here and there and my conclusion points to sol::table::size(). I took dungeon.size() call out from for loop:

auto dungeonSize = dungeon.size();
for(std::size_t i = 1; i <= dungeonSize; ++ i)

With this change everything works. I checked sol::table:size() and we have the following:

size_t size() const {
    push();
    return lua_rawlen(state(), -1);
}

With my total lack of knowledge of how sol and lua work, I would say that push() makes some stack get bigger in each call to size() and finally makes my app crash. Is it possible this to be a bug?

Thanks for your library by the way ;)

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions