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 + `) } }