mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
Remove some format rule (#10919)
* remove some rules * format all codes with new format rule
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include "cocos/bindings/manual/jsb_conversions.h"
|
||||
#include "cocos/bindings/manual/jsb_global.h"
|
||||
|
||||
|
||||
#include "base/std/container/string.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -74,8 +73,8 @@ public:
|
||||
class CallInfo {
|
||||
public:
|
||||
CallInfo(const char *className, const char *methodName)
|
||||
: _className(className),
|
||||
_methodName(methodName) {}
|
||||
: _className(className),
|
||||
_methodName(methodName) {}
|
||||
|
||||
~CallInfo() {}
|
||||
|
||||
@@ -84,6 +83,7 @@ public:
|
||||
}
|
||||
|
||||
bool execute(const se::ValueArray &argv, se::Value &rval);
|
||||
|
||||
private:
|
||||
int _error{JSO_ERR_OK};
|
||||
ccstd::string _className;
|
||||
@@ -91,22 +91,23 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
using JsCallback = std::function<void(const ccstd::string&, const ccstd::string&)>;
|
||||
using JsCallback = std::function<void(const ccstd::string &, const ccstd::string &)>;
|
||||
|
||||
class ScriptNativeBridge{
|
||||
class ScriptNativeBridge {
|
||||
public:
|
||||
void callByNative(const ccstd::string& arg0, const ccstd::string& arg1);
|
||||
inline void setCallback(const JsCallback& cb){
|
||||
void callByNative(const ccstd::string &arg0, const ccstd::string &arg1);
|
||||
inline void setCallback(const JsCallback &cb) {
|
||||
_callback = cb;
|
||||
}
|
||||
static ScriptNativeBridge* bridgeCxxInstance;
|
||||
static ScriptNativeBridge *bridgeCxxInstance;
|
||||
se::Value jsCb;
|
||||
|
||||
private:
|
||||
JsCallback _callback{nullptr}; // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
ScriptNativeBridge* ScriptNativeBridge::bridgeCxxInstance{nullptr};
|
||||
ScriptNativeBridge *ScriptNativeBridge::bridgeCxxInstance{nullptr};
|
||||
bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Value &rval) {
|
||||
NSString *className = [NSString stringWithCString:_className.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *className = [NSString stringWithCString:_className.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *methodName = [NSString stringWithCString:_methodName.c_str() encoding:NSUTF8StringEncoding];
|
||||
|
||||
if (!className || !methodName) {
|
||||
@@ -125,7 +126,7 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Val
|
||||
_error = JSO_ERR_METHOD_NOT_FOUND;
|
||||
return false;
|
||||
}
|
||||
methodSel = NSSelectorFromString(methodName);
|
||||
methodSel = NSSelectorFromString(methodName);
|
||||
NSMethodSignature *methodSig = [targetClass methodSignatureForSelector:(SEL)methodSel];
|
||||
if (methodSig == nil) {
|
||||
_error = JSO_ERR_METHOD_NOT_FOUND;
|
||||
@@ -133,7 +134,7 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Val
|
||||
return false;
|
||||
}
|
||||
@try {
|
||||
int argc = (int)argv.size();
|
||||
int argc = (int)argv.size();
|
||||
NSUInteger argumentCount = [methodSig numberOfArguments];
|
||||
if (argumentCount != argc) {
|
||||
_error = JSO_ERR_INVALID_ARGUMENTS;
|
||||
@@ -145,8 +146,8 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Val
|
||||
[invocation setSelector:methodSel];
|
||||
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
ccstd::string argumentType = [methodSig getArgumentTypeAtIndex:i];
|
||||
const se::Value &arg = argv[i];
|
||||
ccstd::string argumentType = [methodSig getArgumentTypeAtIndex:i];
|
||||
const se::Value &arg = argv[i];
|
||||
|
||||
/* - (void)setArgument:(void *)argumentLocation atIndex:(NSInteger)idx;
|
||||
*
|
||||
@@ -219,8 +220,8 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Val
|
||||
}
|
||||
}
|
||||
|
||||
NSUInteger returnLength = [methodSig methodReturnLength];
|
||||
ccstd::string returnType = [methodSig methodReturnType];
|
||||
NSUInteger returnLength = [methodSig methodReturnLength];
|
||||
ccstd::string returnType = [methodSig methodReturnType];
|
||||
[invocation invoke];
|
||||
|
||||
if (returnLength > 0) {
|
||||
@@ -287,8 +288,7 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray &argv, se::Val
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ScriptNativeBridge::callByNative(const ccstd::string& arg0, const ccstd::string& arg1){
|
||||
void ScriptNativeBridge::callByNative(const ccstd::string &arg0, const ccstd::string &arg1) {
|
||||
_callback(arg0, arg1);
|
||||
}
|
||||
|
||||
@@ -308,10 +308,10 @@ SE_BIND_CTOR(JavaScriptObjCBridge_constructor, __jsb_JavaScriptObjCBridge_class,
|
||||
|
||||
static bool JavaScriptObjCBridge_callStaticMethod(se::State &s) {
|
||||
const auto &args = s.args();
|
||||
int argc = (int)args.size();
|
||||
int argc = (int)args.size();
|
||||
|
||||
if (argc >= 2) {
|
||||
bool ok = false;
|
||||
bool ok = false;
|
||||
ccstd::string clsName, methodName;
|
||||
ok = sevalue_to_native(args[0], &clsName);
|
||||
SE_PRECONDITION2(ok, false, "Converting class name failed!");
|
||||
@@ -334,7 +334,7 @@ static bool JavaScriptObjCBridge_callStaticMethod(se::State &s) {
|
||||
}
|
||||
SE_BIND_FUNC(JavaScriptObjCBridge_callStaticMethod)
|
||||
|
||||
static bool ScriptNativeBridge_getCallback(se::State &s){
|
||||
static bool ScriptNativeBridge_getCallback(se::State &s) {
|
||||
ScriptNativeBridge *cobj = (ScriptNativeBridge *)s.nativeThisObject();
|
||||
CC_ASSERT(cobj == ScriptNativeBridge::bridgeCxxInstance);
|
||||
s.rval() = cobj->jsCb;
|
||||
@@ -343,37 +343,36 @@ static bool ScriptNativeBridge_getCallback(se::State &s){
|
||||
}
|
||||
SE_BIND_PROP_GET(ScriptNativeBridge_getCallback)
|
||||
|
||||
static bool ScriptNativeBridge_setCallback(se::State &s){ //NOLINT(readability-identifier-naming)
|
||||
static bool ScriptNativeBridge_setCallback(se::State &s) { //NOLINT(readability-identifier-naming)
|
||||
auto *cobj = static_cast<ScriptNativeBridge *>(s.nativeThisObject());
|
||||
CC_ASSERT(cobj == ScriptNativeBridge::bridgeCxxInstance);
|
||||
const auto &args = s.args();
|
||||
se::Value jsFunc = args[0];
|
||||
cobj->jsCb = jsFunc;
|
||||
if(jsFunc.isNullOrUndefined())
|
||||
{
|
||||
if (jsFunc.isNullOrUndefined()) {
|
||||
cobj->setCallback(nullptr);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
CC_ASSERT(jsFunc.isObject() && jsFunc.toObject()->isFunction());
|
||||
s.thisObject()->attachObject(jsFunc.toObject());
|
||||
cobj->setCallback([jsFunc](const ccstd::string& arg0, const ccstd::string& arg1){
|
||||
cobj->setCallback([jsFunc](const ccstd::string &arg0, const ccstd::string &arg1) {
|
||||
se::AutoHandleScope hs;
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(arg0));
|
||||
if(!arg1.empty()) {
|
||||
if (!arg1.empty()) {
|
||||
args.push_back(se::Value(arg1));
|
||||
}
|
||||
jsFunc.toObject()->call(args, nullptr);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}SE_BIND_PROP_SET(ScriptNativeBridge_setCallback)
|
||||
}
|
||||
SE_BIND_PROP_SET(ScriptNativeBridge_setCallback)
|
||||
|
||||
static bool ScriptNativeBridge_sendToNative(se::State &s) { //NOLINT
|
||||
const auto &args = s.args();
|
||||
int argc = (int)args.size();
|
||||
if (argc >= 1 && argc < 3) {
|
||||
bool ok = false;
|
||||
bool ok = false;
|
||||
ccstd::string arg0;
|
||||
ok = sevalue_to_native(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "Converting first argument failed!");
|
||||
@@ -391,7 +390,6 @@ static bool ScriptNativeBridge_sendToNative(se::State &s) { //NOLINT
|
||||
}
|
||||
SE_BIND_FUNC(ScriptNativeBridge_sendToNative)
|
||||
|
||||
|
||||
bool register_javascript_objc_bridge(se::Object *obj) {
|
||||
se::Class *cls = se::Class::create("JavaScriptObjCBridge", obj, nullptr, _SE(JavaScriptObjCBridge_constructor));
|
||||
cls->defineFinalizeFunction(_SE(JavaScriptObjCBridge_finalize));
|
||||
@@ -405,8 +403,6 @@ bool register_javascript_objc_bridge(se::Object *obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
se::Class *__jsb_ScriptNativeBridge_class = nullptr; // NOLINT
|
||||
|
||||
static bool ScriptNativeBridge_finalize(se::State &s) { //NOLINT(readability-identifier-naming)
|
||||
@@ -438,6 +434,6 @@ bool register_script_native_bridge(se::Object *obj) { //NOLINT(readability-ident
|
||||
|
||||
return true;
|
||||
}
|
||||
void callScript(const ccstd::string& arg0, const ccstd::string& arg1){
|
||||
void callScript(const ccstd::string &arg0, const ccstd::string &arg1) {
|
||||
ScriptNativeBridge::bridgeCxxInstance->callByNative(arg0, arg1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user