2018年8月26日日曜日

C#+ NLua (Byte Array)

I wanted to use Byte Array between Lua Script and C#.
I read many site, but I couldn't get solution,
I visit NLua site today and it was description of using dotnet object from Lua Script.
So I finally get solution as following.

C# code.


_lua = new NLua.Lua();
_lua.LoadCLRPackage();
_lua.RegisterFunction("SendData", this, this.GetType().GetMethod("SendData"));


public void SendData(object dat)
{
    byte[] byteData = (byte[])data;
    // you can use ByteData from Lua Script
}
  

Lua Sctipt



import ('System')

    byteData = Byte[4]  -- create 4 length Byte Array
    byteData[0] = 0x00
    byteData[1] = 0x11
    byteData[2] = 0x22
    byteData[3] = 0x33
    SendData(byteData)  -- Call C# Function from Lua
  

0 件のコメント: