-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
学习 Lua #298
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello world
通过brew或者make install都可以很容易的安装lua。
shell 运行:
script 运行:
语法
注释
变量
控制语句
while
i++
和i += 1
的操作if
~=
for
IO相关
函数
function
lambda
return
Table
this
模块
和nodejs很类似
foo.lua
hello.lua
Lua & C
Lua和C等同于Swift和C,也等同于Javascript和C (quickjs)
foo.lua
echo()
app.c
如果scirpt是用户配置数据库中,则可以直接采用更底层的luaL_dostring
这样就非常简单的实现了从Lua直接call到C的方法,通过lua script扩展C的核心能力。由于lua本身就是依托C,所以互相调用会非常方便,而swift,js只能说是不得不兼容C,从易用性的角度来说lua和c是绝配。
LuaJIT
Difference Lua Luajit – Shahzheeb Khan – Open Source Enthusiast
简单来说,luajit是一个更高效率的lua实现。OpenResty和Redis都采用了LuaJIT。
Lua原生的实现17000行C,到了LuaJIT就将近50000行C,可见通过复杂度换性能。几个特点:
OpenResty
传送: openresty 简介 - 戴磊笔记
所以,OpenResty就是nginx+lua+一系列基于nginx的扩展。传送: 序 · OpenResty最佳实践
另,Kong基于OpenResty,在Github上32k stars,cloc看了一下竟然有17万行lua, 从侧面证明lua也不完全是C附属品,足够强大。
参考阅读
The text was updated successfully, but these errors were encountered: