Skip to content

Commit

Permalink
fix handle lua vm stack
Browse files Browse the repository at this point in the history
  • Loading branch information
missdeer committed Feb 5, 2024
1 parent 26999d9 commit a2b156a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion handler/luahandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ func (h *ExternalHandler) initLuaEnv() {
files, err := os.ReadDir(directory)
if err != nil {
log.Println(err)
return
}

for _, file := range files {
if file.IsDir() {
continue
}

if strings.ToLower(filepath.Ext(file.Name())) != ".lua" {
continue
}
Expand All @@ -170,6 +175,7 @@ func (h *ExternalHandler) invokePreprocessExternalChapterListURL(u string) strin
h.l.GetGlobal("PreprocessChapterListURL")
h.l.PushString(u)
h.l.Call(1, 1)
defer h.l.Pop(1)
if !h.l.IsString(-1) {
return u
}
Expand Down Expand Up @@ -217,14 +223,15 @@ func (h *ExternalHandler) invokeExtractExternalChapterList(u string, rawPageCont
}
h.l.Pop(1)
}

h.l.Pop(2)
return
}

func (h *ExternalHandler) invokeExtractExternalChapterContent(rawPageContent []byte) (c []byte) {
h.l.GetGlobal("ExtractChapterContent")
h.l.PushBytes(rawPageContent)
h.l.Call(1, 1)
defer h.l.Pop(1)
if !h.l.IsString(-1) {
return
}
Expand All @@ -235,6 +242,7 @@ func (h *ExternalHandler) invokeCanHandleExternalSite(u string) bool {
h.l.GetGlobal("CanHandle")
h.l.PushString(u)
h.l.Call(1, 1)
defer h.l.Pop(1)
if !h.l.IsBoolean(-1) {
return false
}
Expand Down

0 comments on commit a2b156a

Please sign in to comment.