Re: comments, line numbers and storing a file in a single

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: comments, line numbers and storing a file in a single

William Bubel

I believe the Debug library and API both have facilities for reporting code fragments in the case of errors, but I'll address the problem at hand. When you load up the strings of a file, typically the strings don't carry the newlines. These would need to be placed in. In the case of C code, that probably looks like this,

char * lineptr = 0, * linetosave;
size_t len = 0;
getline( &lineptr, &len, infile );
linetosave = (char *) malloc(len+2);
strcpy(linetosave, lineptr)
strcat(linetosave, "\n");
free(lineptr);

Within Lua, this is much easier (and a good reason why we like to use it).
linetosave = file:read("*l");
linetosave = linetosave .. "\n";


Reply | Threaded
Open this post in threaded view
|

Re: comments, line numbers and storing a file in a single

Luo Hei


W. C. Bubel escribió:

I believe the Debug library and API both have facilities for reporting code fragments in the case of errors, but I'll address the problem at
Interesting, I would like (besides fixing the current problem) to implement some debuging facilities in my project. Can you give some more details?


--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can’t take the sky from me

	
	
		
______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: comments, line numbers and storing a file in a single

William Bubel
In reply to this post by William Bubel
> Interesting, I would like (besides fixing the current problem) to implement some debuging facilities in my project. Can you give some more details?

In specific, the lua_getinfo function in the API can get code fragments out

lua_getinfo(L, ">S", &ar);
printf("%s", ar.source);

There's also plenty of info in the manuals, and on the wiki.

http://www.lua.org/manual/5.1/manual.html#3.8
http://www.lua.org/manual/5.1/manual.html#5.9
http://lua-users.org/wiki/DebuggingAndTesting