From 1b23e934b0833637dfb5d82af670475db0b4e108 Mon Sep 17 00:00:00 2001 From: Taco Hoekwater Date: Sat, 1 Mar 2008 11:26:09 +0000 Subject: [PATCH] use the options hash to set file_finder instead of a separate function git-svn-id: svn+ssh://scm.foundry.supelec.fr/svn/metapost/mplib/trunk@352 b0617d17-b707-0410-b22c-fd2634e05cc4 --- src/texk/web2c/mpdir/lmplib.c | 25 +++++++++++------------ src/texk/web2c/mpdir/tests/test.lua | 31 ++++++++++++++--------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/texk/web2c/mpdir/lmplib.c b/src/texk/web2c/mpdir/lmplib.c index ac52fef..f19e32b 100644 --- a/src/texk/web2c/mpdir/lmplib.c +++ b/src/texk/web2c/mpdir/lmplib.c @@ -57,8 +57,8 @@ parm_struct img_parms[] = { {"command_line", P_COMMAND_LINE,'s' }, {"mem_name", P_MEM_NAME, 's' }, {"job_name", P_JOB_NAME, 's' }, -#if 0 {"find_file", P_FIND_FILE, 'p' }, +#if 0 {"open_file", P_OPEN_FILE, 'p' }, {"close_file", P_CLOSE_FILE, 'p' }, {"eof_file", P_EOF_FILE, 'p' }, @@ -122,22 +122,18 @@ char *mplib_find_file (char *fname, char *fmode, int ftype) { return NULL; } -int mplib_find_file_function (lua_State *L) { - if (lua_gettop(L)!=1 || (!(lua_isfunction(L,1) || lua_isnil(L,1) ))) { - lua_pop(L,1); - lua_pushnil(L); - lua_pushstring(L,"Invalid arguments to mp.find_file_function"); - return 2; - } - if (lua_isfunction(L,1)) { +static int +mplib_find_file_function (lua_State *L) { + if (lua_isfunction(L,-1)) { LL = L; - } else { + } else if (lua_isnil(L,-1)) { LL = NULL; + } else { + return 1; /* error */ } lua_pushstring(L, "mplib_file_finder"); lua_pushvalue(L,-2); lua_rawset(L,LUA_REGISTRYINDEX); - lua_pop(L,1); return 0; } @@ -434,8 +430,12 @@ mplib_new (lua_State *L) { case P_JOB_NAME: options->job_name = strdup((char *)lua_tostring(L,-1)); break; -#if 0 case P_FIND_FILE: + if(mplib_find_file_function(L)) { /* error here */ + fprintf(stdout,"Invalid arguments to mp.new({find_file=...})\n"); + } + break; +#if 0 case P_OPEN_FILE: case P_CLOSE_FILE: case P_EOF_FILE: @@ -674,7 +674,6 @@ static const struct luaL_reg mplib_d [] = { static const struct luaL_reg mplib_m[] = { {"new", mplib_new}, - {"find_file_function", mplib_find_file_function }, {NULL, NULL} /* sentinel */ }; diff --git a/src/texk/web2c/mpdir/tests/test.lua b/src/texk/web2c/mpdir/tests/test.lua index 8a892e5..f77313a 100644 --- a/src/texk/web2c/mpdir/tests/test.lua +++ b/src/texk/web2c/mpdir/tests/test.lua @@ -10,27 +10,13 @@ if false then mpx = nil; end -function finder (a,b,c) - print(a,b,c) - if a == "mpost.map" then - return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map" - end - if a =="cmr10.tfm" then - return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm" - end - return a -end - --- if you don't do this, it only finds local files -mp.find_file_function (finder) - function dorun (m, s) local v = m:execute(s) -- print ('<>') print ('<>') if v.fig then for _,gs in ipairs(v.fig) do - print(gs:postscript()) +-- print(gs:postscript()) end end end @@ -50,7 +36,20 @@ local lines = { "beginfig(7); label(\"stuff\", (0,0)); endfig;", } -mpx = mp.new({mem_name = "plain.mem", command_line = "\\relax "}) +function finder (a,b,c) + print(a,b,c) + if a == "mpost.map" then + return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map" + end + if a =="cmr10.tfm" then + return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm" + end + return a +end + +mpx = mp.new({mem_name = "plain.mem", + command_line = "\\relax ", + find_file = finder}) for _,l in ipairs(lines) do dorun (mpx, l) -- 2.32.0.93.g670b81a890