polserver/pol-core/pol/module/basiciomod.cpp
Kevin Eady 271722af13
Send Print() messages to attached debugger (#663)
* Implementation

* Tests

* Update core-changes

* Implementation fixup
- do not copy message from executor
2024-07-16 12:41:55 +02:00

43 lines
980 B
C++

/** @file
*
* @par History
*/
#include "basiciomod.h"
#include "bscript/berror.h"
#include "bscript/impstr.h"
#include "clib/logfacility.h"
#include "plib/systemstate.h"
#include <module_defs/basicio.h>
namespace Pol::Module
{
BasicIoExecutorModule::BasicIoExecutorModule( Bscript::Executor& exec )
: Bscript::TmplExecutorModule<BasicIoExecutorModule, Bscript::ExecutorModule>( exec )
{
}
Bscript::BObjectImp* BasicIoExecutorModule::mf_Print()
{
const Bscript::String* color;
if ( !exec.getStringParam( 1, color ) )
return new Bscript::BError( "Invalid parameter type" );
const auto& message = exec.getParamImp( 0 )->getStringRep();
if ( Plib::systemstate.config.enable_colored_output && color->length() )
{
INFO_PRINTLN( "{}{}{}", color->value(), message, Clib::Logging::CONSOLE_RESET_COLOR );
}
else
{
INFO_PRINTLN( message );
}
exec.print_to_debugger( message );
return new Bscript::UninitObject;
}
} // namespace Pol::Module