Register - Login
Views: 99830658
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 09:15:09 PM
Jul - Computers and Technology - C# LuaInterface New poll - New thread - New reply
Next newer thread | Next older thread
Zero One
5170
And as we fall the spirit carries on,
That a hero'll come and save us all,
As we call the ones we left below,
We all dream of the day we rise above
Level: 129


Posts: 4566/5173
EXP: 24573391
For next: 476263

Since: 05-24-10

From: Delta Quadrant

Since last post: 1.6 years
Last activity: 131 days

Posted on 09-14-13 04:25:10 AM (last edited by Zero One at 09-14-13 01:10:01 PM) Link | Quote
I'm using LuaInterface to allow me to call Lua scripts in a C# program. I have a Lua script that contains the following code:

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

and in C#, I'm trying to add the output to a Queue<string> by doing:

sendQueue.Enqueue(lua.DoFile(script)[0].ToString());

The Lua script returns an Object[] and the zeroth index is meant to contain a string. However, the Lua script only ever returns 'nil', instead of teststring. Any one have any ideas as to how I can fix this?

EDIT: Solution found!

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

No idea why it works, just that it does.

____________________
This is a Heisenberg post. I know I posted this really fast, but I don't know where...
My YouTube Channel and Triggernometry Class!
Crossover - The Comic!
My Livestream. Check it! And now, check out my Twitch!
3DS Code: 2879-0110-5138

Sukasa

Level: 123


Posts: 4191/4326
EXP: 20936850
For next: 294416

Since: 07-07-07


Since last post: 1.1 years
Last activity: 1.1 years

Posted on 09-14-13 03:33:28 PM Link | Quote
What does the documentation for First() say?

____________________
Zero One
5170
And as we fall the spirit carries on,
That a hero'll come and save us all,
As we call the ones we left below,
We all dream of the day we rise above
Level: 129


Posts: 4568/5173
EXP: 24573391
For next: 476263

Since: 05-24-10

From: Delta Quadrant

Since last post: 1.6 years
Last activity: 131 days

Posted on 09-14-13 03:36:21 PM Link | Quote
Returns the first element in a sequence. I'm quite certain that First() is part of C# generics and not to do with Lua.

____________________
This is a Heisenberg post. I know I posted this really fast, but I don't know where...
My YouTube Channel and Triggernometry Class!
Crossover - The Comic!
My Livestream. Check it! And now, check out my Twitch!
3DS Code: 2879-0110-5138

Next newer thread | Next older thread
Jul - Computers and Technology - C# LuaInterface New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

28 database queries.
Query execution time: 0.082009 seconds
Script execution time: 0.007781 seconds
Total render time: 0.089790 seconds