fix fenv error
This commit is contained in:
parent
e2b1b932ff
commit
1ad3059ff0
@ -130,25 +130,36 @@ func (s *Sandbox) registerCoreFunctions(state *luajit.State) error {
|
||||
|
||||
// Execute runs a Lua script in the sandbox with the given context
|
||||
func (s *Sandbox) Execute(state *luajit.State, bytecode []byte, ctx *Context) (*Response, error) {
|
||||
// Use CallGlobal for cleaner function calling
|
||||
results, err := state.CallGlobal("__execute_script",
|
||||
func() any {
|
||||
if err := state.LoadBytecode(bytecode, "script"); err != nil {
|
||||
return nil
|
||||
}
|
||||
return "loaded_script"
|
||||
}(),
|
||||
ctx.Values)
|
||||
// Load bytecode - pushes function onto stack
|
||||
if err := state.LoadBytecode(bytecode, "script"); err != nil {
|
||||
return nil, fmt.Errorf("failed to load bytecode: %w", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Stack: [function]
|
||||
state.GetGlobal("__execute_script") // Stack: [function, __execute_script]
|
||||
state.PushCopy(-2) // Stack: [function, __execute_script, function]
|
||||
|
||||
// Push context using PushValue
|
||||
if err := state.PushValue(ctx.Values); err != nil {
|
||||
state.Pop(3)
|
||||
return nil, fmt.Errorf("failed to push context: %w", err)
|
||||
}
|
||||
// Stack: [function, __execute_script, function, context]
|
||||
|
||||
// Call __execute_script(function, context)
|
||||
if err := state.Call(2, 1); err != nil {
|
||||
state.Pop(1) // Clean up original function
|
||||
return nil, fmt.Errorf("script execution failed: %w", err)
|
||||
}
|
||||
// Stack: [function, result]
|
||||
|
||||
response := NewResponse()
|
||||
if len(results) > 0 {
|
||||
response.Body = results[0]
|
||||
if result, err := state.ToValue(-1); err == nil {
|
||||
response.Body = result
|
||||
}
|
||||
|
||||
state.SetTop(0) // Clear stack
|
||||
|
||||
extractHTTPResponseData(state, response)
|
||||
return response, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user