Skip to content

Commit

Permalink
[unity]重构,plugin的名字空间可支持定制
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 22, 2024
1 parent eca8165 commit a8e5094
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 80 deletions.
3 changes: 2 additions & 1 deletion unity/native_src/Inc/BackendEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <map>
#include <algorithm>
#include "Common.h"
#include "Log.h"
#include "V8InspectorImpl.h"
#if WITH_QUICKJS
Expand All @@ -27,7 +28,7 @@

#endif

namespace puerts
namespace PUERTS_NAMESPACE
{
class BackendEnv
{
Expand Down
44 changes: 44 additions & 0 deletions unity/native_src/Inc/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Tencent is pleased to support the open source community by making Puerts available.
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
* Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may be subject to their corresponding license terms.
* This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code package.
*/

#pragma once

#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
{

typedef void (*FuncPtr)(void);


enum JsValueType
{
NullOrUndefined = 1,
BigInt = 2,
Number = 4,
String = 8,
Boolean = 16,
NativeObject = 32,
JsObject = 64,
Array = 128,
Function = 256,
Date = 512,
ArrayBuffer = 1024,
Unknow = 2048,
};


}

4 changes: 3 additions & 1 deletion unity/native_src/Inc/ExecuteModuleJSCode.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace puerts
#include "Common.h"

namespace PUERTS_NAMESPACE
{
static const char* ExecuteModuleJSCode = " \n"
"(function() { \n"
Expand Down
7 changes: 4 additions & 3 deletions unity/native_src/Inc/JSEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <mutex>
#include <string>
#include <memory>
#include "Common.h"

#pragma warning(push, 0)
#include "libplatform/libplatform.h"
Expand All @@ -31,6 +32,8 @@

#endif

namespace PUERTS_NAMESPACE
{
typedef char* (*CSharpModuleResolveCallback)(const char* identifer, int32_t jsEnvIdx, char*& pathForDebug);

typedef void(*CSharpFunctionCallback)(v8::Isolate* Isolate, const v8::FunctionCallbackInfo<v8::Value>& Info, void* Self, int ParamLen, int64_t UserData);
Expand All @@ -39,8 +42,6 @@ typedef void* (*CSharpConstructorCallback)(v8::Isolate* Isolate, const v8::Funct

typedef void(*CSharpDestructorCallback)(void* Self, int64_t UserData);

namespace puerts
{
struct FCallbackInfo
{
FCallbackInfo(bool InIsStatic, CSharpFunctionCallback InCallback, int64_t InData) : IsStatic(InIsStatic), Callback(InCallback), Data(InData) {}
Expand Down Expand Up @@ -146,7 +147,7 @@ class JSEngine

int32_t Idx;

puerts::BackendEnv BackendEnv;
BackendEnv BackendEnv;

private:
std::vector<FCallbackInfo*> CallbackInfos;
Expand Down
5 changes: 3 additions & 2 deletions unity/native_src/Inc/JSFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vector>
#include <string>
#include "Common.h"

#pragma warning(push, 0)
#include "libplatform/libplatform.h"
Expand All @@ -19,7 +20,7 @@

#define FUNCTION_INDEX_KEY "_psid"

namespace puerts
namespace PUERTS_NAMESPACE
{
class JSObject
{
Expand Down Expand Up @@ -47,7 +48,7 @@ struct FValue
bool Boolean;
int64_t BigInt;
class JSFunction *FunctionPtr;
class puerts::JSObject *JSObjectPtr;
class JSObject *JSObjectPtr;
};
v8::UniquePersistent<v8::Value> Persistent;
};
Expand Down
5 changes: 3 additions & 2 deletions unity/native_src/Inc/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#pragma once

#include <string>
#include <string>
#include "Common.h"

namespace puerts
namespace PUERTS_NAMESPACE
{
enum LogLevel
{
Expand Down
19 changes: 2 additions & 17 deletions unity/native_src/Inc/V8Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,17 @@

#include <string>
#include <sstream>
#include "Common.h"

#pragma warning(push, 0)
#include "libplatform/libplatform.h"
#include "v8.h"
#pragma warning(pop)

namespace puerts
namespace PUERTS_NAMESPACE
{
const intptr_t OBJECT_MAGIC = 0xFA0E5D68; // a random value

enum JsValueType
{
NullOrUndefined = 1,
BigInt = 2,
Number = 4,
String = 8,
Boolean = 16,
NativeObject = 32,
JsObject = 64,
Array = 128,
Function = 256,
Date = 512,
ArrayBuffer = 1024,
Unknow = 2048,
};

class FV8Utils
{
public:
Expand Down
Loading

0 comments on commit a8e5094

Please sign in to comment.