try to preserve http_request

This commit is contained in:
Sky Johnson 2025-03-27 18:25:53 -05:00
parent b336ce5efa
commit 08a532f11a

View File

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