Skip to content

Error Values Eagerly Formatted #631

@Pspritechologist

Description

@Pspritechologist

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.

let err_string = to_string(state, -1);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions