This commit is contained in:
ekibun
2020-09-13 22:50:14 +08:00
parent 89ea0222be
commit 60466a5c7d
11 changed files with 146 additions and 10 deletions

39
test/lib/ffi.cpp Normal file
View File

@@ -0,0 +1,39 @@
/*
* @Description:
* @Author: ekibun
* @Date: 2020-09-06 18:32:45
* @LastEditors: ekibun
* @LastEditTime: 2020-09-13 17:26:29
*/
#include "../../cxx/quickjs/quickjs.h"
#include <cstring>
#ifdef _MSC_VER
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __attribute__((visibility("default")))
#endif
extern "C"
{
DLLEXPORT JSRuntime *jsNewRuntime()
{
return JS_NewRuntime();
}
DLLEXPORT JSContext *jsNewContext(JSRuntime *rt)
{
return JS_NewContext(rt);
}
DLLEXPORT JSValue *jsEval(JSContext *ctx, const char *input, const char *filename, int eval_flags)
{
return new JSValue{JS_Eval(ctx, input, strlen(input), filename, eval_flags)};
}
DLLEXPORT const char *jsToCString(JSContext *ctx, JSValue *val)
{
return JS_ToCString(ctx, *val);
}
}