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

static methods don't see static members in same class #1495

Open Enem-20 opened 1 year ago

Enem-20 commented 1 year ago

Hello mates. I'm trying to introduce resource manager parts to binding. the class I want to embed in lua consists of static methods and fields. This is my small binding:

void ClassRegistrator::Reg_ResourceManager(sol::table* Lnamespace)
{
    Lnamespace->new_usertype<ResourceManager>("ResourceManager"
        , "", sol::no_constructor
        , "loadScene", &ResourceManager::loadSave
        , "getGameObject", &ResourceManager::getResource<GameObject>
    );
}

When I call getGameObject function it doesn't see resources which I stored before. Here, for example, m_resources is clear:

template<class ResourceType>
std::shared_ptr<ResourceType> ResourceManager::getResource(const std::string& name) {
    static_assert(std::is_base_of<ResourceBase, ResourceType>::value, "this resource can't be attached due to the class isn't inherit from ResourceBase");
    auto resourcesByType = m_resources.find(ResourceType::type);
    if (resourcesByType != m_resources.cend()) {
        auto resource = resourcesByType->second.find(name);

        if (resource != resourcesByType->second.cend()) {
            return resource->second.getResource<ResourceType>();
        }
    }
    std::cerr << "Error: this resource type doesn't exist" << '\n';
    return nullptr;
} 

Is that due to sol just copy function signature and call it?