Skip to content

Commit

Permalink
Add node.insertbefore and document:newpage
Browse files Browse the repository at this point in the history
  • Loading branch information
pgundlach committed Oct 30, 2021
1 parent 5841abe commit e89373b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
*.code-workspace
dist/
7 changes: 3 additions & 4 deletions core/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func indexDoc(l *lua.LState) int {
case "loadpattern":
l.Push(l.NewFunction(documentLoadPatternFile(doc.d)))
return 1
case "newpage":
l.Push(l.NewFunction(documentNewPage(doc.d)))
return 1
case "outputat":
l.Push(l.NewFunction(documentOutputAt(doc.d)))
return 1
Expand Down Expand Up @@ -177,7 +180,3 @@ func newIndexLang(l *lua.LState) int {
func indexLang(l *lua.LState) int {
return 0
}

var documentMethods = map[string]lua.LGFunction{
"newPage": documentNewPage,
}
17 changes: 17 additions & 0 deletions core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func registerNodeType(l *lua.LState) {
l.SetField(mt, "debug", l.NewFunction(debugNode))
l.SetField(mt, "hpack", l.NewFunction(nodeHpack))
l.SetField(mt, "insertafter", l.NewFunction(nodeInsertAfter))
l.SetField(mt, "insertbefore", l.NewFunction(nodeInsertBefore))
l.SetField(mt, "simplelinebreak", l.NewFunction(nodeSimpleLinebreak))
}

Expand Down Expand Up @@ -76,6 +77,22 @@ func nodeInsertAfter(l *lua.LState) int {
return 1
}

func nodeInsertBefore(l *lua.LState) int {
var head, cur bagnode.Node
if l.Get(1) == lua.LNil {
} else {
head = checkNode(l, 1)
}
if l.Get(2) == lua.LNil {
} else {
cur = checkNode(l, 2)
}
ins := checkNode(l, 3)
newhead := bagnode.InsertBefore(head, cur, ins)
l.Push(newUserDataFromNode(l, newhead))
return 1
}

func nodeSimpleLinebreak(l *lua.LState) int {
n := checkNode(l, 1)
tbl := l.CheckTable(2)
Expand Down
11 changes: 6 additions & 5 deletions core/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func documentCurrentPage(doc *document.Document) lua.LGFunction {
}
}

func documentNewPage(l *lua.LState) int {
d := checkDocument(l, 1)
p := d.d.NewPage()
l.Push(newUserdataPage(l, p))
return 1
func documentNewPage(doc *document.Document) lua.LGFunction {
return func(l *lua.LState) int {
p := doc.NewPage()
l.Push(newUserdataPage(l, p))
return 1
}
}
3 changes: 3 additions & 0 deletions ets/ets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"time"

"github.com/speedata/ets/core"
"github.com/speedata/optionparser"
Expand All @@ -24,9 +25,11 @@ func dothings() error {
}

func main() {
start := time.Now()
err := dothings()
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println(time.Now().Sub(start))
}

0 comments on commit e89373b

Please sign in to comment.