[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: comments, line numbers and storing a file in a single string
- From: "Eric Tetz" <erictetz@...>
- Date: Tue, 11 Dec 2007 11:54:48 -0800
On Dec 11, 2007 9:22 AM, Roger D. Vargas <email@example.com> wrote:
> Stefan Sandberg escribió:
> > ...which means your line breaks are missing.
> line breaks? Do I need DOS like line breaks?
You need *some* kind of line breaks.
If your code is supposed to be this:
-- yeah, this is silly
local noise = "*****"
print(noise, string.toupper(msg), noise)
And you store it like this:
-- yeah, this is silly function shout(msg) local noise = "*****"
print(noise, string.toupper(msg), noise) end
It's not going to work, right?
You shouldn't need to *add* line breaks... just don't remove them in
the first place. Sounds like maybe you are reading the file in some
sort of line-oriented mode which strips newlines, and you're not
re-adding the newlines. Better to just slurp the entire thing into a
buffer in one read. For instance (in Lua):
script_file = io.open("yourscript.lua", "rt")
script_text = script_file:read("*a") -- read entire file
Or better yet, since you're concerned with speed, load it and compile
it so it's ready to go:
script_code = loadfile("yourscript.lua")