mlua-rs / mlua

High level Lua 5.4/5.3/5.2/5.1 (including LuaJIT) and Roblox Luau bindings to Rust with async/await support
Other
1.75k stars 139 forks source link

Allow for more customizable Chunk names #428

Closed federicotdn closed 3 months ago

federicotdn commented 4 months ago

Hi! Thanks for creating this library, I've been enjoying using it while learning Rust at the same time. My question is mostly regarding something aesthetic: I am currently loading a Lua script as a string (using include_str!) into a Chunk, and then calling set_name("prelude.lua") on it (I'm not loading the script from a file as I want to have everything contained in a single binary file).

When I run code and I get an error, I get a stacktrace like the following:

Screenshot from 2024-07-19 00-14-03

The question then: is there a way maybe of changing the [string "prelude.lua"] part? I would like it to say just prelude.lua, as if it was loaded from a Path. Or maybe any value, but it seems like [string ...] always get added afterwards.

Thanks!

khvzak commented 4 months ago

The behaviour is mostly defined in Lua itself. If you want to see a file name (instead of "string ...") try adding = prefix. Eg: set_name("=prelude.lua")

federicotdn commented 3 months ago

Worked perfectly! Thank you!