You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You love Lua but the runtime API is very weak and you don't want to handle and learn a lot of different luarock libraries? You came at the right place! This project aims to offer the bests of **Lua** and **NodeJS** together.
4
+
5
+
## Usage
6
+
7
+
You don't need `lua` installed to run demoon, but you need `node` and npm as well, firstly, install demoon globally:
8
+
9
+
```sh
10
+
$: npm i -g demoon
11
+
```
12
+
13
+
Then run it passing your entry lua file:
14
+
15
+
```sh
16
+
$: demoon app.lua
17
+
```
18
+
19
+
## Example
20
+
21
+
This is a little sample code to demonstrate how demoon is powerful and bridges well with nodeJS:
22
+
```lua
23
+
-- you can require node modules (package.json/node_modules works as well)
24
+
localhttp=require('http')
25
+
26
+
-- you can require js modules and lua files
27
+
-- require('./myjsmodule.js')
28
+
-- require('./myluamodule.lua')
29
+
30
+
localport=os.getenv('PORT') or8080
31
+
32
+
functionsleep(ms)
33
+
-- you can use and create promises
34
+
returnPromise.create(function(resolve)
35
+
setTimeout(resolve, ms)
36
+
end)
37
+
end
38
+
39
+
-- top level await works!
40
+
sleep(1000):await()
41
+
42
+
http.createServer(async(function (req, res)
43
+
-- you can await inside async bounded functions
44
+
sleep(1000):await()
45
+
46
+
res:write('Hello World!');
47
+
-- because end is a lua keyword you have to put the '_'
48
+
res:_end();
49
+
end)):listen(port);
50
+
51
+
print('Your server is running on port ' ..port..'!')
0 commit comments