lua-users home
lua-l archive

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

Eric Tetz wrote:
> On Dec 11, 2007 9:22 AM, Roger D. Vargas <> wrote:
>> Stefan Sandberg escribió:
>>> ...which means your line breaks are missing.
>> line breaks? Do I need DOS like line breaks?
> [snip] Better to just slurp the entire thing into a
> buffer in one read. For instance (in Lua):
>     script_file ="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")

I'll second that. Assuming your application scripts are hundreds
of KB or even a few MB, loading file(s)-at-once isn't too bad if
you're going to compile all of it quickly at the start. Desktop
memory is cheap, and we're not greedy or keeping the memory anyway
-- just garbage-collect the memory used to store the source
string(s) and we're done.

Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia