1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

lua: Preload gluahttp module (#328)

This commit is contained in:
James Hillyerd
2023-02-09 19:04:33 -08:00
committed by GitHub
parent 75b7c69b5c
commit b38b2e9760
3 changed files with 8 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
package luahost
import (
"net/http"
"sync"
"github.com/cjoudrey/gluahttp"
lua "github.com/yuin/gopher-lua"
)
@@ -24,6 +26,9 @@ func newStatePool(funcProto *lua.FunctionProto) *statePool {
func (lp *statePool) newState() (*lua.LState, error) {
ls := lua.NewState()
// Load supplemental native modules.
ls.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
// Setup channels.
for name, ch := range lp.channels {
ls.SetGlobal(name, lua.LChannel(ch))