• Detecting syntax errors in CompileString()
    4 replies, posted
Hi there. I have noticed that on a syntax error, CompileString simply prints the error to the server console and returns nil. Thus, there is no way to detect what line or any information about syntax errors in any code passed to CompileString, just simply the fact that there is a syntax error. So does anyone know a workaround to this?
[lua] local lua = "print( undefinedtable[3] )" local status, err = pcall( CompileString( lua, "testcode" ) ) print( status, err )[/lua] [code]false testcode:1: attempt to index global 'undefinedtable' (a nil value)[/code] Atleast that's what the gmod wiki says?
No, the error in that one is not a syntax error. The code being compiled there is perfectly fine lua code; it can compile nicely. But what I am looking for is where the code cannot compile.
Pass false as a 3rd argument and it will return the error string instead of showing it in console [lua] local res = CompileString("syntax is for nubs","",false) if (type(res) == "string") then print("Error: "..res) --Error: [:1] '=' expected near 'is' else --compiled fine end [/lua]
[QUOTE=ralle105;29460915]Pass false as a 3rd argument and it will return the error string instead of showing it in console [lua] local res = CompileString("syntax is for nubs","",false) if (type(res) == "string") then print("Error: "..res) --Error: [:1] '=' expected near 'is' else --compiled fine end [/lua][/QUOTE] Ah, thanks a lot.
Sorry, you need to Log In to post a reply to this thread.