Browse Source

Fix bugs with internalName accessor

Jeff Hutchinson 4 năm trước cách đây
mục cha
commit
98a2fa0f33

+ 3 - 2
Engine/source/console/astNodes.cpp

@@ -1304,12 +1304,13 @@ U32 InternalSlotAccessNode::compile(CodeStream& codeStream, U32 ip, TypeReq type
    ip = objectExpr->compile(codeStream, ip, TypeReqString);
    ip = objectExpr->compile(codeStream, ip, TypeReqString);
    codeStream.emit(OP_SETCUROBJECT);
    codeStream.emit(OP_SETCUROBJECT);
 
 
+   // we pop the stack as we will override the current object with the internal object
+   codeStream.emit(OP_POP_STK);
+
    ip = slotExpr->compile(codeStream, ip, TypeReqString);
    ip = slotExpr->compile(codeStream, ip, TypeReqString);
    codeStream.emit(OP_SETCUROBJECT_INTERNAL);
    codeStream.emit(OP_SETCUROBJECT_INTERNAL);
    codeStream.emit(recurse);
    codeStream.emit(recurse);
 
 
-   codeStream.emit(OP_POP_STK);
-
    return codeStream.tell();
    return codeStream.tell();
 }
 }
 
 

+ 5 - 0
Engine/source/console/compiledEval.cpp

@@ -1614,6 +1614,11 @@ ConsoleValue CodeBlock::exec(U32 ip, const char* functionName, Namespace* thisNa
                stack[_STK].setInt(0);
                stack[_STK].setInt(0);
             }
             }
          }
          }
+         else
+         {
+            Con::errorf(ConsoleLogEntry::Script, "%s: Attempt to use ->, but the group object wasn't found.", getFileLine(ip - 2));
+            stack[_STK].setInt(0);
+         }
          break;
          break;
 
 
       case OP_SETCUROBJECT_NEW:
       case OP_SETCUROBJECT_NEW:

+ 39 - 2
Engine/source/console/test/ScriptTest.cpp

@@ -544,7 +544,7 @@ TEST(Script, Basic_SimObject)
 TEST(Script, Internal_Name)
 TEST(Script, Internal_Name)
 {
 {
    ConsoleValue value = RunScript(R"(
    ConsoleValue value = RunScript(R"(
-         function SimObject::_internalCall(%this)
+         function TheFirstInner::_internalCall(%this)
          {
          {
             return 5;
             return 5;
          }
          }
@@ -552,7 +552,7 @@ TEST(Script, Internal_Name)
          function a()
          function a()
          {
          {
             %grp = new SimGroup();
             %grp = new SimGroup();
-            %obj = new SimObject()
+            %obj = new SimObject(TheFirstInner)
             {
             {
                internalName = "Yay";
                internalName = "Yay";
             };
             };
@@ -568,6 +568,43 @@ TEST(Script, Internal_Name)
    )");
    )");
 
 
    ASSERT_EQ(value.getInt(), 5);
    ASSERT_EQ(value.getInt(), 5);
+
+   ConsoleValue recursiveValue = RunScript(R"(
+         function SimGroup::doTheInternalCall(%this)
+         {
+            return %this-->Yeah._internalCall2();
+         }
+
+         function TheAnotherObject::_internalCall2(%this)
+         {
+            return %this.property;
+         }
+
+         function a()
+         {
+            %grp = new SimGroup();
+            %obj = new SimGroup()
+            {
+               internalName = "Yay2";
+
+               new SimObject(TheAnotherObject)
+               {
+                  internalName = "Yeah";
+                  property = 12;
+               };
+            };
+            %grp.add(%obj);
+
+            %val = %grp.doTheInternalCall();
+
+            %grp.delete();
+
+            return %val;
+         }
+         return a();      
+   )");
+
+   ASSERT_EQ(recursiveValue.getInt(), 12);
 }
 }
 
 
 TEST(Script, Basic_Package)
 TEST(Script, Basic_Package)