-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] More direct source line mapping #141
Comments
Added a new option -r to the compiler to generate Lua codes with corresponding line to the original Yuescript codes. > yue -r test.yue Will now compile the code x = if this
foo()
else
bar() to local x;if this then
x = foo()else
x = bar()end And the -r option can work with file watcher function. > yue -r -w path_to_watch Will generate the formatted Lua code when any script under watch folder changes. |
@pigpigyyy |
The current line mapping function is done with a lib named luaminify, and I modified the lib source to support Lua 5.4 then added a transform function for converting Yuescript compiled codes. You can find the modified lib here: https://github.com/pigpigyyy/Yuescript/blob/main/src/3rdParty/luaminify.lua And use it as: local luaminify = require("luaminify")
local yue = require("yue")
local luaCode = yue.to_lua(yueCode, {reserve_line_number = true})
local output = luaminify.FormatYue(luaCode) |
Thank you! |
If you have the local yue = require("yue")
local yuescriptCode = [[
if user = database.find_user "moon"
print user.name
]]
local func, load_err = yue.loadstring(yuescriptCode, "moduleName")
if func then
local success, result = xpcall(func, function(err)
return yue.traceback(err)
end)
if success then
return print(result)
else
return print("runtime error:\n" .. result)
end
else
return print("load error:\n" .. load_err)
end |
I could use it in my code, but the issue is that the whole environment is in Lua, and I cannot change predefined error-catching functions there. |
Since the compiler can already append a comment to each Lua line saying what Yuescript line it came from, it would be nice if there were an option to instead just put all Lua code on the same line as the Yuescript code that produced it, as well as preserving empty lines.
For example, the code:
would be compiled like this:
My suggestion would be to allow for it to be compiled to something more like this:
The goal is to make line numbers in tracebacks and debugging info map directly to their according Yuescript line, meaning that it would no longer be necessary to first look which Lua line the error occurred on and then go to the Yuescript line that produced it. Instead, we could simply go to the error line directly in the Yuescript file.
The text was updated successfully, but these errors were encountered: