Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:08:58+00:00 2026-06-02T03:08:58+00:00

This is some of my actual code that deals with exposing C++ classes to

  • 0

This is some of my actual code that deals with exposing C++ classes to Lua, exemplified:

#include <lua5.1/lua.hpp>
#include <tuple>

//in actual code, lots of specializations of these C++<=>Lua's stack helper functions. Here it's just a sample.
template<typename T> T to(lua_State*, int);
template<> int to(lua_State* l, int i){
    return lua_tointeger(l, i);
}
template<typename T> void push(lua_State*, T);
template<> void push(lua_State* l, int val){
    lua_pushinteger(l, val);
}

//in actual code, placed in a header
template<typename T, T> class function_proxy{
    static_assert(sizeof(T)!=sizeof(T), "Error: function_proxy works with functions (duh)");
};

template<typename Return, typename... Args, Return(*func)(Args...)> class function_proxy<Return(*)(Args...), func>{
    static Return call(lua_State* l, Args... args){
        return func(args...);
    }
    template<typename... retrieved> static Return call(lua_State* l, retrieved... read){
        return call(l, read..., to<typename std::tuple_element<sizeof...(read), std::tuple<Args...> >::type >(l, 1+sizeof...(read)));
    }
public:
    static int wrapper(lua_State* l){
        push(l, call(l));
        return 1;
    }
};

//in actual code, inner class of a template class in another header
template<typename CT, CT> class member_helper{
    static_assert(sizeof(CT)!=sizeof(CT), "Error: member_helper works with members of T (duh)");
};
//Just one of the actual partial specializations, to combine constness and the return of void or non-void
template<typename Class, typename Return, typename... Args, Return(Class::*fun)(Args...)> struct member_helper<Return(Class::*)(Args...), fun>{
    static Return as_free(Class& obj, Args... args){
        return (obj.*fun)(args...);
    }
    static int worker(lua_State* l, Class& obj, bool is_const, bool write){
        if(write) throw "Cannot write a member function.";
        //ERROR HERE: template argument 2 is invalid. Not very helpful message.
        lua_pushcclosure(l, function_proxy<decltype(&as_free), &as_free>::wrapper, 0);
        return 1;
    }
};

struct Test{
    int test(int arg){ return arg*3; }
};

int test_as_free(int arg){ return arg*3; }

int main(){
    lua_State* l=luaL_newstate();
    Test t;
    //works fine
    lua_pushcclosure(l, function_proxy<decltype(&test_as_free), &test_as_free>::wrapper, 0);
    //does not work
    member_helper<decltype(&Test::test), &Test::test>::worker(l, t, false, false);
}

The code fails when getting the pointer function_proxy<decltype(&as_free), &as_free>::wrapper, even though a very similar thing is done in main. I don’t think that there’s any difference between getting the pointer of a free function rather than a static member function. Is this an instance of this g++ bug (note that I compile with -std=c++0x and it appears that the bug was fixed in C++11)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:08:59+00:00Added an answer on June 2, 2026 at 3:08 am

    This is a g++ bug and has been acknowledged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is some code that SDL requires in visual studios 2005 in order for
Ok I have some code that boils down to a pattern like this class
I'm writing some code which deals with lots of different fix versions (4.2,4.3,4.4). The
I have a string that is like this {{ some text @ other text
I currently have a table structure that looks something like this(some details omitted): ColumnName
This is some code I found on the internet. I'm not sure how it
I found some this promising code on activestate.com to sort huge files. I'm trying
I have some javascript code that is used in a few different pages in
I'm reviewing some legacy code and I've found a bug that causes the response
I have some code that is structured as follows from my.modules import MyClass Class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.