Skip to content

LuaRef::callWithHandler(...).message() returns an invalid message #263

Description

@3lyrion

According to this guide I tried to use LuaRef::callWithHandler.

static auto handle = +[](lua_State* L) -> int
{
    luaL_traceback(L, L, NULL, 1);
    std::string trace   = sol::stack::pop<std::string>(L);
    std::string message = $("{}\n{}", lua_tostring(L, 1), trace); // fmt::format
    lua_pushstring(L, message.c_str());
    return 1;
};
auto result = f.callWithHandler(handle, table);
if (!result)
    std::cerr << result.message();

Output:

The lua function invocation raised an error

static auto handle = +[](lua_State* L) -> int
{
    luaL_traceback(L, L, NULL, 1);
    std::string trace   = sol::stack::pop<std::string>(L);
    std::string message = $("{}\n{}", lua_tostring(L, 1), trace); // fmt::format
    std::cerr << message;
    lua_pushstring(L, message.c_str());
    return 1;
};
f.callWithHandler(handle, table);

Output:

...lua:18: attempt to index local 'a' (a nil value)
stack traceback:  
        ...
        ...
        ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions