How to use variadic templates to make a generic Lua function wrapper?

后端 未结 2 1420
感情败类
感情败类 2020-12-30 12:52

For my current project, I\'ve been writing a lot of C/C++ to Lua wrappers. A large number of these are simple setters and getters, so I managed to write some templates that

2条回答
  •  长发绾君心
    2020-12-30 13:32

    Reusing the indices generation code from this answer and ignoring the function call to Func (don't know how exactly this is intended to be used), this is how it could look like:

    template 
    int luaU_func_impl(lua_State* L, Collection)
    {
       luaU_push(L, luaW_check(L, 1), luaU_check(L, Idx+2)...);
       return 1;
    }
    
    template 
    int luaU_func(lua_State* L)
    {
       typename GenerateCollection::type Indices;
       return luaU_func_impl(L, Indices);
    }
    

提交回复
热议问题