However, in my case I would like to have a container plus some additional add overloads, to simplify lua code.
This is my code so far:
struct MyObject
{
int x;
int y;
};
struct MyObjContainer : std::list<MyObject>
{
// my own overloads
void add(int x, int y) { push_back(MyObject{x, y}); } // should allow list:add(1, 2) instead of list:add(MyObject(1, 2))
// void add(...) { ... } // many overloads, imagine MyObject with different arguments
};
At first, I followed the example provided here to expose a container: https://github.com/ThePhD/sol2/issues/773#issuecomment-463550908 and it's working.
However, in my case I would like to have a container plus some additional
add
overloads, to simplify lua code.This is my code so far:
and then:
But this just gives huge errors (I renamed real filenames):
I don't understand why it's requiring additional operators, since they are not requested when exposing
std::list<MyObject>
directly in this way: https://github.com/ThePhD/sol2/issues/773#issuecomment-463550908.I just need an additional method, could this be so difficult? What am I missing? Is there a way to achieve what I need?
I found this alternative here (via composition): https://github.com/ThePhD/sol2/blob/develop/examples/source/container_usertype_as_container.cpp but I would like to avoid having to explicitly wrap all methods and types of the underlying container if possible, since I just need to go in "addition" to them.