Implements extern C function to set print func
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
40e45b0112
commit
e639a2c170
|
@ -5,8 +5,14 @@
|
|||
std::streambuf* Porygon::GlobalScriptOptions::_printBuffer = std::cout.rdbuf();
|
||||
std::ostream* Porygon::GlobalScriptOptions::_printStream = new std::ostream(Porygon::GlobalScriptOptions::_printBuffer);
|
||||
|
||||
static void DefaultPrint(const std::u16string& s){
|
||||
static void DefaultPrint(const char16_t* s){
|
||||
Porygon::GlobalScriptOptions::GetPrintStream() << Porygon::Utilities::StringUtils::FromUTF8(s) << std::endl;
|
||||
}
|
||||
|
||||
void (*Porygon::GlobalScriptOptions::_print)(const std::u16string &) = DefaultPrint;
|
||||
void (*Porygon::GlobalScriptOptions::_print)(const char16_t*) = DefaultPrint;
|
||||
|
||||
extern "C"{
|
||||
void SetPrintFunc(void (*func)(const char16_t*)){
|
||||
Porygon::GlobalScriptOptions::SetPrintFunc(func);
|
||||
}
|
||||
}
|
|
@ -5,15 +5,15 @@
|
|||
|
||||
namespace Porygon{
|
||||
class GlobalScriptOptions{
|
||||
static void (*_print)(const std::u16string& s);
|
||||
static void (*_print)(const char16_t* s);
|
||||
static std::streambuf* _printBuffer;
|
||||
static std::ostream* _printStream;
|
||||
public:
|
||||
inline static void Print(const std::u16string& s){
|
||||
inline static void Print(const char16_t* s){
|
||||
GlobalScriptOptions::_print(s);
|
||||
}
|
||||
|
||||
static void SetPrintFunc(void (*print)(const std::u16string&)){
|
||||
static void SetPrintFunc(void (*print)(const char16_t *)){
|
||||
GlobalScriptOptions::_print = print;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Porygon::StandardLibraries{
|
|||
|
||||
static Evaluation::EvalValue* _print(void*, Evaluation::EvalValue* parameters[], int parameterCount){
|
||||
auto message = parameters[0]->EvaluateString();
|
||||
GlobalScriptOptions::Print(message);
|
||||
GlobalScriptOptions::Print(message.c_str());
|
||||
return new Evaluation::NilEvalValue();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue