Implement xpath (by calling library)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/antchfx/xmlquery"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
@@ -89,6 +90,16 @@ func Process(p Processor, filename string, pattern string, luaExpr string) (int,
|
||||
// ToLua converts a struct or map to a Lua table recursively
|
||||
func ToLua(L *lua.LState, data interface{}) (lua.LValue, error) {
|
||||
switch v := data.(type) {
|
||||
case *xmlquery.Node:
|
||||
luaTable := L.NewTable()
|
||||
luaTable.RawSetString("text", lua.LString(v.Data))
|
||||
// Should be a map, simple key value pairs
|
||||
attr, err := ToLua(L, v.Attr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
luaTable.RawSetString("attr", attr)
|
||||
return luaTable, nil
|
||||
case map[string]interface{}:
|
||||
luaTable := L.NewTable()
|
||||
for key, value := range v {
|
||||
|
Reference in New Issue
Block a user