Event loop mystery using lit or luvi

85 views
Skip to first unread message

develephant

unread,
Jul 7, 2017, 5:02:33 PM7/7/17
to luvit
Hi,

I have an server app that runs perfectly using:

luvit /path/to/main.lua

When the process starts, it sits and waits patiently for connections.

I want to compile it into a standalone app, so I've made the needed adjustments to use lit make to do so. But, when running the app using Luvi, or compiling using Lit, the event loop seems to never "catch" and the app exits as soon as its started.

Through debugging I can see that all of the proper areas are being hit, and the server object is present. Te be sure I wasn't totally nuts, I created a very simple `net` server, and the results are the same whether using luvi or lit make.

The test project tree looks like:

rootDir/
  libs
  main
.lua
  luvit
-loader.lua
 
package.lua


The package.lua contains:

 
return {
   name
= "develephant/project-name",
   version
= "0.0.1",
   description
= "A simple description of my little package.",
   tags
= { "lua", "lit", "luvit" },
   license
= "MIT",
   author
= { name = "develephant", email = "<email>" },
   homepage
= "https://github.com/develephant/project-name",
   luvi
= {
     version
= "v2.7.6",
     flavor
= "regular",
   
},
   dependencies
= {
     
"luvit/luvit"
   
},
   files
= {
     
"**.lua",
     
"!test*"
   
}
 
}

I've created a simple test `main.lua` which looks like:

local bundle = require('luvi').bundle
loadstring
(bundle.readfile("luvit-loader.lua"), "bundle:luvit-loader.lua")()

local net = require('net')

local server = net.createServer(function(client)
 
print("Client connected")
end)

server
:on('error', function(err)
 
if err then error(err) end
end)

server
:listen(7173)

When running the app with luvit /path/to/main.lua I need to comment out the first 2 lines (which makes sense), and it works great.

But...when using luvi ./path/to/app /path/to/bin/luvit the app exits as soon as its started. If I use luvi /path/to/bin/luvit ./path/to/app then the Luvit REPL starts.

When using lit make ./path/to/app it compiles without error, but again the event loop just doesn't seem to "catch" and the app exits.

Again, I can see the server object using p(server), but no luck on getting it to "listen" for connections.

Any ideas on what I'm missing?

Thanks in advance,
-dev


Ryan Liptak

unread,
Jul 9, 2017, 2:33:43 PM7/9/17
to luvit
You're missing
uv.run()
to start the event loop.

See also https://github.com/luvit/luvit/blob/master/init.lua#L47-L68 for what Luvit does with regards to starting and cleaning up the event loop.

develephant

unread,
Jul 11, 2017, 8:32:48 AM7/11/17
to luvit
Works like a charm. Thank you for your help.

-dev
Reply all
Reply to author
Forward
0 new messages