#include "wren_inter.h" #include "../utils/stringBuilder.h" #include #include #include StringBuilder stdout_sb = {0}; void writeFn(WrenVM* vm, const char* text) { AppendStringBuilder(&stdout_sb, text, '\n'); } void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) { switch (errorType) { case WREN_ERROR_COMPILE: { TraceLog(LOG_ERROR, "[%s line %d] [Error] %s", module, line, msg); } break; case WREN_ERROR_STACK_TRACE: { TraceLog(LOG_ERROR, "[%s line %d] in %s", module, line, msg); } break; case WREN_ERROR_RUNTIME: { TraceLog(LOG_ERROR, "[Runtime Error] %s", msg); } break; } } void EvaluateScript(char *script) { TraceLog(LOG_INFO, "Evaluating %s...", script); FreeStringBuilder(&stdout_sb); WrenConfiguration config; wrenInitConfiguration(&config); config.writeFn = writeFn; config.errorFn = errorFn; WrenVM* vm = wrenNewVM(&config); if (vm == NULL) { TraceLog(LOG_ERROR, "Failed to initialize a wren vm"); return; } WrenInterpretResult result = wrenInterpret(vm, "main", script); switch (result) { case WREN_RESULT_SUCCESS: break; case WREN_RESULT_COMPILE_ERROR: break; case WREN_RESULT_RUNTIME_ERROR: break; } printf("Wren outp: %s", stdout_sb.val); wrenFreeVM(vm); }