ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 493 forks source link

Inheritance class, template class, how to bind #1512

Open littleboss01 opened 12 months ago

littleboss01 commented 12 months ago

cpp code

template<class StringT>
class Request {
public:
    StringT method  ;
    StringT url;
};

template<class StringT>
struct Response {
    int statusCode = 0;
    StringT body;
};

template<class StringT>
class HttpClient
{
public: 
    virtual Response<StringT> Get(StringT url) = 0;

};

class QHttpClient : public HttpClient<QString>
{
public:
    QHttpClient();
    ~QHttpClient();

    Response<QString> override;
}

lua code

local client=QHttpClient()
client:Get()

How to use the sol library to bind QHttpClient class to c++, note that it is an inherited abstract class,Request Response also needs to be bound