我试图将一个Lua表转换为一个C#字节数组。我能得到一个转换为双阵列工作方式如下:将表转换为字节数组
> 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
>
但是,如果我改变dbl_arr
到Byte
阵列(dbl_arr = Byte[4]
),然后我得到了以下错误:(error object is not a string)
我我试了一堆不同的东西,但没有运气。任何帮助,将不胜感激。
更新:
我能够这样做是为了得到错误更多的信息:
suc,err = pcall(function() byte_arr:SetValue(12,0) end)
现在suc
是假的,err
返回以下消息:
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)
我已经从here安装了luaforwindows。它的版本是5.1.4-45。我在运行Microsoft Windows XP专业版2002 Service Pack 3的
更新:
这是示例代码和当错误发生时
> require 'CLRPackage'
> import "System"
> tbl = {11,22,33,44}
> dbl_arr = Byte[4]
> for i,v in ipairs(tbl) do dbl_arr:SetValue(v,i-1) end <-- Error occurs here
哪里'dbl_arr'从何而来? –
@Nicol - 它只是我创建的Double数组:'dbl_arr = Double [4]' – SwDevMan81
不够公平。我的意思是'Double [4]'来自哪里。它是否使用某种metatable来使用[]创建对象? –