From 08a532f11a7dded00453926cb292617772270d7c Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 27 Mar 2025 18:25:53 -0500 Subject: [PATCH] try to preserve http_request --- core/runner/Http.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/runner/Http.go b/core/runner/Http.go index 6b7e7ee..7eadbc4 100644 --- a/core/runner/Http.go +++ b/core/runner/Http.go @@ -521,10 +521,7 @@ end // HTTPModuleInitFunc returns an initializer function for the HTTP module func HTTPModuleInitFunc() StateInitFunc { return func(state *luajit.State) error { - // First, unregister any existing function to prevent registry leaks - state.UnregisterGoFunction(httpRequestFuncName) - - // Register the native __http_request function + // The important fix: register the Go function directly to the global environment if err := state.RegisterGoFunction(httpRequestFuncName, httpRequest); err != nil { return err } @@ -567,7 +564,14 @@ func HTTPModuleInitFunc() StateInitFunc { state.SetGlobal("__http_client_config") - return nil + // Ensure the Go function is registered with the base environment + // This is critical to make it persist across reloads + return state.DoString(` + -- Make the __http_request function available in the base environment + if __env_system and __env_system.base_env then + __env_system.base_env.__http_request = __http_request + end + `) } }