Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As already noted, there are several issues with the script that prevent you from getting what you want:</p> <ul> <li><code>os.execute("...")</code> is blocked until the command is completed and in your case it doesn't complete (as it runs an infinite loop). <strong>Solution:</strong> you need to detach that process from yours by using something like <code>io.popen()</code> instead of <code>os.execute()</code></li> <li><code>co = coroutine.create( startServer() )</code> doesn't create a coroutine in your case. <code>coroutine.create</code> call accepts a function reference and you pass it the result of <code>startServer</code> call, which is <code>nil</code>. <strong>Solution:</strong> use <code>co = coroutine.create( startServer )</code> (note that parenthesis are dropped, so it's not a function call anymore).</li> <li>You are not yielding from your coroutines; if you want several coroutines to work together, they need to be cooperating by giving control to each other when appropriate. That's what <code>yield</code> command is for and that's why it's called <a href="http://www.lua.org/pil/9.4.html" rel="nofollow">non-preemptive multithreading</a>. <strong>Solution:</strong> you need to use a combination of <code>resume</code> and <code>yield</code> calls after you <code>create</code> your coroutine.</li> <li><code>startServer</code> doesn't need to be a coroutine as you are not giving control back to it; its only purpose is to start the server.</li> </ul> <p>In your case, the solution may not even need coroutines as all you need to do is: (1) start the server and let it detach from your process (for example, using <code>popen</code>) and (2) work with your process using whatever communication protocol it requires (pipes, sockets, etc.).</p> <p>There are more complex and complete solutions (like <a href="https://github.com/LuaLanes/lanes" rel="nofollow">LuaLanes</a>) and also several good descriptions on creating <a href="http://williamaadams.wordpress.com/2013/01/30/lua-coroutines-getting-started/" rel="nofollow">simple coroutine dispatchers</a>.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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