Fix oopsie

This commit is contained in:
2025-03-26 02:52:28 +01:00
parent 66a522aa12
commit bb14087598
2 changed files with 14 additions and 8 deletions

View File

@@ -43,11 +43,10 @@ func (p *XMLProcessor) ProcessContent(content string, path string, luaExpr strin
}
defer L.Close()
table, err := p.ToLua(L, node)
err = p.ToLua(L, node)
if err != nil {
return content, modCount, matchCount, fmt.Errorf("error converting to Lua: %v", err)
}
L.SetGlobal("v", table)
err = L.DoString(BuildLuaScript(luaExpr))
if err != nil {
@@ -92,8 +91,17 @@ func (p *XMLProcessor) ProcessContent(content string, path string, luaExpr strin
return ConvertToNamedEntities(doc.OutputXML(true)), modCount, matchCount, nil
}
func (p *XMLProcessor) ToLua(L *lua.LState, data interface{}) error {
table, err := p.ToLuaTable(L, data)
if err != nil {
return err
}
L.SetGlobal("v", table)
return nil
}
// ToLua converts XML node values to Lua variables
func (p *XMLProcessor) ToLua(L *lua.LState, data interface{}) (lua.LValue, error) {
func (p *XMLProcessor) ToLuaTable(L *lua.LState, data interface{}) (lua.LValue, error) {
// Check if data is an xmlquery.Node
node, ok := data.(*xmlquery.Node)
if !ok {
@@ -111,7 +119,7 @@ func (p *XMLProcessor) ToLua(L *lua.LState, data interface{}) (lua.LValue, error
// Add children if any
children := L.NewTable()
for child := node.FirstChild; child != nil; child = child.NextSibling {
childTable, err := p.ToLua(L, child)
childTable, err := p.ToLuaTable(L, child)
if err == nil {
children.Append(childTable)
}