sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

static methods don't see static members in same class

Open Enem-20 opened this issue 2 years ago • 0 comments

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?

Enem-20 avatar May 29 '23 07:05 Enem-20