C# LuaInterface How to get System.String from a Lua string

774 views Asked by At

I recently started using LuaInterface in order to be able to run Lua scripts from a C# program. I wrote a test script which returns a string:

teststring = "PRIVMSG #```` : SUCCESS!"
return testring

I then try and add it to a C# Queue<string> by doing:

sendQueue.Enqueue(lua.DoFile(script).ToString());

However, this doesn't return a string. Instead, it returns System.Object[]. How do I get it to return System.String instead?

1

There are 1 answers

0
Zero One On BEST ANSWER

A friend of mine managed to stumble upon the answer. In order to get it to produce an actual string, you should do the following:

var output = lua.DoFile(script).First().ToString();
Console.WriteLine(output);
sendQueue.Enqueue(output);

I don't understand why this method works, just that it does.