[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: comments, line numbers and storing a file in a single string
- From: KHMan <keinhong@...>
- Date: Wed, 12 Dec 2007 10:14:45 +0800
Eric Tetz wrote:
> On Dec 11, 2007 9:22 AM, Roger D. Vargas <firstname.lastname@example.org> 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 = 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")
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