Page 1 of 1

[Solved] Passing a member function to Noesis::SetLogHandler()

Posted: 16 Oct 2022, 02:00
by Gazoo
Hey y'all,

I prefer to avoid lambda functions unless necessary, given their increased power/complexity compared to 'standard' functions. I've unsuccessfully attempted to pass a member function to the Noesis::SetLogHandler() function. Attempted approaches:

std::bind()
Noesis::SetLogHandler( std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
No bueno, as std::bind() returns an unspecified type https://stackoverflow.com/questions/631 ... d-function

std::function
	std::function<void( const char*, uint32_t, uint32_t, const char*, const char* )> f = std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
	Noesis::SetLogHandler( f );
Setting aside my concern for how long 'f' exists beyond the scope it's declared in, and if that'd cause issues, I still receive this error with this approach:

E0413 no suitable conversion function from "std::function<void (const char *, uint32_t, uint32_t, const char *, const char *)>" to "Noesis::LogHandler" exists

Which... Well... Alright, they're supposedly the same type, but I guess a typedef != std::function?

Anonymous namespace function

My current best solution is to simply implement a function in an anonymous namespace and use it:
namespace {
	void MyLogger( const char*, uint32_t, uint32_t level, const char*, const char* msg )
	{
	}
}
This avoids the lambda function, but doesn't allow me to use a member function.

I'm open to any ideas/suggestions!

Thanks in advance,
Gazoo

Re: Passing a member function to Noesis::SetLogHandler()

Posted: 17 Oct 2022, 12:33
by jsantos
Unfortunately this is not possible with the current API. Please report if this is a blocking feature for your development.

Re: Passing a member function to Noesis::SetLogHandler()

Posted: 18 Oct 2022, 11:51
by Gazoo
Not a blocker as such. More of a minor annoyance. Really appreciate confirming that it isn't currently possible. The anonymous namespace function is preferable to me, compared to the lambda function.