ffi wrapper

This commit is contained in:
ekibun
2020-09-20 15:57:08 +08:00
parent 50c7ff12db
commit 5f9fdac9f4
7 changed files with 1104 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(ffi_library LANGUAGES CXX)
add_library(ffi_library SHARED ffi.cpp)
add_library(ffi_library SHARED ${CMAKE_CURRENT_SOURCE_DIR}/../../cxx/ffi.cpp)
# quickjs
set(QUICK_JS_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../cxx/quickjs)

View File

@@ -1,39 +0,0 @@
/*
* @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);
}
}