Closed WillianBR closed 3 months ago
There's nothing that golua does except give you what the underlying C implementation returns. I think the difference you are seeing is just down to using different versions of lua for luac and golua. If I compile golua with lua5.4 I get this error: test.lua:7: ')' expected (to close '(' at line 5) near 'print'
, with this code:
L := lua.NewState()
defer L.Close()
L.OpenLibs()
n := L.LoadFile("test.lua")
fmt.Printf("out: %v %s\n", n, L.ToString(-1))
go-lua syntax error without details
I did notice a small inconvenient in the errors message. If the issue is a run-time error, it'll show the filename and line number where the run-time problem is.
But if we load the script (with a syntax error) without execution, which give us a syntax error. In this particular case, there's no line number information. The error object retuned by the go-lua is a string with value "syntax error".
So, using:
lua.LoadFile()
returns "syntax error".lua.DoFile()
returns "runtime error: testLuaVM.lua:6: attempt to call a nil value"It would surely be usefull to embed go-lua and provide a friendly environment, if we had a detailed error information.
Let's say:
1) file name if it was the case:
testLuaVM.lua
2) the line number (usefull even in a string buffer):6
In the below buggy code, there's a few situation:
1) If execute by go-lua, we only have: "syntax error" 2) If compile by luac binary, we have: "')' expected (to close '(' at line 5) near 'bar'"
The last one is sure a excellent error message.
Therefor...