filecache.lua

Mon, 14 Sep 2009 00:16:13 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 14 Sep 2009 00:16:13 +0300
changeset 4
4cb0d1dbc65b
parent 3
b2df1b3f2c83
child 7
038275cd92ed
permissions
-rw-r--r--

fixes

3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 module("filecache", package.seeall)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 local cache={}
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 function get(file)
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 if not cache[file] then
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 local f=io.openX(file, "r")
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 cache[file]=f:read('*a')
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 f:close()
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 end
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 return cache[file]
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 end

mercurial