void JSBModuleWriter::GenerateSource(String& sourceOut)
{
    source_ = "// This file was autogenerated by JSBind, changes will be lost\n";

    source_ += "#ifdef ATOMIC_PLATFORM_WINDOWS\n";

    source_ += "#pragma warning(disable: 4244) // possible loss of data\n";

    source_ += "#endif\n";

    if (module_->Requires("3D"))
    {
        source_ += "#ifdef ATOMIC_3D\n";
    }

    source_ += "#include <Duktape/duktape.h>\n";
    source_ += "#include <AtomicJS/Javascript/JSVM.h>\n";
    source_ += "#include <AtomicJS/Javascript/JSAPI.h>\n";

    WriteIncludes(source_);

    String ns = module_->GetPackage()->GetNamespace();

    if (ns != "Atomic")
    {
        source_ += "\n\nusing namespace " + ns + ";\n\n";
    }

    source_ += "\n\nnamespace Atomic\n{\n \n";

    source_ += "// Begin Class Declarations\n";

    WriteForwardDeclarations(source_);

    source_ += "// End Class Declarations\n\n";

    source_ += "// Begin Classes\n";

    Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();

    for (unsigned i = 0; i < classes.Size(); i++)
    {
        JSBClassWriter clsWriter(classes[i]);
        clsWriter.GenerateSource(source_);
    }

    source_ += "// End Classes\n\n";

    WriteClassDeclaration(source_);

    WriteClassDefine(source_);

    WriteModulePreInit(source_);

    WriteModuleInit(source_);

    // end Atomic namespace
    source_ += "\n}\n";

    if (module_->Requires("3D"))
    {
        source_ += "#endif //ATOMIC_3D\n";
    }

    sourceOut = source_;
}
示例#2
0
void JSBModule::EmitSource(const String& filepath)
{
    File file(JSBind::context_);
    file.Open(filepath, FILE_WRITE);

    source_ = "// This file was autogenerated by JSBind, changes will be lost\n";

    if (Requires("3D"))
    {
        source_ += "#ifdef ATOMIC_3D\n";
    }

    source_ += "#include <Duktape/duktape.h>\n";    
    source_ += "#include <AtomicJS/Javascript/JSVM.h>\n";
    source_ += "#include <AtomicJS/Javascript/JSAPI.h>\n";

    WriteIncludes(source_);

    source_ += "\n\nnamespace Atomic\n{\n \n";

    source_ += "// Begin Class Declarations\n";

    for (unsigned i = 0; i < classes_.Size(); i++)
    {
        classes_[i]->WriteForwardDeclarations(source_);
    }

    source_ += "// End Class Declarations\n\n";

    source_ += "// Begin Classes\n";

    for (unsigned i = 0; i < classes_.Size(); i++)
    {
        classes_[i]->Write(source_);
    }

    source_ += "// End Classes\n\n";


    WriteClassDeclaration(source_);

    WriteClassDefine(source_);

    WriteModulePreInit(source_);

    WriteModuleInit(source_);

    // end Atomic namespace
    source_ += "\n}\n";

    if (Requires("3D"))
    {
        source_ += "#endif //ATOMIC_3D\n";
    }


    file.Write(source_.CString(), source_.Length());

    file.Close();

}
void JSModuleWriter::GenerateSource()
{
    String source = "// This file was autogenerated by JSBind, changes will be lost\n";

    source += "#ifdef ATOMIC_PLATFORM_WINDOWS\n";

    source += "#pragma warning(disable: 4244) // possible loss of data\n";

    source += "#endif\n";

    if (module_->Requires("3D"))
    {
        source += "#ifdef ATOMIC_3D\n";
    }

    source += "#include <Duktape/duktape.h>\n";
    source += "#include <AtomicJS/Javascript/JSVM.h>\n";
    source += "#include <AtomicJS/Javascript/JSAPI.h>\n";

    WriteIncludes(source);

    String ns = module_->GetPackage()->GetNamespace();

    if (ns != "Atomic")
    {
        source += "\n\nusing namespace " + ns + ";\n\n";
    }

    source += "\n\nnamespace Atomic\n{\n \n";

    source += "// Begin Class Declarations\n";

    WriteForwardDeclarations(source);

    source += "// End Class Declarations\n\n";

    source += "// Begin Classes\n";

    Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();

    for (unsigned i = 0; i < classes.Size(); i++)
    {
        JSClassWriter clsWriter(classes[i]);
        clsWriter.GenerateSource(source);
    }

    source += "// End Classes\n\n";

    WriteClassDeclaration(source);

    WriteClassDefine(source);

    WriteModulePreInit(source);

    WriteModuleInit(source);

    // end Atomic namespace
    source += "\n}\n";

    if (module_->Requires("3D"))
    {
        source += "#endif //ATOMIC_3D\n";
    }

    JSBind* jsbind = module_->GetSubsystem<JSBind>();

    String filepath = jsbind->GetDestNativeFolder() + "/JSModule" + module_->name_ + ".cpp";

    File file(module_->GetContext());
    file.Open(filepath, FILE_WRITE);
    file.Write(source.CString(), source.Length());
    file.Close();

}