Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将ByteArray从C#函数传递到Lua代码_C#_Lua_Bytearray - Fatal编程技术网

将ByteArray从C#函数传递到Lua代码

将ByteArray从C#函数传递到Lua代码,c#,lua,bytearray,C#,Lua,Bytearray,我使用基于C#的GUI与Lua引擎进行接口。我搜索了帮助,但我没有得到正确的解决方案,而且我无法在Lua方面做太多更改,因为LuaInterface.dll已提供给我,无法更改 在C#中,我有一个函数,如下所示: public Int32 Calculate_Func(string input,out Byte[] byte_arr) { byte_arr = Process(input); return 1; } 在Lua中,我将上述函数称为: ret, val = Calculat

我使用基于C#的GUI与Lua引擎进行接口。我搜索了帮助,但我没有得到正确的解决方案,而且我无法在Lua方面做太多更改,因为LuaInterface.dll已提供给我,无法更改

在C#中,我有一个函数,如下所示:

public Int32 Calculate_Func(string input,out Byte[] byte_arr)
{
  byte_arr = Process(input);
  return 1;
}
在Lua中,我将上述函数称为:

ret, val = Calculate_Func(Packet_String)
但是我看到字节数组没有反映在我的Lua函数中。当我尝试读取
val
变量的值时,它返回
System.Byte[]
。我无法访问Lua中的字节数组值

但如果我将字节数组更改为字符串,则返回值,但我需要在Lua中处理字节。我怎样才能做到这一点

试试这个:

public Int32 Calculate_Func(string input, out LuaTable byte_arr)
{
    byte[] arr = Process(input);
    byte_arr = (LuaTable)lua.DoString("return {"+String.Join(",", byte_arr)+"}");
    return 1;
}
试试这个:

public Int32 Calculate_Func(string input, out LuaTable byte_arr)
{
    byte[] arr = Process(input);
    byte_arr = (LuaTable)lua.DoString("return {"+String.Join(",", byte_arr)+"}");
    return 1;
}

您的编组库似乎无法将
System.Byte[]
转换为LUA缓冲区,并将其作为用户数据传输到LUA。您可以尝试转换为一些不同的类型,例如
char[]
,可能是
LuaInterface.dll
熟悉的类型。检查
LuaInterface.dll的导出会很方便-据我所知,它必须导出用于来回封送类型的函数。似乎您的封送库无法将
System.Byte[]
转换为LUA缓冲区,并将其作为用户数据传输到LUA。您可以尝试转换为一些不同的类型,例如
char[]
,可能是
LuaInterface.dll
熟悉的类型。检查
LuaInterface.dll的导出会很方便-据我所知,它必须导出用于来回封送类型的函数。