title: Convert table to Byte array
body: <p>I'm trying to convert a Lua Table to a C# Byte array.  I was able to get a conversion to a Double array to work as follows:</p>
  
  <pre><code>&gt; require 'CLRPackage'
  &gt; import "System"
  &gt; tbl = {11,22,33,44}
  &gt; dbl_arr = Double[4]
  &gt; dbl_arr:GetValue(0)
  &gt; dbl_arr:GetValue(1)
  &gt; for i=0,3 do Console.WriteLine(dbl_arr:GetValue(i)) end
  0
  0
  0
  0
  &gt; for i,v in ipairs(tbl) do dbl_arr:SetValue(v,i-1) end
  &gt; for i=0,3 do Console.WriteLine(dbl_arr:GetValue(i)) end
  11
  22
  33
  44
  &gt;
  </code></pre>
  
  <p>However if I change the <code>dbl_arr</code> to a <code>Byte</code> array (<code>dbl_arr = Byte[4]</code>), then I get the following error: <code>(error object is not a string)</code></p>
  
  <p>I've tried a bunch of different things with no luck.  Any help would be appreciated.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I was able to get a bit more information from the error by doing this:</p>
  
  <pre><code>suc,err = pcall(function() byte_arr:SetValue(12,0) end)
  </code></pre>
  
  <p>Now <code>suc</code> is false and <code>err</code> returns the following message:</p>
  
  <pre><code>SetValue failed
  System.ArgumentException: Cannot widen from source type to target type either
     because the source type is a not a primitive type or the conversion cannot
     be accomplished.
  at System.Array.InternalSetValue(Void* target, Object value)
  at System.Array.SetValue(Object value, Int32 index)
  </code></pre>
  
  <p>I've installed luaforwindows from <a href="http://code.google.com/p/luaforwindows/downloads/list" rel="nofollow">here</a>. It's version 5.1.4-45.  I'm running Microsoft Windows XP Professional Version 2002 Service Pack 3 </p>
  
  <p><strong>Update:</strong></p>
  
  <p>This is the example code and where the error occurs</p>
  
  <pre><code>&gt; require 'CLRPackage'
  &gt; import "System"
  &gt; tbl = {11,22,33,44}
  &gt; dbl_arr = Byte[4]
  &gt; for i,v in ipairs(tbl) do dbl_arr:SetValue(v,i-1) end &lt;-- Error occurs here
  </code></pre>