mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 05:27:23 +00:00
(WIP) macos ffi
This commit is contained in:
31
cxx/ffi.cpp
31
cxx/ffi.cpp
@@ -5,20 +5,13 @@
|
||||
* @LastEditors: ekibun
|
||||
* @LastEditTime: 2020-09-24 00:28:11
|
||||
*/
|
||||
#include "quickjs/quickjs.h"
|
||||
#include "ffi.h"
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLEXPORT __attribute__((visibility("default"))) __attribute__((used))
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef void *JSChannel(JSContext *ctx, const char *method, void *argv);
|
||||
|
||||
DLLEXPORT JSValue *jsThrowInternalError(JSContext *ctx, char *message)
|
||||
{
|
||||
@@ -58,7 +51,7 @@ extern "C"
|
||||
return m;
|
||||
}
|
||||
|
||||
JSValue js_channel(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
JSValue js_channel(JSContext *ctx, JSValueConst this_val, int32_t argc, JSValueConst *argv)
|
||||
{
|
||||
JSRuntime *rt = JS_GetRuntime(ctx);
|
||||
JSChannel *channel = (JSChannel *)JS_GetRuntimeOpaque(rt);
|
||||
@@ -105,7 +98,7 @@ extern "C"
|
||||
return JS_GetRuntime(ctx);
|
||||
}
|
||||
|
||||
DLLEXPORT JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int eval_flags)
|
||||
DLLEXPORT JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int32_t eval_flags)
|
||||
{
|
||||
return new JSValue(JS_Eval(ctx, input, input_len, filename, eval_flags));
|
||||
}
|
||||
@@ -125,7 +118,7 @@ extern "C"
|
||||
return JS_TAG_IS_FLOAT64(tag);
|
||||
}
|
||||
|
||||
DLLEXPORT JSValue *jsNewBool(JSContext *ctx, int val)
|
||||
DLLEXPORT JSValue *jsNewBool(JSContext *ctx, int32_t val)
|
||||
{
|
||||
return new JSValue(JS_NewBool(ctx, val));
|
||||
}
|
||||
@@ -235,8 +228,8 @@ extern "C"
|
||||
return new JSValue(JS_GetProperty(ctx, *this_obj, prop));
|
||||
}
|
||||
|
||||
DLLEXPORT int jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj,
|
||||
JSAtom prop, JSValue *val, int flags)
|
||||
DLLEXPORT int32_t jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj,
|
||||
JSAtom prop, JSValue *val, int32_t flags)
|
||||
{
|
||||
return JS_DefinePropertyValue(ctx, *this_obj, prop, *val, flags);
|
||||
}
|
||||
@@ -256,13 +249,13 @@ extern "C"
|
||||
return new JSValue(JS_AtomToValue(ctx, val));
|
||||
}
|
||||
|
||||
DLLEXPORT int jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
||||
uint32_t *plen, JSValueConst *obj, int flags)
|
||||
DLLEXPORT int32_t jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
||||
uint32_t *plen, JSValueConst *obj, int32_t flags)
|
||||
{
|
||||
return JS_GetOwnPropertyNames(ctx, ptab, plen, *obj, flags);
|
||||
}
|
||||
|
||||
DLLEXPORT JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int i)
|
||||
DLLEXPORT JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int32_t i)
|
||||
{
|
||||
return ptab[i].atom;
|
||||
}
|
||||
@@ -278,12 +271,12 @@ extern "C"
|
||||
}
|
||||
|
||||
DLLEXPORT JSValue *jsCall(JSContext *ctx, JSValueConst *func_obj, JSValueConst *this_obj,
|
||||
int argc, JSValueConst *argv)
|
||||
int32_t argc, JSValueConst *argv)
|
||||
{
|
||||
return new JSValue(JS_Call(ctx, *func_obj, *this_obj, argc, argv));
|
||||
}
|
||||
|
||||
DLLEXPORT int jsIsException(JSValueConst *val)
|
||||
DLLEXPORT int32_t jsIsException(JSValueConst *val)
|
||||
{
|
||||
return JS_IsException(*val);
|
||||
}
|
||||
@@ -293,7 +286,7 @@ extern "C"
|
||||
return new JSValue(JS_GetException(ctx));
|
||||
}
|
||||
|
||||
DLLEXPORT int jsExecutePendingJob(JSRuntime *rt)
|
||||
DLLEXPORT int32_t jsExecutePendingJob(JSRuntime *rt)
|
||||
{
|
||||
JSContext *ctx;
|
||||
return JS_ExecutePendingJob(rt, &ctx);
|
||||
|
112
cxx/ffi.h
Normal file
112
cxx/ffi.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "quickjs/quickjs.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLEXPORT __attribute__((visibility("default"))) __attribute__((used))
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
typedef void *JSChannel(JSContext *ctx, const char *method, void *argv);
|
||||
|
||||
JSValue *jsThrowInternalError(JSContext *ctx, char *message);
|
||||
|
||||
JSValue *jsEXCEPTION();
|
||||
|
||||
JSValue *jsUNDEFINED();
|
||||
|
||||
JSValue *jsNULL();
|
||||
|
||||
JSRuntime *jsNewRuntime(JSChannel channel);
|
||||
|
||||
void jsFreeRuntime(JSRuntime *rt);
|
||||
|
||||
JSContext *jsNewContext(JSRuntime *rt);
|
||||
|
||||
void jsFreeContext(JSContext *ctx);
|
||||
|
||||
JSRuntime *jsGetRuntime(JSContext *ctx);
|
||||
|
||||
JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int32_t eval_flags);
|
||||
|
||||
int32_t jsValueGetTag(JSValue *val);
|
||||
|
||||
void *jsValueGetPtr(JSValue *val);
|
||||
|
||||
int32_t jsTagIsFloat64(int32_t tag);
|
||||
|
||||
JSValue *jsNewBool(JSContext *ctx, int32_t val);
|
||||
|
||||
JSValue *jsNewInt64(JSContext *ctx, int64_t val);
|
||||
|
||||
JSValue *jsNewFloat64(JSContext *ctx, double val);
|
||||
|
||||
JSValue *jsNewString(JSContext *ctx, const char *str);
|
||||
|
||||
JSValue *jsNewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
||||
|
||||
JSValue *jsNewArray(JSContext *ctx);
|
||||
|
||||
JSValue *jsNewObject(JSContext *ctx);
|
||||
|
||||
void jsFreeValue(JSContext *ctx, JSValue *v);
|
||||
|
||||
void jsFreeValueRT(JSRuntime *rt, JSValue *v);
|
||||
|
||||
JSValue *jsDupValue(JSContext *ctx, JSValueConst *v);
|
||||
|
||||
JSValue *jsDupValueRT(JSRuntime *rt, JSValue *v);
|
||||
|
||||
int32_t jsToBool(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
int64_t jsToInt64(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
double jsToFloat64(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
const char *jsToCString(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
void jsFreeCString(JSContext *ctx, const char *ptr);
|
||||
|
||||
uint8_t *jsGetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst *obj);
|
||||
|
||||
int32_t jsIsFunction(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
int32_t jsIsArray(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
void deleteJSValue(JSValueConst *val);
|
||||
|
||||
JSValue *jsGetProperty(JSContext *ctx, JSValueConst *this_obj,
|
||||
JSAtom prop);
|
||||
|
||||
int32_t jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj,
|
||||
JSAtom prop, JSValue *val, int32_t flags);
|
||||
|
||||
void jsFreeAtom(JSContext *ctx, JSAtom v);
|
||||
|
||||
JSAtom jsValueToAtom(JSContext *ctx, JSValueConst *val);
|
||||
|
||||
JSValue *jsAtomToValue(JSContext *ctx, JSAtom val);
|
||||
|
||||
int32_t jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
||||
uint32_t *plen, JSValueConst *obj, int32_t flags);
|
||||
|
||||
JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int32_t i);
|
||||
|
||||
uint32_t sizeOfJSValue();
|
||||
|
||||
void setJSValueList(JSValue *list, uint32_t i, JSValue *val);
|
||||
|
||||
JSValue *jsCall(JSContext *ctx, JSValueConst *func_obj, JSValueConst *this_obj,
|
||||
int32_t argc, JSValueConst *argv);
|
||||
|
||||
int32_t jsIsException(JSValueConst *val);
|
||||
|
||||
JSValue *jsGetException(JSContext *ctx);
|
||||
|
||||
int32_t jsExecutePendingJob(JSRuntime *rt);
|
||||
|
||||
JSValue *jsNewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
|
||||
|
||||
}
|
Reference in New Issue
Block a user