diff options
| author | unwox <me@unwox.com> | 2024-12-09 14:33:25 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-12-09 14:42:04 +0600 |
| commit | 9ab527b9be01de1b9a294869bfcdb0c0c0989bee (patch) | |
| tree | bea373a06b771721f0474e04d3ac0e41e42fb348 /worker.go | |
| parent | ab4a82dc0b267d48315fbb8c0bcf1d0939d7590e (diff) | |
add -D flag for development
Diffstat (limited to 'worker.go')
| -rw-r--r-- | worker.go | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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) } |
