Commit a0d59c8b by orangle

add new makefile

parent 224860e0
# Makefile for qrencode library for Lua # Makefile for qrencode library for Lua
version=0.1
LIBNAME= qrencode name=lua-resty-qrencode
LUA_VERSION = 5.1
LUAEXE= lua # See http://lua-users.org/wiki/BuildingModules for platform specific
# details.
ROCKSPEC= $(shell find . -name $(LIBNAME)-*-*.rockspec) ## Linux/BSD
PREFIX ?= /usr/local/openresty
#LDFLAGS += -shared
all: install ## OSX (Macports)
#PREFIX ?= /opt/local
LDFLAGS += -bundle -undefined dynamic_lookup
install: ## find your luajit path
luarocks make $(ROCKSPEC) LUA_INCLUDE_DIR ?= $(PREFIX)/luajit/include/luajit-2.1
LUA_LIB_DIR ?= $(PREFIX)/lualib
# Some versions of Solaris are missing isinf(). Add -DMISSING_ISINF to
# CFLAGS to work around this bug.
#CFLAGS ?= -g -Wall -pedantic -fno-inline
CFLAGS ?= -g -O3 -Wall -pedantic
override CFLAGS += -fpic -I$(LUA_INCLUDE_DIR) -lpng -lqrencode
INSTALL ?= install
test: .PHONY: all clean install
$(LUAEXE) test/test.lua
.PHONY: all test install all: qrencode.so
qrencode.so: qrencode.c
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
install:
$(INSTALL) -d $(LUA_LIB_DIR)
$(INSTALL) qrencode.so $(LUA_LIB_DIR)
clean:
rm *.so
...@@ -11,24 +11,39 @@ qrencode is dependent on [libqrencode](http://fukuchi.org/works/qrencode/) ...@@ -11,24 +11,39 @@ qrencode is dependent on [libqrencode](http://fukuchi.org/works/qrencode/)
and [libpng](http://www.libpng.org/pub/png/libpng.html), so make sure these are installed and [libpng](http://www.libpng.org/pub/png/libpng.html), so make sure these are installed
before compile it. before compile it.
## Example usage ### MacOS
```lua ```
qr = require "qrencode" $ brew install libqrencode
$ https://github.com/orangle/lua-resty-qrencode.git
$ cd lua-resty-qrencode
$ make
$ make install
```
defalut openresty `PREFIX` is `/usr/local/openresty`, if you have a different path, please read `Makefile` and change the path.
### Other
-- print PNG data stream to stdout. please install libqrencode and libpng, and read Makefile.
print(qr.encode("is ok?"))
print(qr:encode("is ok?"))
print(qr("is ok?"))
-- print ansi char ## Example usage
print(qr {text = "is ok?", ansi = true})
```lua
location /qrcode {
content_by_lua_block {
local qr = require("qrencode")
local args = ngx.req.get_uri_args()
local text = args.text
-- or pass a table : if text == nil or text== "" then
ngx.say('need a text param')
ngx.exit(404)
end
print(qr { ngx.say(qr {
text="is ok?", text=text,
level="L", level="L",
kanji=false, kanji=false,
ansi=true, ansi=true,
...@@ -36,11 +51,17 @@ print(qr { ...@@ -36,11 +51,17 @@ print(qr {
margin=2, margin=2,
symversion=0, symversion=0,
dpi=78, dpi=78,
casesensitive=false, casesensitive=true,
foreground="48AF6D", foreground="48AF6D",
background="3FAF6F" background="3FAF6F"
} })
) }
}
```
test url like
```
curl 'http://127.0.0.1:8008/qrcode?text=http://orangleliu.info'
``` ```
when pass a table, "text" is required and other is optional. when pass a table, "text" is required and other is optional.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment