Implement xpath (by calling library)

This commit is contained in:
2025-03-25 23:47:14 +01:00
parent 73d93367a0
commit e31c0e4e8f
7 changed files with 449 additions and 538 deletions

View File

@@ -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 {