lua-users home
lua-l archive

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


Sorry this is a bit late, been busy.  But thanks very much, this is exactly
what I need!

Chris Percival
Software Engineer
Interaxis Computing Ltd.
DDI:  +44 (0)1249 700072
http://www.interaxis.co.uk/

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Francis Irving
> Sent: 18 January 2002 16:55
> To: Multiple recipients of list
> Subject: Re: Syntax check
>
>
> On Thu, 17 Jan 2002 14:37:13 -0000, "Chris Percival"
> <cpercival@interaxis.co.uk> wrote:
>
> >Ah ok.  For a bit of background to my project, I will be trying
> to impliment
> >some kind of debugger, but first I just need to be able to have
> some kind of
> >syntax checking so the users of my application can 'test' their
> code before
> >actually running it.  I guess I have three options:
> >
> >1. Don't do any syntax checking.  The script just gets executed when they
> >hit go.  Then I would need to know how to get the debug/error messages
> >outputted where I wanted them (not to stdout which I guess they
> goto at the
> >moment).
>
> No, they don't go to stdout, they go to the _ERRORMESSAGE function.
> You can override _ERRORMESSAGE (either in Lua or in C) and do whatever
> you like.
>
> For example, this saves all error messages in a static string
> ourStringOutput (I'm using std::string in C++):
>
> 	lua_register(L,"_ERRORMESSAGE", StringPrint);
>
> 	static int __cdecl StringPrint(lua_State *L)
> 	{
> 		int n = lua_gettop(L);  /* number of arguments */
> 		int i;
> 		lua_getglobal(L, "tostring");
> 		for (i=1; i<=n; i++) {
> 			const char *s;
> 			lua_pushvalue(L, -1);  /* function to be
> called */
> 			lua_pushvalue(L, i);   /* value to print */
> 			lua_rawcall(L, 1, 1);
> 			s = lua_tostring(L, -1);  /* get result */
> 			if (s == NULL)
> 				lua_error(L, "`tostring' must return a
> string to `print'");
> 			if (i>1) ourStringOutput += "\t";
> 			ourStringOutput += s;
> 			lua_pop(L, 1);  /* pop result */
> 		}
> 		ourStringOutput += "\n";
> 		return 0;
> 	}
>
>
> Francis
>