Browse Source

AS Bindings: Register long / unsgined long as separate type because it have different width on different systems (#2774)

1vanK 4 years ago
parent
commit
5bce5959b0
2 changed files with 24 additions and 2 deletions
  1. 13 2
      Source/Tools/BindingGenerator/ASUtils.cpp
  2. 11 0
      Source/Urho3D/AngelScript/Manual.cpp

+ 13 - 2
Source/Tools/BindingGenerator/ASUtils.cpp

@@ -33,6 +33,7 @@ namespace ASBindingGenerator
 {
 {
 
 
 // https://www.angelcode.com/angelscript/sdk/docs/manual/doc_datatypes_primitives.html
 // https://www.angelcode.com/angelscript/sdk/docs/manual/doc_datatypes_primitives.html
+// https://en.cppreference.com/w/cpp/language/types
 string CppFundamentalTypeToAS(const string& cppType)
 string CppFundamentalTypeToAS(const string& cppType)
 {
 {
     if (cppType == "char" || cppType == "signed char")
     if (cppType == "char" || cppType == "signed char")
@@ -47,10 +48,10 @@ string CppFundamentalTypeToAS(const string& cppType)
     if (cppType == "unsigned short")
     if (cppType == "unsigned short")
         return "uint16";
         return "uint16";
 
 
-    if (cppType == "int" || cppType == "long")
+    if (cppType == "int")
         return "int";
         return "int";
 
 
-    if (cppType == "unsigned" || cppType == "unsigned int" || cppType == "unsigned long")
+    if (cppType == "unsigned" || cppType == "unsigned int")
         return "uint";
         return "uint";
 
 
     if (cppType == "long long")
     if (cppType == "long long")
@@ -59,6 +60,16 @@ string CppFundamentalTypeToAS(const string& cppType)
     if (cppType == "unsigned long long")
     if (cppType == "unsigned long long")
         return "uint64";
         return "uint64";
 
 
+    // Types below have different width on different systems and are registered in Manual.cpp
+    if (cppType == "long")
+        return "long";
+
+    if (cppType == "unsigned long")
+        return "ulong";
+
+    if (cppType == "size_t")
+        return "size_t";
+
     return cppType;
     return cppType;
 }
 }
 
 

+ 11 - 0
Source/Urho3D/AngelScript/Manual.cpp

@@ -91,6 +91,17 @@ void ASRegisterManualLast_Urho2D(asIScriptEngine* engine);
 // This function is called before ASRegisterGenerated()
 // This function is called before ASRegisterGenerated()
 void ASRegisterManualFirst(asIScriptEngine* engine)
 void ASRegisterManualFirst(asIScriptEngine* engine)
 {
 {
+    if (sizeof(long) == 4)
+    {
+        engine->RegisterTypedef("long", "int");
+        engine->RegisterTypedef("ulong", "uint");
+    }
+    else
+    {
+        engine->RegisterTypedef("long", "int64");
+        engine->RegisterTypedef("ulong", "uint64");
+    }
+
     if (sizeof(size_t) == 4)
     if (sizeof(size_t) == 4)
         engine->RegisterTypedef("size_t", "uint");
         engine->RegisterTypedef("size_t", "uint");
     else
     else