lua-aot-5.4 icon indicating copy to clipboard operation
lua-aot-5.4 copied to clipboard

Better syntax errors

Open Frityet opened this issue 1 year ago • 3 comments
trafficstars

Adding the message at the top of the stack lets you know what failed

Frityet avatar Jul 04 '24 23:07 Frityet

I'm confused why LuaAOT didn't detect this as a compile-time error. In theory the first thing we do is compile to bytecode and then turn that bytecode into C. Shouldn't the syntax error have been caught in that first step?

ps.: I'm currently working on a branch to update LuaAOT to Lua 5.4.6. After that, there will likely be merge conflicts for this PR. (hopefully not much)

hugomg avatar Jul 05 '24 22:07 hugomg

I'm confused why LuaAOT didn't detect this as a compile-time error. In theory the first thing we do is compile to bytecode and then turn that bytecode into C. Shouldn't the syntax error have been caught in that first step? Yes, but shebangs are valid lua, and can't be interpreted with loadstring. Just in case there are other cases like that I think its useful to have the message

I'm currently working on a branch to update LuaAOT to Lua 5.4.6 awesome, thank you so much!

Frityet avatar Jul 25 '24 16:07 Frityet

Yes, but shebangs are valid lua, and can't be interpreted with loadstring. Just in case there are other cases like that I think its useful to have the message

Looks like the magic is all in luaL_loadfilex. All it does is eat an optional UTF byte order mark and shebang. See functions skipBOM and skipcomment in lauxlib.c

Since there are no other cases to worry about, I think it makes sense to replicate the behavior of skipBOM and skipcomment. We can keep a sanity check to see if loadstring had a syntax error or not, but we don't need to present a pretty user-facing message because in theory that should never happen.

hugomg avatar Jul 25 '24 17:07 hugomg