Skip to content

Commit

Permalink
[unity]因为JsValueType的名字空间是固定不变的,需要加全路径进行引用,另外SetLogCallback移动到Puerts.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 25, 2024
1 parent 153c54f commit 2611136
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 45 deletions.
6 changes: 0 additions & 6 deletions unity/native_src/Inc/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
#pragma warning(pop)

#if !defined(PUERTS_NAMESPACE)
#if defined(WITH_QJS_NAMESPACE_SUFFIX)
#define PUERTS_NAMESPACE puerts_qjs
#elif defined(WITH_V8_NAMESPACE_SUFFIX)
#define PUERTS_NAMESPACE puerts_v8
#else
#define PUERTS_NAMESPACE puerts
#endif
#endif

namespace puerts
{
Expand Down
2 changes: 1 addition & 1 deletion unity/native_src/Inc/JSFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class JSObject

struct FValue
{
JsValueType Type;
puerts::JsValueType Type;
std::string Str;
union
{
Expand Down
26 changes: 13 additions & 13 deletions unity/native_src/Inc/V8Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,57 +115,57 @@ class FV8Utils
Object->GetAlignedPointerFromInternalField(Index) : nullptr;
}

V8_INLINE static JsValueType GetType(v8::Local<v8::Context> Context, const v8::Value *Value)
V8_INLINE static puerts::JsValueType GetType(v8::Local<v8::Context> Context, const v8::Value *Value)
{
if (!Value) return NullOrUndefined;
if (!Value) return puerts::NullOrUndefined;

if (Value->IsNullOrUndefined())
{
return NullOrUndefined;
return puerts::NullOrUndefined;
}
else if (Value->IsBigInt())
{
return BigInt;
return puerts::BigInt;
}
else if (Value->IsNumber())
{
return Number;
return puerts::Number;
}
else if (Value->IsString() || Value->IsRegExp())
{
return String;
return puerts::String;
}
else if (Value->IsBoolean())
{
return Boolean;
return puerts::Boolean;
}
else if (Value->IsFunction())
{
return Function;
return puerts::Function;
}
else if (Value->IsDate())
{
return Date;
return puerts::Date;
}
else if (Value->IsArrayBufferView() || Value->IsArrayBuffer())
{
return ArrayBuffer;
return puerts::ArrayBuffer;
}
else if (Value->IsObject())
{
auto Object = Value->ToObject(Context).ToLocalChecked();
if (Object->InternalFieldCount() == 3 && (intptr_t)Object->GetAlignedPointerFromInternalField(2) == OBJECT_MAGIC)
{
return NativeObject;
return puerts::NativeObject;
}
else
{
return JsObject;
return puerts::JsObject;
}
}
else
{
return Unknow;
return puerts::Unknow;
}
}
};
Expand Down
20 changes: 10 additions & 10 deletions unity/native_src/Src/JSFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ namespace PUERTS_NAMESPACE
{
switch (Value.Type)
{
case NullOrUndefined:
case puerts::NullOrUndefined:
return v8::Null(Isolate);
case BigInt:
case puerts::BigInt:
return v8::BigInt::New(Isolate, Value.BigInt);
case Number:
case puerts::Number:
return v8::Number::New(Isolate, Value.Number);
case Date:
case puerts::Date:
return v8::Date::New(Context, Value.Number).ToLocalChecked();
case String:
case puerts::String:
return FV8Utils::V8String(Isolate, Value.Str.c_str());
case NativeObject:
case puerts::NativeObject:
return Value.Persistent.Get(Isolate);
case Function:
case puerts::Function:
return Value.FunctionPtr->GFunction.Get(Isolate);
case JsObject:
case puerts::JsObject:
return Value.JSObjectPtr->GObject.Get(Isolate);
case Boolean:
case puerts::Boolean:
return v8::Boolean::New(Isolate, Value.Boolean);
case ArrayBuffer:
case puerts::ArrayBuffer:
return Value.Persistent.Get(Isolate);
default:
return v8::Undefined(Isolate);
Expand Down
15 changes: 0 additions & 15 deletions unity/native_src/Src/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ LogCallback GLogCallback = nullptr;
LogCallback GLogWarningCallback = nullptr;
LogCallback GLogErrorCallback = nullptr;

#ifdef __cplusplus
extern "C" {
#endif

V8_EXPORT void SetLogCallback(LogCallback Log, LogCallback LogWarning, LogCallback LogError)
{
GLogCallback = Log;
GLogWarningCallback = LogError;
GLogErrorCallback = LogWarning;
}

#ifdef __cplusplus
}
#endif

namespace PUERTS_NAMESPACE
{

Expand Down
13 changes: 13 additions & 0 deletions unity/native_src/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,19 @@ V8_EXPORT void LogicTick(v8::Isolate *Isolate)
return JsEngine->LogicTick();
}

typedef void(*LogCallback)(const char* value);

extern LogCallback GLogCallback = nullptr;
extern LogCallback GLogWarningCallback = nullptr;
extern LogCallback GLogErrorCallback = nullptr;

V8_EXPORT void SetLogCallback(LogCallback Log, LogCallback LogWarning, LogCallback LogError)
{
GLogCallback = Log;
GLogWarningCallback = LogError;
GLogErrorCallback = LogWarning;
}

//-------------------------- end debug --------------------------

#ifdef __cplusplus
Expand Down

0 comments on commit 2611136

Please sign in to comment.