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:
> require 'CLRPackage'
> import "System"
> tbl = {11,22,33,44}
> dbl_arr = Double[4]
> dbl_arr:GetValue(0)
> dbl_arr:GetValue(1)
> for i=0,3 do Console.WriteLine(dbl_arr:GetValue(i)) end
0
0
0
0
> for i,v in ipairs(tbl) do dbl_arr:SetValue(v,i-1) end
> for i=0,3 do Console.WriteLine(dbl_arr:GetValue(i)) end
11
22
33
44
>
However if I change the dbl_arr
to a Byte
array (dbl_arr = Byte[4]
), then I get the following error: (error object is not a string)
I was able to get a bit more information from the error by doing this:
suc,err = pcall(function() byte_arr:SetValue(12,0) end)
Now suc
is false and err
returns the following message:
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)
I tried doing Convert.ToByte(12)
and passing that in, but it still fails. I have a feeling its storing the intermediate results as a Lua 'number', which then automatically converts it to a C# Double. This is the only explanation I can come up with based on that error.
I've tried a bunch of different things with no luck. Any help would be appreciated.
I've also asked this question on Stackoverflow to try and get some answers. I thought I would try here since it seems like Lua would be used more by people involved with Wireshark.
asked 26 Aug '11, 06:54
SwDevMan81
36●3●6●12
accept rate: 50%
Off topic? You might get better results from stackoverflow.com.
I did try SO first, but didnt get any response. I was hoping someone here might have run into this while using Wireshark or might have some ideas. I've linked the SO question in my original question.