lua-users home
lua-l archive

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


On Dec 11, 2007 9:22 AM, Roger D. Vargas <luo_hei@yahoo.es> 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
  function shout(msg)
    local noise = "*****"
    print(noise, string.toupper(msg), noise)
  end

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")