summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go11
-rw-r--r--worker.go26
2 files changed, 7 insertions, 30 deletions
diff --git a/main.go b/main.go
index 7ebee5b..96e8a38 100644
--- a/main.go
+++ b/main.go
@@ -107,7 +107,7 @@ func main() {
req, err := http.NewRequest(method, url, strings.NewReader(body))
if err != nil {
- // fixme: return error
+ // FIXME: return error
return 0
}
for k, v := range headers {
@@ -115,13 +115,13 @@ func main() {
}
resp, err := httpClient.Do(req)
if err != nil {
- // fixme: return error
+ // FIXME: return error
return 0
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
- // fixme: return error
+ // FIXME: return error
return 0
}
respHeaders := make(map[string]any)
@@ -149,10 +149,10 @@ func main() {
log.Fatal(err)
}
wrks = append(wrks, wrk)
+ log.Printf("worker %d started\n", i)
wrk.Listen(msgs)
}()
defer wrk.Stop()
- log.Printf("worker %d started\n", i)
}
// listen for evals from stdio
@@ -184,6 +184,7 @@ func printUsage() {
func mustExist(file string) {
if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
- log.Fatalf("file \"%s\" does not exist", file)
+ fmt.Printf(`file "%s" does not exist\n`, file)
+ os.Exit(1)
}
}
diff --git a/worker.go b/worker.go
index 77aae33..b4cae12 100644
--- a/worker.go
+++ b/worker.go
@@ -209,30 +209,6 @@ func (w *Worker) HasSameLua(l *Lua) bool {
// initLunaModule registers the module in the Lua context.
func (w *Worker) initLunaModule(module map[string]any) {
- var pushTable func(t map[string]any)
- pushTable = func (t map[string]any) {
- w.lua.CreateTable(len(t))
- for k, v := range t {
- switch v.(type) {
- case string:
- v, _ := v.(string)
- w.lua.PushString(v)
- case func (l *Lua) int:
- v, _ := v.(func (l *Lua) int)
- w.lua.PushGoFunction(v)
- case int:
- v, _ := v.(int)
- w.lua.PushNumber(v)
- case map[string]any:
- v, _ := v.(map[string]any)
- pushTable(v)
- default:
- // FIXME: more details.
- log.Fatal("unsupported module value type")
- }
- w.lua.SetTableItem(k)
- }
- }
- pushTable(module)
+ w.lua.PushObject(module)
w.lua.SetGlobal("luna")
}