lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

>Is there a way to check the syntax of or validate a
>lua script programmatically, without actually running it?

Not directly, but if you don't use "function x() .. end " constructions,
only "x=function() ... end", then you can put the whole chunk inside a fake
function and return it:

return function ()
	--- code for the chunk here

If this new chunk loads without errors, then there were not syntax errors
in the original chunk.
If you then want to run it, then save the results of dofile and then
call the first result as a function (which it is).

Perhaps we could remove the restriction that "function x() .. end" cannot
occur inside other functions, as has already been discussed here.
This would make the solution above completely general.