一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Lua - Luvit像Node.js一樣寫Lua應用

Luvit像Node.js一樣寫Lua應用

2020-05-10 14:50liumiaocn Lua

今天小編就為大家分享一篇關于Luvit像Node.js一樣寫Lua應用,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

Luvit像Node.js一樣寫Lua應用

luvit是什么?它是目前Lua這個小眾語言中較為流行的一個開源框架,給那些習慣使用Lua的開發者一個機會向寫Node.js一樣用Lua進行開發,它是Lua的Node.js.在Gitlab上,項目的描述對于Luvit是這樣描述的:Lua + libUV + jIT = pure awesomesauce。

概要信息

Luvit像Node.js一樣寫Lua應用

安裝

提供了安裝腳本進行一鍵安裝,但是版本不是最新,如果需要最新的版本,可以從源碼開始

curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh

安裝日志

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
[root@kong ~]# curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh
 % Total  % Received % Xferd Average Speed  Time  Time   Time Current
                 Dload Upload  Total  Spent  Left Speed
100  127 100  127  0   0   57   0 0:00:02 0:00:02 --:--:--  57
100  567 100  567  0   0  192   0 0:00:02 0:00:02 --:--:-- 1788
Downloading https://github.com/luvit/luvi/releases/download/v2.7.6/luvi-regular-Linux_x86_64 to luvi
 % Total  % Received % Xferd Average Speed  Time  Time   Time Current
                 Dload Upload  Total  Spent  Left Speed
100  615  0  615  0   0  280   0 --:--:-- 0:00:02 --:--:--  280
100 4261k 100 4261k  0   0  481k   0 0:00:08 0:00:08 --:--:-- 1007k
Downloading https://lit.luvit.io/packages/luvit/lit/v3.5.4.zip to lit.zip
 % Total  % Received % Xferd Average Speed  Time  Time   Time Current
                 Dload Upload  Total  Spent  Left Speed
100 234k 100 234k  0   0 91459   0 0:00:02 0:00:02 --:--:-- 91488
lit version: 3.5.4
luvi version: v2.7.6
command: make lit.zip lit luvi
create config: /root/.litconfig
compiling filter: ** excludes by default (first rule is positive)
including: commands/README
including: commands/add.lua
including: commands/auth.lua
including: commands/claim.lua
including: commands/config.lua
including: commands/down.lua
including: commands/get-luvi.lua
including: commands/help.lua
including: commands/init.lua
including: commands/install.lua
including: commands/ls.lua
including: commands/make.lua
including: commands/publish.lua
including: commands/serve.lua
including: commands/share.lua
including: commands/sync.lua
including: commands/unclaim.lua
including: commands/up.lua
including: commands/update.lua
including: init.lua
including: libs/api.lua
including: libs/auto-updater.lua
including: libs/autoconfig.lua
including: libs/calculate-deps.lua
including: libs/codec.lua
including: libs/core.lua
including: libs/db-fs.lua
including: libs/db.lua
including: libs/exec.lua
including: libs/export-zip.lua
including: libs/export.lua
including: libs/get-installed.lua
including: libs/github-request.lua
including: libs/handlers.lua
including: libs/import.lua
including: libs/install-deps.lua
including: libs/log.lua
including: libs/metrics.lua
including: libs/pkg.lua
including: libs/rdb.lua
including: libs/rules.lua
including: libs/snapshots.lua
including: libs/stats.lua
including: libs/verify-signature.lua
including: libs/vfs.lua
including: luvit-loader.lua
including: main.lua
including: package.lua
including dependency: base64 (deps/base64.lua)
including dependency: coro-channel (deps/coro-channel.lua)
including dependency: coro-fs (deps/coro-fs.lua)
including dependency: coro-http (deps/coro-http.lua)
including dependency: coro-net (deps/coro-net.lua)
including dependency: coro-spawn (deps/coro-spawn.lua)
including dependency: coro-split (deps/coro-split.lua)
including dependency: coro-websocket (deps/coro-websocket.lua)
including dependency: coro-wrapper (deps/coro-wrapper.lua)
including dependency: git (deps/git/)
including dependency: http-codec (deps/http-codec.lua)
including dependency: json (deps/json.lua)
including dependency: md5 (deps/md5.lua)
including dependency: pathjoin (deps/pathjoin.lua)
including dependency: pretty-print (deps/pretty-print.lua)
including dependency: prompt (deps/prompt.lua)
including dependency: querystring (deps/querystring.lua)
including dependency: readline (deps/readline.lua)
including dependency: resource (deps/resource.lua)
including dependency: secure-socket (deps/secure-socket/)
including dependency: semver (deps/semver.lua)
including dependency: sha1 (deps/sha1.lua)
including dependency: ssh-rsa (deps/ssh-rsa.lua)
including dependency: ustring (deps/ustring.lua)
including dependency: weblit-app (deps/weblit-app.lua)
including dependency: weblit-auto-headers (deps/weblit-auto-headers.lua)
including dependency: weblit-websocket (deps/weblit-websocket.lua)
including dependency: websocket-codec (deps/websocket-codec.lua)
compiling filter: deps/git/** excludes by default (first rule is positive)
including: core.lua
including: db.lua
including: init.lua
including: package.lua
including: storage.lua
creating binary: /root/lit
using luvi from: /root/luvi
inserting luvi: /root/luvi
storing: commands/add.lua
compiling: commands/auth.lua (9.9% reduction)
storing: commands/claim.lua
storing: commands/config.lua
storing: commands/down.lua
compiling: commands/get-luvi.lua (20.7% reduction)
storing: commands/help.lua
compiling: commands/init.lua (14.9% reduction)
storing: commands/install.lua
compiling: commands/ls.lua (2.6% reduction)
storing: commands/make.lua
storing: commands/publish.lua
compiling: commands/serve.lua (19% reduction)
storing: commands/share.lua
storing: commands/sync.lua
storing: commands/unclaim.lua
storing: commands/up.lua
compiling: commands/update.lua (23.3% reduction)
compiling: deps/base64.lua (29.2% reduction)
compiling: deps/coro-channel.lua (19.7% reduction)
storing: deps/coro-fs.lua
compiling: deps/coro-http.lua (30.4% reduction)
compiling: deps/coro-net.lua (18.5% reduction)
compiling: deps/coro-spawn.lua (44% reduction)
compiling: deps/coro-split.lua (34.4% reduction)
compiling: deps/coro-websocket.lua (34.6% reduction)
compiling: deps/coro-wrapper.lua (66.1% reduction)
compiling: deps/git/core.lua (3.4% reduction)
compiling: deps/git/db.lua (18.7% reduction)
storing: deps/git/init.lua
storing: deps/git/package.lua
compiling: deps/git/storage.lua (34.5% reduction)
compiling: deps/http-codec.lua (37.2% reduction)
compiling: deps/json.lua (30.7% reduction)
storing: deps/md5.lua
compiling: deps/pathjoin.lua (33.5% reduction)
compiling: deps/pretty-print.lua (30.4% reduction)
compiling: deps/prompt.lua (43.4% reduction)
compiling: deps/querystring.lua (35.9% reduction)
compiling: deps/readline.lua (18.6% reduction)
compiling: deps/resource.lua (31.5% reduction)
compiling: deps/secure-socket/biowrap.lua (31.8% reduction)
compiling: deps/secure-socket/context.lua (27.4% reduction)
compiling: deps/secure-socket/init.lua (52.5% reduction)
storing: deps/secure-socket/package.lua
compiling: deps/semver.lua (28.2% reduction)
compiling: deps/sha1.lua (27.9% reduction)
compiling: deps/ssh-rsa.lua (16.2% reduction)
compiling: deps/ustring.lua (37.1% reduction)
compiling: deps/weblit-app.lua (14.8% reduction)
compiling: deps/weblit-auto-headers.lua (50.9% reduction)
compiling: deps/weblit-websocket.lua (35.8% reduction)
compiling: deps/websocket-codec.lua (18.2% reduction)
storing: init.lua
compiling: libs/api.lua (30.9% reduction)
compiling: libs/auto-updater.lua (29% reduction)
compiling: libs/autoconfig.lua (32.3% reduction)
compiling: libs/calculate-deps.lua (30.4% reduction)
compiling: libs/codec.lua (31.2% reduction)
compiling: libs/core.lua (14% reduction)
compiling: libs/db-fs.lua (29.5% reduction)
compiling: libs/db.lua (38.2% reduction)
compiling: libs/exec.lua (45.1% reduction)
compiling: libs/export-zip.lua (36.4% reduction)
compiling: libs/export.lua (36.6% reduction)
compiling: libs/get-installed.lua (45.9% reduction)
compiling: libs/github-request.lua (49.8% reduction)
compiling: libs/handlers.lua (18.1% reduction)
compiling: libs/import.lua (27.6% reduction)
compiling: libs/install-deps.lua (38.4% reduction)
compiling: libs/log.lua (60.7% reduction)
compiling: libs/metrics.lua (56.8% reduction)
compiling: libs/pkg.lua (36.9% reduction)
compiling: libs/rdb.lua (22.2% reduction)
compiling: libs/rules.lua (29.7% reduction)
compiling: libs/snapshots.lua (12.6% reduction)
compiling: libs/stats.lua (1.5% reduction)
compiling: libs/verify-signature.lua (40.8% reduction)
compiling: libs/vfs.lua (29.9% reduction)
compiling: luvit-loader.lua (29.8% reduction)
compiling: main.lua (24.3% reduction)
compiling: package.lua (14.8% reduction)
done building: /root/lit
done: success
lit version: 3.5.4
luvi version: v2.7.6
command: make lit://luvit/luvit luvit luvi
load config: /root/.litconfig
connecting: wss://lit.luvit.io/
fetching: 1 object
fetching: 1 object
fetching: 4 objects
using snapshot: ab0b6ace5a16a88e6fbb4c8da0083c40cf1d6803
creating binary: /root/luvit
using luvi from: /root/luvi
fetching: 1 object
fetching: 1 object
fetching: 27 objects
fetching: 16 objects
inserting luvi: /root/luvi
compiling: deps/buffer.lua (16.5% reduction)
compiling: deps/childprocess.lua (19.1% reduction)
compiling: deps/codec.lua (35.3% reduction)
compiling: deps/core.lua (57.3% reduction)
compiling: deps/dgram.lua (25.5% reduction)
compiling: deps/dns.lua (25.1% reduction)
compiling: deps/fs.lua (6.2% reduction)
compiling: deps/helpful.lua (42.7% reduction)
compiling: deps/hooks.lua (83.3% reduction)
compiling: deps/http-codec.lua (37.4% reduction)
compiling: deps/http-header.lua (59.4% reduction)
compiling: deps/http.lua (29.6% reduction)
compiling: deps/https.lua (45.6% reduction)
compiling: deps/json.lua (30.7% reduction)
compiling: deps/los.lua (76.9% reduction)
compiling: deps/net.lua (13.9% reduction)
compiling: deps/path/base.lua (24.9% reduction)
compiling: deps/path/init.lua (49.7% reduction)
storing: deps/path/package.lua
compiling: deps/pathjoin.lua (33.5% reduction)
compiling: deps/pretty-print.lua (30.6% reduction)
compiling: deps/process.lua (17.2% reduction)
compiling: deps/querystring.lua (35.9% reduction)
compiling: deps/readline.lua (18.6% reduction)
compiling: deps/repl.lua (28.2% reduction)
compiling: deps/require.lua (24.6% reduction)
compiling: deps/resource.lua (31.5% reduction)
compiling: deps/stream/init.lua (55.6% reduction)
storing: deps/stream/package.lua
compiling: deps/stream/stream_core.lua (38.5% reduction)
compiling: deps/stream/stream_duplex.lua (49.7% reduction)
compiling: deps/stream/stream_observable.lua (50.8% reduction)
compiling: deps/stream/stream_passthrough.lua (65.3% reduction)
compiling: deps/stream/stream_readable.lua (48.2% reduction)
compiling: deps/stream/stream_transform.lua (62% reduction)
compiling: deps/stream/stream_writable.lua (43% reduction)
compiling: deps/thread.lua (38.6% reduction)
compiling: deps/timer.lua (24% reduction)
compiling: deps/tls/common.lua (14.9% reduction)
compiling: deps/tls/init.lua (26.1% reduction)
compiling: deps/tls/lcrypto.lua (46.8% reduction)
compiling: deps/tls/package.lua (2.6% reduction)
compiling: deps/url.lua (32.8% reduction)
compiling: deps/ustring.lua (37.5% reduction)
compiling: deps/utils.lua (39.7% reduction)
compiling: init.lua (43.5% reduction)
compiling: main.lua (21.6% reduction)
compiling: package.lua (21.1% reduction)
storing: test.lua
done building: /root/luvit
done: success
[root@kong ~]#

安裝結果確認

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@kong ~]# ./lit --version
lit version: 3.5.4
luvi version: v2.7.6
[root@kong ~]# ./luvi --version
./luvi v2.7.6
rex: 8.37 2015-04-28
libuv: 1.9.1
ssl: OpenSSL 1.0.2h 3 May 2016, lua-openssl 0.5.1
[root@kong ~]# ./luvit --version
luvit version: 2.14.2
luvi version: v2.7.6
rex version: 8.37 2015-04-28
libuv version: 1.9.1
ssl version: OpenSSL 1.0.2h 3 May 2016, lua-openssl 0.5.1
[root@kong ~]#

拷貝至PATH搜索目錄

?
1
2
3
4
5
6
7
8
9
10
11
[root@kong ~]# cp lit /usr/local/bin
[root@kong ~]# cp luvi /usr/local/bin
[root@kong ~]# cp luvit /usr/local/bin
[root@kong ~]#
[root@kong ~]# which luvi
/usr/local/bin/luvi
[root@kong ~]# which lit
/usr/local/bin/lit
[root@kong ~]# which luvit
/usr/local/bin/luvit
[root@kong ~]#

Lua界的Node.js

一個Node.js的HelloWorld的server.js可能是這樣的,運行則是使用node server.js

?
1
2
3
4
5
6
7
8
var http = require('http');
http.createServer(function (req, res) {
 var body = 'Hello world\n';
 res.setHeader('Content-Type', 'text/plain');
 res.setHeader('Content-Length', body.length);
 res.end(body);
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

而Luvit的HelloWorld的Server.lua則是這樣的,運行則是使用luvit server.lua

?
1
2
3
4
5
6
7
8
9
10
[root@kong ~]# cat server.lua
local http = require('http')
http.createServer(function (req, res)
 local body = 'Hello world\n'
 res:setHeader('Content-Type', 'text/plain')
 res:setHeader("Content-Length", #body)
 res:finish(body)
end):listen(1337, '127.0.0.1')
print('Server running at <a href="http://127.0.0.1:1337/')[root@kong" rel="external nofollow">http://127.0.0.1:1337/')
[root@kong</a> ~]#

運行結果為:

[root@kong ~]# luvit server.lua
Server running at http://127.0.0.1:1337/

確認結果:

[root@kong ~]# curl http://localhost:1337
Hello world
[root@kong ~]#

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接

原文鏈接:https://blog.csdn.net/liumiaocn/article/details/80529446

延伸 · 閱讀

精彩推薦
  • LuaLua中table庫函數方法介紹

    Lua中table庫函數方法介紹

    這篇文章主要介紹了Lua中table庫函數方法介紹,本文講解了concat、insert、maxn、remove、sort、foreachi等方法,需要的朋友可以參考下 ...

    腳本之家2502020-04-17
  • LuaLua和C語言的交互詳解

    Lua和C語言的交互詳解

    這篇文章主要介紹了Lua和C語言的交互詳解,Lua和C語言通過棧完成交互,本文結合代碼實例詳細講解了交互的方法,需要的朋友可以參考下 ...

    果凍想3702020-04-14
  • LuaLua簡介、編譯安裝教程及變量等語法介紹

    Lua簡介、編譯安裝教程及變量等語法介紹

    這篇文章主要介紹了Lua簡介、編譯安裝教程及變量等語法介紹,本文同時講解了lua注釋語法、Lua命令行方式等內容,需要的朋友可以參考下 ...

    junjie3632020-04-14
  • LuaLua中計算、執行字符串中Lua代碼的方法

    Lua中計算、執行字符串中Lua代碼的方法

    這篇文章主要介紹了Lua中計算、執行字符串中Lua代碼的方法,類似JavaScript中eval函數的功能,在Lua中也可以實現,需要的朋友可以參考下 ...

    腳本之家6322020-04-30
  • Lua深入探究Lua中的解析表達式

    深入探究Lua中的解析表達式

    這篇文章主要介紹了深入探究Lua中的解析表達式,對于其語法部分的說明和示例都超詳細,極力推薦此文!需要的朋友可以參考下 ...

    腳本之家3542020-05-05
  • LuaLua實現__add方法重載示例

    Lua實現__add方法重載示例

    這篇文章主要介紹了Lua實現__add方法重載示例,本文直接給出實現代碼,需要的朋友可以參考下 ...

    腳本之家7452020-04-24
  • LuaLua教程(二):基礎知識、類型與值介紹

    Lua教程(二):基礎知識、類型與值介紹

    這篇文章主要介紹了Lua教程(二):基礎知識、類型與值介紹,本文講解了Hello World程序、代碼規范、全局變量、類型與值等內容,需要的朋友可以參考下 ...

    腳本之家5922020-04-28
  • LuaLua中的元方法__newindex詳解

    Lua中的元方法__newindex詳解

    這篇文章主要介紹了Lua中的元方法__newindex詳解,本文講解了查詢與更新、監控賦值、通過table給另一個table賦值等內容,需要的朋友可以參考下 ...

    笨木頭8872020-04-09
主站蜘蛛池模板: 国产欧美精品 | 日韩精品视频免费 | 午夜影院免费看 | 久久婷婷五月免费综合色啪 | 欧美高清国产 | 久久亚洲精品专区蓝色区 | 91精品综合久久久久m3u8 | 国产成年人网站 | 精品国产福利片在线观看 | 岛国不卡 | 青青草在视线频久久 | 狠狠搞视频 | 千金肉奴隶免费观看 | 国产农村一级特黄α真人毛片 | 色悠久久久久综合欧美99 | www.色姐姐| 好逼365 | 成人毛片1024你懂的 | 日韩版码免费福利视频 | 日韩欧美国产免费看清风阁 | 92精品国产成人观看免费 | 成年人免费观看的视频 | 亚洲精品福利一区二区在线观看 | 五月天精品视频播放在线观看 | 91免费高清无砖码区 | 高h肉爽文农民工 | 久久青青草原综合伊人 | 性色香蕉AV久久久天天网 | 色热综合| 亚洲黄色网页 | 女仆色永久免费网站 | 国产精品国产国产aⅴ | 精品久久久久国产免费 | 东北老女人91p0rny | 国产精品女主播自在线拍 | 精品日韩欧美一区二区三区 | 91精品国产麻豆国产自产在线 | 欧美折磨另类系列sm | 狠狠五月天中文字幕 | 国产亚洲玖玖玖在线观看 | 秋霞理论一级在线观看手机版 |