Compare commits

..

No commits in common. "6f20540720318e6277bddcea12d520a5d6e76561" and "cc2cb0c682496f91b263054a668e5c8bf4cfb43c" have entirely different histories.

5 changed files with 17 additions and 13 deletions

View File

@ -234,13 +234,13 @@ func handleRequest(ctx *fasthttp.RequestCtx) {
req.Path = path req.Path = path
req.Body = string(ctx.Request.Body()) req.Body = string(ctx.Request.Body())
for key, value := range ctx.QueryArgs().All() { ctx.QueryArgs().VisitAll(func(key, value []byte) {
req.Query[string(key)] = string(value) req.Query[string(key)] = string(value)
} })
for key, value := range ctx.Request.Header.All() { ctx.Request.Header.VisitAll(func(key, value []byte) {
req.Headers[string(key)] = string(value) req.Headers[string(key)] = string(value)
} })
err := worker.HandleRequest(req, resp) err := worker.HandleRequest(req, resp)
if err != nil { if err != nil {
@ -277,8 +277,8 @@ func tryStaticHandler(ctx *fasthttp.RequestCtx, path string) bool {
defer staticMu.RUnlock() defer staticMu.RUnlock()
for prefix, fs := range staticHandlers { for prefix, fs := range staticHandlers {
if after, ok := strings.CutPrefix(path, prefix); ok { if strings.HasPrefix(path, prefix) {
ctx.Request.URI().SetPath(after) ctx.Request.URI().SetPath(strings.TrimPrefix(path, prefix))
fs.NewRequestHandler()(ctx) fs.NewRequestHandler()(ctx)
return true return true
} }

View File

@ -1,7 +1,6 @@
-- modules/http.lua - Express-like HTTP server with pure Lua routing -- modules/http.lua - Express-like HTTP server with pure Lua routing
local http = {} local http = {}
local json = require("json")
-- Global routing tables (shared across all states) -- Global routing tables (shared across all states)
_G._http_routes = _G._http_routes or {} _G._http_routes = _G._http_routes or {}
@ -309,7 +308,7 @@ function Request:json()
end end
local success, result = pcall(function() local success, result = pcall(function()
return json.decode(self.body) return moonshark.json_decode(self.body)
end) end)
if success then if success then
@ -392,7 +391,7 @@ function Response:json(data)
self:type("application/json") self:type("application/json")
local success, json_str = pcall(function() local success, json_str = pcall(function()
return json.encode(data) return moonshark.json_encode(data)
end) end)
if success then if success then

View File

@ -30,7 +30,11 @@ func string_slice(s *luajit.State) int {
runes := []rune(str) runes := []rune(str)
length := len(runes) length := len(runes)
startIdx := max(start-1, 0) // Convert from 1-indexed startIdx := start - 1 // Convert from 1-indexed
if startIdx < 0 {
startIdx = 0
}
if startIdx >= length { if startIdx >= length {
s.PushString("") s.PushString("")
return 1 return 1

View File

@ -259,7 +259,7 @@ func (s *State) ExecuteStringWithResults(code, name string) ([]any, error) {
} }
results := make([]any, nresults) results := make([]any, nresults)
for i := range nresults { for i := 0; i < nresults; i++ {
val, err := s.ToValue(baseTop + i + 1) val, err := s.ToValue(baseTop + i + 1)
if err != nil { if err != nil {
results[i] = nil results[i] = nil

View File

@ -3,7 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -85,7 +84,9 @@ func (fw *FileWatcher) pollLoop() {
func (fw *FileWatcher) checkFiles() { func (fw *FileWatcher) checkFiles() {
fw.mu.RLock() fw.mu.RLock()
files := make(map[string]time.Time, len(fw.files)) files := make(map[string]time.Time, len(fw.files))
maps.Copy(files, fw.files) for path, modTime := range fw.files {
files[path] = modTime
}
fw.mu.RUnlock() fw.mu.RUnlock()
changed := false changed := false