mlua icon indicating copy to clipboard operation
mlua copied to clipboard

Error Values Eagerly Formatted

Open Pspritechologist opened this issue 4 months ago • 0 comments

A Lua error can contain any Lua value, bubbling up the stack to the nearest native function (or pcall). The following Lua code for instance uses an error to call a function and actually prints `"Hello, World".

local function thing()
  print("Hello, World")
end

local function fallible()
  error(thing)
end

local err, result = pcall(fallible)
result()

This can be useful in situations where an error is intended to carry data or otherwise have some meaning to the code receiving it. It seems like, however, mlua eagerly formats all RuntimeErrors upon receiving them, erasing any actual values carried with them. Looking at the source code I see no immediate reason for this. Is this simply a limitation of mlua?

This appears to be the offending line, I do apologize if I've missed some reason this is nessecary. https://github.com/mlua-rs/mlua/blob/85b280a9d68796ad9c438cc26120839e4665e4fe/src/util/error.rs#L123

Pspritechologist avatar Aug 23 '25 19:08 Pspritechologist