Pull requests

#4 Merged
Repository
bazhenovc
Branch
default
Repository
alexames
Branch
default

Added proper support for methods returning 'void', added support for 'const T&' and 'T&' parameters

Author
  1. Kirill Bazhenov
Reviewers
Description

Hello.

Consider the following use case:

template <>
struct luaU_Impl<std::string>
{
    static std::string luaU_check(lua_State* L, int index)
    {
        return std::string(luaL_checkstring(L, index));
    }

    static std::string luaU_to(lua_State* L, int index )
    {
        return std::string(lua_tostring(L, index));
    }

    static void luaU_push(lua_State* L, const std::string& val)
    {
        lua_pushstring(L, val.c_str());
    }
};

struct Test
{
    void PrintString(const std::string& s) { /* whatever */ }
};

luaL_Reg Test_metadata[] = {
    { "Info", luaU_func(&Test::PrintString) },
    { nullptr, nullptr }
};

void RegisterTest(lua_State* L)
{
    luaW_register<LogWrapper>(L, "Log", nullptr, lua_Log);
}

It failed to compile because of two issues:
luawrapper did not handle methods returning void properly
luawrapper did not handle references and const references in the 'Args' template expansion in luaU_FuncWrapper.

I fixed the first issue by adding a separate luaU_FuncWrapper template for void functions, and the second issue by removing const qualifiers and references from the 'Args' expansion. (note: do we need to remove volatile qualifiers as well?)

Please note that I've tested these changes only on GCC 4.8.1, I`m planning to test it on other compilers as well as soon as I have some free time.

Hope that this pull request will be useful.

Cheers,
Kirill.

  • Learn about pull requests

Comments (0)