Note that there are some explanatory texts on larger screens.

plurals
  1. POWait for Asynchronous Event in Lua
    primarykey
    data
    text
    <p>I have a library in Lua that creates and parses data packets for a protocol. When I send a packet out, I'm expecting a reply back from the destination that is then parsed into a table. I'm trying to write a wrapper around this library so that I can make a function call like the following: <code>result = SendUnicast(dest,packetData)</code> and have the parsed response table returned to result. </p> <p>My problem is two fold: 1) The incoming message comes in asynchronously and on a different thread than the executing script and 2) the next packet I receive isn't necessarily the response for my request, I have to parse the incoming packet and match a sequence id.</p> <p>The program flow currently looks something like:</p> <p>[C# UI Thread]</p> <ul> <li>Button Click </li> <li>Run Lua Script <ul> <li>Call SendUnicast </li> <li>Wait For Response</li> </ul></li> </ul> <p>[C# Data Thread]</p> <ul> <li>Incoming Message <ul> <li>Pass message to Lua parser function</li> <li>if sequence matches waiting command, store parsed table, resume blocked</li> </ul></li> </ul> <p>[C# UI Thread]</p> <ul> <li>Lua scipt returns parsed table</li> </ul> <p>I can't seem to find a good method for blocking the currently executing script (in the UIThread). Creating a coroutine to be called when the message is parsed and then <code>while coroutine.status(co) ~= "dead"</code> seems to kill my lua interpreter.</p> <p><strong>EDIT</strong></p> <p>I'm marking BMitch's answer as accepted because it is the correct way to handle this issue. I will warn you, however, that LuaInterface does not support coroutines and I had to add support for them to the C# code myself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload