Browse Source

Fixing a few errors in generated C#

JoshEngebretson 10 years ago
parent
commit
c16e7bc3d0

+ 1 - 25
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -17,7 +17,6 @@
 
 
 #include <AtomicJS/Javascript/Javascript.h>
 #include <AtomicJS/Javascript/Javascript.h>
 
 
-#include <ToolCore/ToolSystem.h>
 #include <ToolCore/ToolEnvironment.h>
 #include <ToolCore/ToolEnvironment.h>
 #include <ToolCore/License/LicenseEvents.h>
 #include <ToolCore/License/LicenseEvents.h>
 #include <ToolCore/License/LicenseSystem.h>
 #include <ToolCore/License/LicenseSystem.h>
@@ -28,11 +27,6 @@
 
 
 using namespace ToolCore;
 using namespace ToolCore;
 
 
-namespace ToolCore
-{
-    extern void jsapi_init_toolcore(JSVM* vm);
-}
-
 namespace AtomicEditor
 namespace AtomicEditor
 {
 {
 
 
@@ -63,7 +57,6 @@ void AEEditorApp::Start()
     SubscribeToEvent(E_JSERROR, HANDLER(AEEditorApp, HandleJSError));
     SubscribeToEvent(E_JSERROR, HANDLER(AEEditorApp, HandleJSError));
     SubscribeToEvent(E_EXITREQUESTED, HANDLER(AEEditorApp, HandleExitRequested));
     SubscribeToEvent(E_EXITREQUESTED, HANDLER(AEEditorApp, HandleExitRequested));
 
 
-    jsapi_init_toolcore(vm_);
     jsapi_init_editor(vm_);
     jsapi_init_editor(vm_);
 
 
     duk_get_global_string(vm_->GetJSContext(), "require");
     duk_get_global_string(vm_->GetJSContext(), "require");
@@ -84,24 +77,7 @@ void AEEditorApp::Setup()
 
 
     AEEditorCommon::Setup();
     AEEditorCommon::Setup();
 
 
-    ToolEnvironment* env = new ToolEnvironment(context_);
-    context_->RegisterSubsystem(env);
-
-    ToolSystem* system = new ToolSystem(context_);
-    context_->RegisterSubsystem(system);
-
-#ifdef ATOMIC_DEV_BUILD
-
-    if (!env->InitFromJSON())
-    {
-        ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
-        return;
-    }
-#else
-
-    env->InitFromPackage();
-
-#endif
+    ToolEnvironment* env = GetSubsystem<ToolEnvironment>();
 
 
     engineParameters_["WindowTitle"] = "AtomicEditor";
     engineParameters_["WindowTitle"] = "AtomicEditor";
     engineParameters_["WindowResizable"] = true;
     engineParameters_["WindowResizable"] = true;

+ 33 - 20
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -16,6 +16,9 @@
 #include <Atomic/Script/ScriptSystem.h>
 #include <Atomic/Script/ScriptSystem.h>
 #include <AtomicJS/Javascript/Javascript.h>
 #include <AtomicJS/Javascript/Javascript.h>
 
 
+#include <ToolCore/ToolSystem.h>
+#include <ToolCore/ToolEnvironment.h>
+
 #ifdef ATOMIC_DOTNET
 #ifdef ATOMIC_DOTNET
 #include <AtomicNET/NETCore/NETHost.h>
 #include <AtomicNET/NETCore/NETHost.h>
 #include <AtomicNET/NETCore/NETCore.h>
 #include <AtomicNET/NETCore/NETCore.h>
@@ -28,6 +31,14 @@ namespace Atomic
     void jsapi_init_atomicnet(JSVM* vm);
     void jsapi_init_atomicnet(JSVM* vm);
 }
 }
 
 
+using namespace ToolCore;
+
+namespace ToolCore
+{
+    extern void jsapi_init_toolcore(JSVM* vm);
+}
+
+
 namespace AtomicEditor
 namespace AtomicEditor
 {
 {
 
 
@@ -46,6 +57,8 @@ void AEEditorCommon::Start()
     vm_ = javascript->InstantiateVM("MainVM");
     vm_ = javascript->InstantiateVM("MainVM");
     vm_->InitJSContext();
     vm_->InitJSContext();
 
 
+    jsapi_init_toolcore(vm_);
+
 #ifdef ATOMIC_DOTNET
 #ifdef ATOMIC_DOTNET
     jsapi_init_atomicnet(vm_);
     jsapi_init_atomicnet(vm_);
 #endif
 #endif
@@ -68,34 +81,32 @@ void AEEditorCommon::Setup()
     Javascript* javascript = new Javascript(context_);
     Javascript* javascript = new Javascript(context_);
     context_->RegisterSubsystem(javascript);
     context_->RegisterSubsystem(javascript);
 
 
-#ifdef ATOMIC_DOTNET
-
-    // Instantiate and register the AtomicNET subsystem
-    SharedPtr<NETCore> netCore (new NETCore(context_));
-    context_->RegisterSubsystem(netCore);
-    String netCoreErrorMsg;
+    ToolEnvironment* env = new ToolEnvironment(context_);
+    context_->RegisterSubsystem(env);
 
 
 #ifdef ATOMIC_DEV_BUILD
 #ifdef ATOMIC_DEV_BUILD
 
 
-    String  assemblyLoadPaths = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
-
-#ifdef ATOMIC_PLATFORM_WINDOWS
+    if (!env->InitFromJSON())
+    {
+        ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
+        return;
+    }
+#else
 
 
-    String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
-    String coreCLRTPAPaths = ToString("%s/Submodules/CoreCLR/Windows/Debug/AnyCPU/TPA/", ATOMIC_ROOT_SOURCE_DIR);
-    coreCLRTPAPaths += ToString(";%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+    env->InitFromPackage();
 
 
-#else
-    String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
 #endif
 #endif
 
 
-#else
-    assert(0);
-#endif
+#ifdef ATOMIC_DOTNET
+
+    // Instantiate and register the AtomicNET subsystem
+    SharedPtr<NETCore> netCore (new NETCore(context_));
+    context_->RegisterSubsystem(netCore);
+    String netCoreErrorMsg;
 
 
-    NETHost::SetCoreCLRFilesAbsPath(coreCLRAbsPath);
-    NETHost::SetCoreCLRTPAPaths(coreCLRTPAPaths);
-    NETHost::SetCoreCLRAssemblyLoadPaths(assemblyLoadPaths);
+    NETHost::SetCoreCLRFilesAbsPath(env->GetNETCoreCLRAbsPath());
+    NETHost::SetCoreCLRTPAPaths(env->GetNETTPAPaths());
+    NETHost::SetCoreCLRAssemblyLoadPaths(env->GetNETAssemblyLoadPaths());
 
 
     if (!netCore->Initialize(netCoreErrorMsg))
     if (!netCore->Initialize(netCoreErrorMsg))
     {
     {
@@ -108,6 +119,8 @@ void AEEditorCommon::Setup()
     }
     }
 #endif
 #endif
 
 
+    ToolSystem* system = new ToolSystem(context_);
+    context_->RegisterSubsystem(system);
 
 
 }
 }
 
 

+ 15 - 0
Source/ToolCore/JSBind/CSharp/CSClassWriter.cpp

@@ -183,6 +183,7 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
     Dedent();
     Dedent();
 
 
     // managed functions
     // managed functions
+    bool wroteConstructor = false;
     for (unsigned i = 0; i < klass_->functions_.Size(); i++)
     for (unsigned i = 0; i < klass_->functions_.Size(); i++)
     {
     {
         JSBFunction* function = klass_->functions_.At(i);
         JSBFunction* function = klass_->functions_.At(i);
@@ -196,11 +197,25 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
         if (CSTypeHelper::OmitFunction(function))
         if (CSTypeHelper::OmitFunction(function))
             continue;
             continue;
 
 
+        if (function->IsConstructor())
+            wroteConstructor = true;
+
         CSFunctionWriter fwriter(function);
         CSFunctionWriter fwriter(function);
         fwriter.GenerateManagedSource(source);
         fwriter.GenerateManagedSource(source);
 
 
     }
     }
 
 
+    // There are some constructors being skipped (like HTTPRequest as it uses a vector of strings in args)
+    // Make sure we have at least a IntPtr version
+    if (!wroteConstructor)
+    {
+        LOGINFOF("WARNING: %s class didn't write a constructor, filling in generated native constructor");
+
+        line = ToString("public %s (IntPtr native) : base (native)\n", klass_->GetName().CString());
+        source += IndentLine(line);
+        source += IndentLine("{\n");
+        source += IndentLine("}\n\n");
+    }
 
 
     Dedent();
     Dedent();
 
 

+ 7 - 1
Source/ToolCore/JSBind/CSharp/CSModuleWriter.cpp

@@ -265,6 +265,12 @@ void CSModuleWriter::GenerateManagedEnumsAndConstants(String& source)
             //static const unsigned M_MIN_UNSIGNED = 0x00000000;
             //static const unsigned M_MIN_UNSIGNED = 0x00000000;
 //            /static const unsigned M_MAX_UNSIGNED = 0xffffffff;
 //            /static const unsigned M_MAX_UNSIGNED = 0xffffffff;
 
 
+            if (cname == "M_MIN_INT")
+                value = "int.MinValue";
+
+            if (cname == "M_INFINITY")
+                value = "float.MaxValue";
+
             if (value == "M_MAX_UNSIGNED")
             if (value == "M_MAX_UNSIGNED")
                 value = "0xffffffff";
                 value = "0xffffffff";
 
 
@@ -304,7 +310,7 @@ void CSModuleWriter::GenerateManagedEnumsAndConstants(String& source)
 
 
             String line = "public const " + managedType + " " + cname + " = " + value;
             String line = "public const " + managedType + " " + cname + " = " + value;
 
 
-            if (managedType == "float" && !line.EndsWith("f"))
+            if (managedType == "float" && !line.EndsWith("f") && IsDigit(line[line.Length()-1]))
                 line += "f";
                 line += "f";
 
 
             line += ";\n";
             line += ";\n";

+ 10 - 0
Source/ToolCore/ToolEnvironment.cpp

@@ -76,6 +76,16 @@ bool ToolEnvironment::InitFromJSON(bool atomicTool)
         SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
         SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
         SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
         SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
 
 
+        netAssemblyLoadPaths_ = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+        netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
+        netTPAPaths_ = ToString("%s/Submodules/CoreCLR/Windows/Debug/AnyCPU/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+        netTPAPaths_ += ToString(";%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+#else
+        String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
+#endif
+
         return true;
         return true;
     }
     }
 
 

+ 10 - 0
Source/ToolCore/ToolEnvironment.h

@@ -57,6 +57,11 @@ public:
     const String& GetPlayerDataDir() { return resourcePlayerDataDir_; }
     const String& GetPlayerDataDir() { return resourcePlayerDataDir_; }
     const String& GetEditorDataDir() { return resourceEditorDataDir_; }
     const String& GetEditorDataDir() { return resourceEditorDataDir_; }
 
 
+    /// AtomicNET
+    const String& GetNETCoreCLRAbsPath() { return netCoreCLRAbsPath_; }
+    const String& GetNETAssemblyLoadPaths() { return netAssemblyLoadPaths_; }
+    const String& GetNETTPAPaths() { return netTPAPaths_; }
+
     /// Data directories
     /// Data directories
     const String& GetDeploymentDataDir() { return toolBinary_; }
     const String& GetDeploymentDataDir() { return toolBinary_; }
 
 
@@ -94,6 +99,11 @@ private:
 
 
     String toolDataDir_;
     String toolDataDir_;
 
 
+    // AtomicNET
+    String netCoreCLRAbsPath_;
+    String netAssemblyLoadPaths_;
+    String netTPAPaths_;
+
     // resources
     // resources
     String resourceCoreDataDir_;
     String resourceCoreDataDir_;
     String resourcePlayerDataDir_;
     String resourcePlayerDataDir_;