From 42c9773711a4a5af4e8a5115bfe9d5450c62c51e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sat, 31 Mar 2012 20:40:46 +0800 Subject: [PATCH] add: cache size control for djvureader --- djvu.c | 2 ++ djvureader.lua | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/djvu.c b/djvu.c index 6bcac2290..a5ab8380f 100644 --- a/djvu.c +++ b/djvu.c @@ -72,6 +72,7 @@ static int handle(lua_State *L, ddjvu_context_t *ctx, int wait) static int openDocument(lua_State *L) { const char *filename = luaL_checkstring(L, 1); /*const char *password = luaL_checkstring(L, 2);*/ + int cache_size = luaL_optint(L, 2, 10 << 20); DjvuDocument *doc = (DjvuDocument*) lua_newuserdata(L, sizeof(DjvuDocument)); luaL_getmetatable(L, "djvudocument"); @@ -81,6 +82,7 @@ static int openDocument(lua_State *L) { if (! doc->context) { return luaL_error(L, "cannot create context."); } + ddjvu_cache_set_size(doc->context, (unsigned long)cache_size); doc->doc_ref = ddjvu_document_create_by_filename_utf8(doc->context, filename, TRUE); while (! ddjvu_document_decoding_done(doc->doc_ref)) diff --git a/djvureader.lua b/djvureader.lua index cd0ad9885..0d38faf55 100644 --- a/djvureader.lua +++ b/djvureader.lua @@ -6,7 +6,7 @@ DJVUReader = UniReader:new{} -- DJVU does not support password yet function DJVUReader:open(filename) local ok - ok, self.doc = pcall(djvu.openDocument, filename) + ok, self.doc = pcall(djvu.openDocument, filename, 10*1024*1024) if not ok then return ok, self.doc -- this will be the error message instead end