From 9ab527b9be01de1b9a294869bfcdb0c0c0989bee Mon Sep 17 00:00:00 2001 From: unwox Date: Mon, 9 Dec 2024 14:33:25 +0600 Subject: add -D flag for development --- worker.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'worker.go') diff --git a/worker.go b/worker.go index 5ae69c2..e7d76e4 100644 --- a/worker.go +++ b/worker.go @@ -40,6 +40,7 @@ type Worker struct { routes map[string]LuaRef started bool mu sync.Mutex + repl *LuaRef } // NewWorker creates a new instance of Worker type. @@ -167,10 +168,16 @@ func (w *Worker) Listen(queue chan *HTTPRequest) { err = l.PCall(1, 3, -3) if err != nil { + var body string + if debug { + body = err.Error() + } else { + body = "server error" + } r.result <- &HTTPResponse{ Code: 500, Headers: make(map[string]string), - Body: "server error", + Body: body, } log.Println("could not process request:\n" + err.Error()) return @@ -234,7 +241,11 @@ outer: func (w *Worker) Eval(code string) error { w.mu.Lock() defer w.mu.Unlock() - defer w.lua.RestoreStackFunc()() + if w.repl != nil { + w.lua.PushFromRef(*w.repl) + w.lua.PushString(code) + return w.lua.PCall(1, 0, 0) + } return w.lua.LoadString(code) } -- cgit v1.2.3