openresty_log_by_lua_file
set the log in nginx.conf1234567891011121314location /docs { keepalive_timeout 0; default_type 'text/html'; set $res ""; set_by_lua_file $res /opt/openresty/set_by.lua; rewrite_by_lua_file /opt/openresty/rewrite.lua; access_by_lua_file /opt/openresty/access.lua; content_by_lua_file /opt/openresty/content.lua; header_filter_by_lua_file /opt/openresty/header_filter.lua; body_filter_by_lua_file /opt/openresty/body_filter.lua; log_by_lua_file /opt/openresty/base/log.lua; proxy_pass h ...
openresty_balancer_by_lua_file
set the balancer in nginx.conf12345678910upstream default_doc_upstream { server 192.168.1.170:8081; # tomcat-8 server 192.168.1.170:8082; # tomcat-9 server 192.168.1.170:8083; balancer_by_lua_file /opt/openresty/balancer.lua;}
traffic control123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263local math = require('math');local string = require('string');local table = require('table');local cjson = require(& ...
编译安装lua
下载:
build $ wget https://www.lua.org/ftp/lua-5.1.5.tar.gz
解压:
build $ tar xf lua-5.1.5.tar.gz
make:
lua-5.1.5 $ make linux
安装:
lua-5.1.5 $ sudo make install
port lua to web environment using webassembly
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.
Recently, all major browsers like Google Chrome, Safari, Microsoft Edge all support web assembly. Web assembly allows developers to compile C/C++ application into a browser supported format, meaning even a 3A game can be run on the browser ...
interfacing lua with c
Lua is a lightweight, multi-paradigm programming language designed primarily for embedded use in applications. Roberto Ierusalimschy, the author of Lua, said that Lua is like passing a language through the eye of a needle.
Lua is amazingly small - it only has around 10000 lines of code, and it can be embedded into any systems. It is written pure C language and any C compiler is able to compile Lua without any issues (no dependency problems, no build tools problems, and even on Windows platform, ...
lua中也能用上go语言的strings包
lua内置的库非常小,我们可以将Go语言的strings包引入到Lua环境。
下面是具体的例子。
hello.go:
package main
import (
"github.com/yuin/gopher-lua"
strings "github.com/chai2010/glua-strings"
)
func main() {
L := lua.NewState()
defer L.Close()
strings.Preload(L)
if err := L.DoFile("hello.lua"); err != nil {
panic(err)
}
}
hello.lua:
local strings = require("strings")
print(strings.ToUpper("abc"))
for i, s in ipairs(strings.Split("aa,b,,c", ", ...
some valuable yii2 extension
Yii2 extension http://codemix.github.io/yii2-bs3activeform/horizontal.html
http://demos.krajee.com/
lua前言
###Lua前言
nginx中,lua的协程机制可以很好的和nginx的全异步、非阻塞的多阶段处理机制结合,使开发者使用同步的模式,开发全异步的应用,而不用考虑异步的处理机制。
Lua 中的随机数
Lua 随机数算法用的是 libc 中的 rand, 也就是 LCG。然而这个算法的随机性一般。尤其是在一些平台上,当随机种子变化非常小的时候,产生的随机数变化也非常小。这样再经过 Lua 的精度取舍之后,产生的随机序列仍然很相似(伪随机的结果变成可预知性)。
lua-l 上也讨论过这个问题 msg00564,lua 的作者之一 lhf 给出的解决方案是先弹出前面几个看起来「不怎么随机」的随机数。另外,作者也写过一个基于 MT 算法的 c lib: lrandim, 有兴趣的同学可以去看下。
然而在 lua-wiki 上有一种更为巧妙的实现(这个用例同样是有缺陷的,这里只是为了引出上面的问题。以后我会单独讨论这个问题):
local seed = 123456
for i=1,2 do
math.randomseed(seed + (i-1)/10)
local num = {}
for j=1,10 do
table.insert(num, math.random(100))
end
print(table. ...
lua编程
Lua一共包含8个基本数据类型
nil: print(type(nil))
boolean: print(type(true))
number: print(type(2.0))
string: print(type("abc"))
function: print(type(type))
userdata:
thread: print(type(coroutine.create(function()end)))
table: print(type({}))
Lua标准库包括以下10个库:
基本库
pcall (f [, arg1, ···])
xpcall (f, msgh [, arg1, ···])
协程操作库
coroutine.create(function(i) print(i); end)
coroutine.isyieldable ()
coroutine.resume (co [, val1, ···])
coroutine.running ()
coroutine.sta ...


