本文整理汇总了C++中JSBClass::GetNativeName方法的典型用法代码示例。如果您正苦于以下问题:C++ JSBClass::GetNativeName方法的具体用法?C++ JSBClass::GetNativeName怎么用?C++ JSBClass::GetNativeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBClass
的用法示例。
在下文中一共展示了JSBClass::GetNativeName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenNativeFunctionParameterSignature
void CSTypeHelper::GenNativeFunctionParameterSignature(JSBFunction* function, String& sig)
{
JSBClass* klass = function->GetClass();
const Vector<JSBFunctionType*>& parameters = function->GetParameters();
Vector<String> args;
if (!function->IsConstructor() && !function->IsStatic())
{
args.Push(ToString("%s* self", klass->GetNativeName().CString()));
}
if (parameters.Size())
{
for (unsigned int i = 0; i < parameters.Size(); i++)
{
JSBFunctionType* ptype = parameters.At(i);
// ignore "Context" parameters
if (ptype->type_->asClassType())
{
JSBClassType* classType = ptype->type_->asClassType();
JSBClass* klass = classType->class_;
if (klass->GetName() == "Context")
{
continue;
}
args.Push(ToString("%s* %s", klass->GetNativeName().CString(), ptype->name_.CString()));
}
else
{
args.Push(CSTypeHelper::GetNativeTypeString(ptype) + " " + ptype->name_);
}
}
}
if (function->GetReturnClass() && function->GetReturnClass()->IsNumberArray())
{
args.Push(ToString("%s* returnValue", function->GetReturnClass()->GetNativeName().CString()));
}
if (function->GetReturnType())
{
JSBVectorType* vtype = function->GetReturnType()->type_->asVectorType();
if (vtype)
{
args.Push("ScriptVector* returnValue");
}
}
sig.Join(args, ", ");
}
示例2: GetNativeFunctionSignature
String CSTypeHelper::GetNativeFunctionSignature(JSBFunction* function, String& returnType)
{
if (function->Skip())
return String::EMPTY;
if (function->IsDestructor())
return String::EMPTY;
if (OmitFunction(function))
return String::EMPTY;
JSBClass* klass = function->GetClass();
JSBPackage* package = klass->GetPackage();
String fname = function->IsConstructor() ? "Constructor" : function->GetName();
returnType = "void";
if (function->IsConstructor())
{
returnType = "RefCounted*";
}
else if (function->GetReturnType())
{
if (function->IsConstructor())
{
returnType = ToString("%s*", klass->GetNativeName().CString());
}
else if (function->GetReturnClass())
{
if (!function->GetReturnClass()->IsNumberArray())
{
returnType = ToString("const %s*", function->GetReturnClass()->GetNativeName().CString());
}
}
else if (function->GetReturnType()->type_->asStringHashType())
{
returnType = "unsigned";
}
else
{
returnType = ToString("%s", CSTypeHelper::GetNativeTypeString(function->GetReturnType()).CString());
// ScriptVector is handled by a out parameter
if (returnType.Contains("ScriptVector"))
returnType = "void";
}
}
String sig;
GenNativeFunctionParameterSignature(function, sig);
String functionSig = ToString("csb_%s_%s_%s_%u(%s)",
package->GetName().CString(), klass->GetName().CString(),
fname.CString(), function->GetID(), sig.CString());
return functionSig;
}
示例3: WriteClassDeclaration
void JSBModuleWriter::WriteClassDeclaration(String& source)
{
Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();
source += "static void jsb_declare_classes(JSVM* vm)\n{\n";
source += "duk_context* ctx = vm->GetJSContext();\n";
String packageName = module_->GetPackage()->GetName();
for (unsigned i = 0; i < classes.Size(); i++)
{
JSBClass* klass = classes.At(i);
if (klass->IsNumberArray())
continue;
source.AppendWithFormat(" js_class_declare<%s>(vm, \"%s\", \"%s\", jsb_constructor_%s);\n", klass->GetNativeName().CString(), packageName.CString(), klass->GetName().CString(), klass->GetName().CString());
if (klass->HasProperties())
{
source.AppendWithFormat("js_class_push_propertyobject(vm, \"%s\", \"%s\");\n", packageName.CString(), klass->GetName().CString());
Vector<String> pnames;
klass->GetPropertyNames(pnames);
for (unsigned j = 0; j < pnames.Size(); j++)
{
JSBProperty* prop = klass->GetProperty(pnames[j]);
source.Append("duk_push_object(ctx);\n");
if (prop->getter_ && !prop->getter_->Skip())
{
source.AppendWithFormat("duk_push_c_function(ctx, jsb_class_%s_%s, 0);\n",
klass->GetName().CString(), prop->getter_->GetName().CString());
source.Append("duk_put_prop_string(ctx, -2, \"get\");\n");
}
if (prop->setter_ && !prop->setter_->Skip())
{
source.AppendWithFormat("duk_push_c_function(ctx, jsb_class_%s_%s, 1);\n",
klass->GetName().CString(), prop->setter_->GetName().CString());
source.Append("duk_put_prop_string(ctx, -2, \"set\");\n");
}
String propertyName = prop->GetCasePropertyName();
source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", propertyName.CString());
}
source.Append("duk_pop(ctx);\n");
}
}
source += "\n}\n\n";
}
示例4: WriteNativeFunction
void CSFunctionWriter::WriteNativeFunction(String& source)
{
JSBClass* klass = function_->GetClass();
JSBPackage* package = klass->GetPackage();
String fname = function_->IsConstructor() ? "Constructor" : function_->GetName();
String returnType;
String functionSig = CSTypeHelper::GetNativeFunctionSignature(function_, returnType);
String line;
line = ToString("ATOMIC_EXPORT_API %s %s\n",
returnType.CString(), functionSig.CString());
source += IndentLine(line);
source += IndentLine("{\n");
Indent();
source += "\n";
bool returnValue = false;
bool sharedPtrReturn = false;
String returnStatement;
if (returnType == "const char*")
{
returnValue = true;
source += IndentLine("static String returnValue;\n");
returnStatement = "returnValue = ";
}
else if (function_->GetReturnClass() && function_->GetReturnClass()->IsNumberArray())
{
returnStatement = "*returnValue = ";
}
else if (function_->GetReturnClass() && function_->GetReturnType()->isSharedPtr_)
{
returnStatement = ToString("SharedPtr<%s> returnValue = ", function_->GetReturnClass()->GetNativeName().CString());
sharedPtrReturn = true;
}
else
{
if (returnType != "void")
{
returnStatement = "return ";
}
}
String callSig;
GenNativeCallParameters(callSig);
if (!function_->isConstructor_)
{
if (function_->IsStatic())
{
line = ToString("%s%s::%s(%s);\n", returnStatement.CString(), klass->GetNativeName().CString(), function_->GetName().CString(), callSig.CString());
}
else
{
line = ToString("%sself->%s(%s);\n", returnStatement.CString(), function_->GetName().CString(), callSig.CString());
}
}
else
{
if (klass->IsAbstract())
{
line = "return 0; // Abstract Class\n";
}
else if (klass->IsObject())
{
if (callSig.Length())
line = ToString("return new %s(NETCore::GetContext(), %s);\n", klass->GetNativeName().CString(), callSig.CString());
else
line = ToString("return new %s(NETCore::GetContext());\n", klass->GetNativeName().CString());
}
else
{
line = ToString("return new %s(%s);\n", klass->GetNativeName().CString(), callSig.CString());
}
}
source += IndentLine(line);
if (sharedPtrReturn)
{
source += IndentLine("returnValue->AddRef();\n");
source += IndentLine("return returnValue;\n");
}
else if (returnType == "const char*")
{
source += IndentLine("return returnValue.CString();\n");
}
Dedent();
source += IndentLine("}\n");
//.........这里部分代码省略.........
示例5: WriteParameterMarshal
void JSFunctionWriter::WriteParameterMarshal(String& source)
{
// generate args
const Vector<JSBFunctionType*>& parameters = function_->GetParameters();
int cparam = 0;
if (parameters.Size())
{
for (unsigned int i = 0; i < parameters.Size(); i++, cparam++)
{
JSBFunctionType * ptype = parameters.At(i);
// ignore "Context" parameters
if (ptype->type_->asClassType())
{
JSBClassType* classType = ptype->type_->asClassType();
JSBClass* klass = classType->class_;
if (klass->GetName() == "Context")
{
cparam--;
continue;
}
}
String pstring = ptype->ToArgString(cparam);
const String& init = ptype->initializer_;
if (ptype->type_->asClassType())
{
JSBClassType* classType = ptype->type_->asClassType();
JSBClass* klass = classType->class_;
if (!klass->IsNumberArray())
{
if (init.Length())
{
source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? js_to_class_instance<%s>(ctx, %i, 0) : %s;\n",
pstring.CString(), cparam + 1, klass->GetNativeName().CString(), cparam, init.CString());
}
else
{
source.AppendWithFormat("%s = js_to_class_instance<%s>(ctx, %i, 0);\n",
pstring.CString(), klass->GetNativeName().CString(), cparam);
}
}
else
{
int elements = klass->GetNumberArrayElements();
String elementType = klass->GetArrayElementType();
source.AppendWithFormat("%s arrayData%i[%i];\n", elementType.CString(), cparam, elements);
if (init.Length())
{
source.AppendWithFormat("const %s& defaultArg%i = %s;\n", klass->GetNativeName().CString(), cparam, init.CString());
source.AppendWithFormat("if (duk_get_top(ctx) >= %i) {\n", cparam + 1);
}
for (int j = 0; j < elements; j++)
{
source.AppendWithFormat("duk_get_prop_index(ctx, %i, %i);\n", cparam, j);
source.AppendWithFormat("arrayData%i[%i] = (%s) duk_to_number(ctx, -1);\n", cparam, j, elementType.CString());
}
source.AppendWithFormat("duk_pop_n(ctx, %i);\n", elements);
if (init.Length())
{
source.Append("}\n");
source.AppendWithFormat("%s __arg%i(duk_get_top(ctx) >= %i ? (const %s *) arrayData%i : defaultArg%i.Data());\n",
klass->GetNativeName().CString(), cparam, cparam + 1, elementType.CString(), cparam, cparam);
}
else
{
source.AppendWithFormat("%s __arg%i(arrayData%i);\n", klass->GetNativeName().CString(), cparam, cparam);
}
}
}
else if (ptype->type_->asStringType() || ptype->type_->asStringHashType())
{
if (init.Length())
{
source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? duk_to_string(ctx, %i) : %s;\n", pstring.CString(), cparam + 1, cparam, init.CString());
}
else
{
source.AppendWithFormat("%s = duk_to_string(ctx, %i);\n", pstring.CString(), cparam);
}
}
else if (ptype->type_->asHeapPtrType())
{
if (init.Length())
{
source.AppendWithFormat("%s = duk_get_top(ctx) >= %i ? duk_get_heapptr(ctx, %i) : %s;\n", pstring.CString(), cparam + 1, cparam, init.CString());
}
//.........这里部分代码省略.........
示例6: WriteFunction
void JSFunctionWriter::WriteFunction(String& source)
{
JSBClass* klass = function_->class_;
source.AppendWithFormat("static int jsb_class_%s_%s(duk_context* ctx)\n{\n", klass->GetName().CString(), function_->name_.CString());
WriteParameterMarshal(source);
if (!function_->IsStatic())
{
source.Append("duk_push_this(ctx);\n");
source.AppendWithFormat("%s* native = js_to_class_instance<%s>(ctx, -1, 0);\n", klass->GetNativeName().CString(), klass->GetNativeName().CString());
}
// declare return value;
bool returnDeclared = false;
JSBFunctionType* returnType = function_->returnType_;
if (returnType)
{
if (returnType->type_->asStringType())
{
returnDeclared = true;
source.Append("const String& retValue = ");
}
else if (returnType->type_->asPrimitiveType())
{
returnDeclared = true;
JSBPrimitiveType* prtype = returnType->type_->asPrimitiveType();
if (prtype->kind_ == JSBPrimitiveType::Bool)
{
source.Append("bool retValue = ");
}
else
{
source.Append("double retValue = ");
}
}
else if (returnType->type_->asClassType())
{
JSBClassType* klassType = returnType->type_->asClassType();
if (returnType->isTemplate_)
{
returnDeclared = true;
source.AppendWithFormat("SharedPtr<%s> object = ", klassType->class_->GetNativeName().CString());
}
else if (klassType->class_->IsObject())
{
returnDeclared = true;
source.Append("const Object* object = ");
}
else if (klassType->class_->IsNumberArray())
{
returnDeclared = true;
if (returnType->isReference_)
source.AppendWithFormat("const %s& retValue = ", klassType->class_->GetName().CString());
else
source.AppendWithFormat(" %s retValue = ", klassType->class_->GetName().CString());
}
else
{
returnDeclared = true;
source.Append("const RefCounted* object = ");
}
}
else if (returnType->type_->asEnumType())
{
JSBEnumType* enumType = returnType->type_->asEnumType();
returnDeclared = true;
source.AppendWithFormat("%s retValue = ", enumType->enum_->GetName().CString());
}
else if (returnType->type_->asVectorType())
{
returnDeclared = true;
JSBVectorType* vtype = returnType->type_->asVectorType();
source.AppendWithFormat("const %s& retValue = ", vtype->ToString().CString());
}
}
const Vector<JSBFunctionType*>& parameters = function_->GetParameters();
if (function_->IsStatic())
{
source.AppendWithFormat("%s::%s(", klass->GetNativeName().CString(), function_->name_.CString());
}
else
{
if (function_->HasMutatedReturn())
{
source.AppendWithFormat("__arg%i = native->%s(", parameters.Size() - 1, function_->name_.CString());
}
else
{
source.AppendWithFormat("native->%s(", function_->name_.CString());
//.........这里部分代码省略.........
示例7: WriteConstructor
void JSFunctionWriter::WriteConstructor(String& source)
{
// TODO: refactor this
if (function_->name_ == "RefCounted")
{
source.Append("// finalizer may be called more than once\n" \
"static int jsb_finalizer_RefCounted(duk_context *ctx)\n" \
"{\n" \
"JSVM* vm = JSVM::GetJSVM(ctx);\n" \
\
"duk_get_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \
\
"if (!duk_is_boolean(ctx, -1))\n" \
"{\n" \
"RefCounted* ref = vm->GetObjectPtr(duk_get_heapptr(ctx, 0));\n" \
"vm->RemoveObject(ref);\n" \
"ref->ReleaseRef();\n" \
"duk_push_boolean(ctx, 1);\n" \
"duk_put_prop_index(ctx, 0, JS_INSTANCE_INDEX_FINALIZED);\n" \
"}\n" \
\
"return 0;\n" \
"}\n");
}
JSBClass* klass = function_->class_;
JSBClass* base = klass->GetBaseClass();
// Constructor
source.AppendWithFormat("duk_ret_t jsb_constructor_%s(duk_context* ctx)\n{\n", klass->GetName().CString());
source.Append( "\nJSVM* vm = JSVM::GetJSVM(ctx);\n" \
"duk_push_this(ctx);\n" \
"void *ptr = duk_get_heapptr(ctx, -1);\n" \
"duk_pop(ctx);\n\n");
source.Append(" if (!vm->GetObjectPtr(ptr, true))\n {\n");
if (!klass->IsAbstract() && !klass->IsNumberArray())
{
String marshal;
WriteParameterMarshal(marshal);
String sparams;
int cparam = 0;
const Vector<JSBFunctionType*>& parameters = function_->GetParameters();
for (unsigned i = 0; i < parameters.Size(); i++, cparam++)
{
JSBFunctionType * ptype = parameters.At(i);
String sarg;
if (ptype->type_->asClassType())
{
JSBClassType* classType = ptype->type_->asClassType();
JSBClass* klass = classType->class_;
if (klass->GetName() == "Context")
{
sarg = "vm->GetContext()";
cparam--;
}
}
if (!sarg.Length())
{
sarg.AppendWithFormat("__arg%i", cparam);
}
sparams += sarg;
if (i + 1 < parameters.Size())
sparams += ", ";
}
source.AppendWithFormat("if (!duk_get_top(ctx) || !duk_is_pointer(ctx, 0))\n"\
"{\n"\
"%s\n"\
"%s* native = new %s(%s);\n" \
"vm->AddObject(ptr, native, INSTANTIATION_JAVASCRIPT);\n"\
"}\n" \
"else if (duk_is_pointer(ctx, 0))\n" \
"{\n" \
"RefCounted* rc = (RefCounted*) duk_get_pointer(ctx, 0);\n" \
"vm->AddObject(ptr, rc, rc->GetInstantiationType());\n" \
"}\n", marshal.CString(), klass->GetNativeName().CString(), klass->GetNativeName().CString(), sparams.CString());
}
else
{
if (klass->IsAbstract())
source.Append("assert(0); // abstract class new'd\n");
if (klass->IsNumberArray())
//.........这里部分代码省略.........
示例8: WriteNativeFunction
void CSFunctionWriter::WriteNativeFunction(String& source)
{
JSBClass* klass = function_->GetClass();
JSBPackage* package = klass->GetPackage();
String fname = function_->IsConstructor() ? "Constructor" : function_->GetName();
String returnType;
String functionSig = CSTypeHelper::GetNativeFunctionSignature(function_, returnType);
String line;
line = ToString("ATOMIC_EXPORT_API %s %s\n",
returnType.CString(), functionSig.CString());
source += IndentLine(line);
source += IndentLine("{\n");
Indent();
source += "\n";
// vector marshal
bool hasVectorMarshal = false;
const Vector<JSBFunctionType*>& fparams = function_->GetParameters();
for (unsigned i = 0; i < fparams.Size(); i++)
{
JSBFunctionType* ftype = fparams[i];
// Interface
JSBClass* interface = 0;
if (ftype->type_->asClassType() && ftype->type_->asClassType()->class_->IsInterface())
{
// We need to downcast to the interface
// TODO: this assumes Object* is in hierarchy, how do we validate this?
interface = ftype->type_->asClassType()->class_;
line = ToString("%s = dynamic_cast<%s*>((Object*)%s);\n", ftype->name_.CString(), interface->GetNativeName().CString(), ftype->name_.CString());
source += IndentLine(line);
}
// Vector
JSBVectorType* vtype = ftype->type_->asVectorType();
if (!vtype)
continue;
JSBClassType* classType = vtype->vectorType_->asClassType();
if (!classType)
continue;
String className = classType->class_->GetName();
String vectorMarshal;
hasVectorMarshal = true;
if (vtype->isPODVector_)
{
const String& pname = ftype->name_;
source += IndentLine(ToString("PODVector<%s*> %s__vector;\n", className.CString(), pname.CString()));
source += IndentLine(ToString("if (%s) %s->AdaptToVector<%s*>(%s__vector);\n", pname.CString(), pname.CString(), className.CString(), pname.CString()));
}
else
{
// vectorMarshal = ToString("PODVector<%s*> %s__vector", className.CString(), ftype->name_.CString());
}
if (vectorMarshal.Length())
{
source += IndentLine(vectorMarshal);
vectorMarshal = String::EMPTY;
}
}
bool returnValue = false;
bool sharedPtrReturn = false;
String returnStatement;
if (returnType == "const char*")
{
returnValue = true;
source += IndentLine("static String returnValue;\n");
returnStatement = "returnValue = ";
}
else if (function_->GetReturnClass() && function_->GetReturnClass()->IsNumberArray())
{
returnStatement = "*returnValue = ";
}
else if (function_->GetReturnClass() && function_->GetReturnType()->isSharedPtr_)
{
returnStatement = ToString("SharedPtr<%s> returnValue = ", function_->GetReturnClass()->GetNativeName().CString());
sharedPtrReturn = true;
}
else if (function_->GetReturnType() && function_->GetReturnType()->type_->asVectorType())
{
//.........这里部分代码省略.........