#include "quickjs.h"
#include "quickjs-libc.h"
#include <string.h>
JSRuntime* QJSRuntime = nullptr;
JSContext* QJSContext = nullptr;
JSContext* CreateQJSContext(JSRuntime* InRuntime)
{
JSContext* RetVal = JS_NewContext(QJSRuntime);
js_init_module_std(RetVal, "std");
js_init_module_os(RetVal, "os");
return RetVal;
}
int main(int argc, char* argv[])
{
QJSRuntime = JS_NewRuntime();
js_std_set_worker_new_context_func(CreateQJSContext);
js_std_init_handlers(QJSRuntime);
QJSContext = CreateQJSContext(QJSRuntime);
JS_SetModuleLoaderFunc(QJSRuntime, nullptr, js_module_loader, nullptr);
js_std_add_helpers(QJSContext, -1, nullptr);
char JSScript[] = R"( console.log("JavaScript call console.log() "); )";
JSValue RetValue = JS_Eval(QJSContext, JSScript, strlen(JSScript), "", 0);
js_std_dump_error(QJSContext);
system("pause");
return 0;
}
标签:std,QuickJS,nullptr,js,QJSContext,JS,Hello,QJSRuntime
From: https://www.cnblogs.com/rpg3d/p/17278800.html