下載luaxml
而後修改Makefilegit
# 2009-03-16 by gf # generic compiler and linker settings: CC = gcc INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1 LIB = LIBDIR = -L. -L/usr/local/openresty/luajit/lib CFLAGS = -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 = .so else 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 endif endif # 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 $< clean: rm -f *.o *~ LuaXML_lib.so LuaXML_lib.dll
主要修改以下幾個地方:github
INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1 LIBDIR = -L. -L/usr/local/openresty/luajit/lib LIBS = $(LIBDIR) $(LIB) -lluajit-5.1 -ldl LIBS = $(LIBDIR) -L/usr/local/lib $(LIB) -lluajit-5.1 LIBS = $(LIBDIR) $(LIB) -llua51 -mconsole -s
拷貝到openresty/openresty:1.11.2.1-trusty鏡像實例中,而後再此基礎上編譯shell
make clean && make
而後拷貝LuaXML_lib.so以及LuaXml.lua到/usr/local/openresty/lualib/windows
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是微信
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <result> <ok>false</ok> </result>