[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Parse/Compile time checking and information
- From: "Matt Holmes" <kerion@...>
- Date: Thu, 23 Aug 2001 16:10:13 -0400
Greetings,
I was wondering what the easiest way was to check the syntax of a block of
code (from a buffer), without executing was? I currently am doing the
following (taken from chunks of the lua_dobuffer() code):
bool VLCompiler::CheckSyntax(string sBuffer)
{
lua_State *cState;
struct lua_longjmp cLJ;
Proto *cClosure;
ZIO cIO;
int nStatus = 1;
cState = lua_open(100);
if(!cState)
return false;
luaZ_mopen(&cIO, sBuffer.c_str(), sBuffer.length(), "SyntaxCheck");
cLJ.status = 0;
cState->errorJmp = &cLJ;
if(setjmp(cLJ.b) == 0)
{
cClosure = luaY_parser(cState, &cIO);
luaV_Lclosure(cState, cClosure, 0);
}
nStatus = cLJ.status;
lua_close(cState);
if(nStatus >= 1)
return false;
else
return true;
}
This works, but it requires me to call some of the Lua internals, and I am
not sure if this is exactly "safe".
Also, what is the best way to extract the error messages when a compile
error occurs? Should I create a C tag method for _ERRORMESSAGE? And finally,
one last question. Is there any way to get the line number that the
compile/parse error occured on?
Thanks in advance,
Matt Holmes
Lead Developer
The Visual Lua Project
http://www.sourceforge.net/projects/visuallua/