mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-28 13:57:25 +00:00
test ffi
This commit is contained in:
19
test/lib/CMakeLists.txt
Normal file
19
test/lib/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
|
||||
project(ffi_library LANGUAGES CXX)
|
||||
add_library(ffi_library SHARED ffi.cpp)
|
||||
|
||||
# quickjs
|
||||
set(QUICK_JS_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../cxx/quickjs)
|
||||
file (STRINGS "${QUICK_JS_LIB_DIR}/VERSION" QUICKJS_VERSION)
|
||||
add_library(libquickjs STATIC
|
||||
${QUICK_JS_LIB_DIR}/cutils.c
|
||||
${QUICK_JS_LIB_DIR}/libregexp.c
|
||||
${QUICK_JS_LIB_DIR}/libunicode.c
|
||||
${QUICK_JS_LIB_DIR}/quickjs.c
|
||||
)
|
||||
|
||||
project(libquickjs LANGUAGES C)
|
||||
target_compile_options(libquickjs PRIVATE "-DCONFIG_VERSION=\"${QUICKJS_VERSION}\"")
|
||||
target_compile_options(libquickjs PRIVATE "-DDUMP_LEAKS")
|
||||
|
||||
target_link_libraries(ffi_library PRIVATE libquickjs)
|
39
test/lib/ffi.cpp
Normal file
39
test/lib/ffi.cpp
Normal 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);
|
||||
}
|
||||
}
|
5
test/lib/make.cmd
Normal file
5
test/lib/make.cmd
Normal file
@@ -0,0 +1,5 @@
|
||||
cd %~dp0
|
||||
set CMAKE="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
|
||||
set BUILD_DIR="./build"
|
||||
%CMAKE% -S ./ -B %BUILD_DIR%
|
||||
%CMAKE% --build %BUILD_DIR% --verbose
|
Reference in New Issue
Block a user