title: Accessing a struct using MoonSharp Lua
body: <p>I am having problems changing members of a struct, which is a member of a class via the Lua interpreter MoonSharp.</p>
  <p>My current test setup looks something like this:</p>
  <pre><code>class VectorClass
  {
      public float X;
      public float Y;
  
      public Vector2(float X, float Y)
      {
          this.X = X;
          this.Y = Y;
      }
  }
  
  struct VectorStruct
  {
      public float X;
      public float Y;
  
      public Vector2(float X, float Y)
      {
          this.X = X;
          this.Y = Y;
      }
  }
  </code></pre>
  <p>For testing I have the vector object as a class and as a struct.</p>
  <pre><code>[MoonSharpUserData]
  class MyClass
  {
      public VectorClass VClass;
      public VectorStruct VStruct;
      
      public MyClass()
      {
          VClass = new VectorClass(0,0);
          VStruct = new VectorStruct(0, 0);
      }
  }
  </code></pre>
  <p>This is the class which contains the struct/class.</p>
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Script script = new Script();
          MyClass classic = new MyClass();
  
  
          string scriptString = @&quot;
                  function changeVelocity()
                      MyClass.VStruct.X = 10
                      MyClass.VClass.X = 10
                  end&quot;;
  
          UserData.RegisterAssembly();
          UserData.RegisterType&lt;VectorClass&gt;();
          UserData.RegisterType&lt;VectorStruct&gt;();
  
          script.Globals[&quot;MyClass&quot;] = classic;
          script.DoString(scriptString);
          script.Call(script.Globals.Get(&quot;changeVelocity&quot;));
  
          Console.WriteLine(&quot;Class: &quot; + classic.VClass.X);
          Console.WriteLine(&quot;Struct: &quot; + classic.VStruct.X);
  
          Console.ReadKey();
      }
  }
  </code></pre>
  <p>In my main program I try to change the value of the struct and the class (only x) but it only works with the class.</p>
  <p>I think there is some problem with the class being a Value-Type and not a Reference type.
  The API I'm working with uses a struct, which forces me to get the struct access to work but I can't even use a MoonSharp ProxyType.</p>
  <p>Does anyone know a workaround without rewriting the code completely?</p>