void JSBModule::WriteClassDeclaration(String& source) { source += "static void jsb_declare_classes(JSVM* vm)\n{\n"; source += "duk_context* ctx = vm->GetJSContext();\n"; for (unsigned i = 0; i < classes_.Size(); i++) { JSBClass* klass = classes_.At(i); if (klass->isNumberArray()) continue; source.AppendWithFormat(" js_class_declare(vm, \"%s\", jsb_constructor_%s);\n", klass->GetName().CString(), klass->GetName().CString()); if (klass->hasProperties()) { source.AppendWithFormat("js_class_push_propertyobject(vm, \"%s\");\n", 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_->name_.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_->name_.CString()); source.Append("duk_put_prop_string(ctx, -2, \"set\");\n"); } pnames[j][0] = tolower(pnames[j][0]); source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n", pnames[j].CString()); } source.Append("duk_pop(ctx);\n"); } } source += "\n}\n\n"; }
void JSBModule::WriteClassDefine(String& source) { source += "static void jsb_init_classes(JSVM* vm)\n{\n"; for (unsigned i = 0; i < classes_.Size(); i++) { JSBClass* klass = classes_.At(i); if (klass->isNumberArray()) continue; source.AppendWithFormat(" jsb_class_define_%s(vm);\n", klass->GetName().CString()); } source += "\n}\n\n"; }