##安装LuaXml 下载 然后修改Makefile
# 2009-03-16 by gf# generic compiler and linker settings:CC = gccINCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1LIB = LIBDIR = -L. -L/usr/local/openresty/luajit/libCFLAGS = -Os -Wall -c #-g# generic platform specific rules:ARCH = $(shell uname -s)ifeq ($(ARCH),Linux) CFLAGS += -fPIC LFLAGS = -fPIC -shared LIBS = $(LIBDIR) $(LIB) -lluajit-5.1 -ldl EXESUFFIX = SHLIBSUFFIX = .soelse ifeq ($(ARCH),Darwin) # MacOSX LFLAGS = -bundle LIBS = $(LIBDIR) -L/usr/local/lib $(LIB) -lluajit-5.1 EXESUFFIX = .app SHLIBSUFFIX = .so else # windows, MinGW LFLAGS = -shared LIBS = $(LIBDIR) $(LIB) -llua51 -mconsole -s EXESUFFIX = .exe SHLIBSUFFIX = .dll endifendif# project specific targets:all: LuaXML_lib$(SHLIBSUFFIX)# project specific link rules:LuaXML_lib$(SHLIBSUFFIX): LuaXML_lib.o $(CC) -o $@ $(LFLAGS) $^ $(LIBS) # project specific dependencies:LuaXML_lib.o: LuaXML_lib.c# generic rules and targets:.c.o: $(CC) $(CFLAGS) $(INCDIR) -c $
主要修改如下几个地方:
INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1LIBDIR = -L. -L/usr/local/openresty/luajit/libLIBS = $(LIBDIR) $(LIB) -lluajit-5.1 -ldlLIBS = $(LIBDIR) -L/usr/local/lib $(LIB) -lluajit-5.1LIBS = $(LIBDIR) $(LIB) -llua51 -mconsole -s
拷贝到openresty/openresty:1.11.2.1-trusty镜像实例中,然后再此基础上编译
make clean && make
然后拷贝LuaXML_lib.so以及LuaXml.lua到/usr/local/openresty/lualib/
##使用luaxml
require "LuaXml" xml = require "xml" local resp = xml.eval(xmlStr) local oktag = resp:find("ok") local ok = oktag[1] ngx.log(ngx.INFO,"ok tag:"..ok)
- 关于xml 如果不require "xml",而是直接用xml的话,则第二次请求会报错
attempt to index global 'xml' (a nil value)
- 关于eval 返回的是lua table,通过find出来,也是一个table,取出相应的值接口,如果是单值,取数组第一个,比如xmlStr是
false
##doc