diff options
author | Luigi Scarso <luigi.scarso@gmail.com> | 2025-02-09 17:59:01 +0000 |
---|---|---|
committer | Luigi Scarso <luigi.scarso@gmail.com> | 2025-02-09 17:59:01 +0000 |
commit | 52c9f06eedb2ef405fda5b678df49ac00b860dbf (patch) | |
tree | 25408d0d2faca146d41615aa03c1bd00f2ba979f /Build/source/texk/web2c/luatexdir/lua | |
parent | 8e079734b6bb74af41bb0106fdedd98b07ca095b (diff) |
LuaTeX: Add token.unchecked_put_next, support setting the environment with os.spawn, permit usage of the img module in texlua mode (thanks to tex@maxchernoff.ca)
git-svn-id: svn://tug.org/texlive/trunk@73808 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c | 41 | ||||
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/loslibext.c | 24 | ||||
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/luastuff.c | 4 |
3 files changed, 64 insertions, 5 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c index 984e5094335..aa42038b378 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c @@ -336,6 +336,46 @@ inline static int run_put_next(lua_State * L) return 0; } +inline static int unchecked_put_next(lua_State * L) +{ + int n = lua_gettop(L); + int i = 1; + halfword h = null; + halfword t = null; + halfword x = null; + lua_token *p ; + switch (n) { + case 0: + return 0; + case 1: + break; + default: + normal_error("token lib","only one table permitted in put_next"); + return 0; + } + if (lua_type(L,1) == LUA_TTABLE) { + for (i = 1;; i++) { + lua_rawgeti(L, 1, i); + p = lua_touserdata(L, -1); + if (p == NULL) { + break; + } + fast_get_avail(x); + token_info(x) = token_info(p->token); + if (h == null) { + h = x; + } else { + token_link(t) = x; + } + t = x; + lua_pop(L, 1); + } + } + begin_token_list(h,0); + lua_settop(L,n); + return 0; +} + static int run_scan_keyword(lua_State * L) { saved_tex_scanner texstate; @@ -1409,6 +1449,7 @@ static const struct luaL_Reg tokenlib[] = { { "scan_list", run_scan_list }, /* writers */ { "put_next", run_put_next }, + { "unchecked_put_next", unchecked_put_next }, { "expand", run_expand }, /* getters */ { "get_command", lua_tokenlib_get_command }, diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c index 79368ef9262..e184a4624a6 100644 --- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c @@ -516,8 +516,8 @@ static int os_spawn(lua_State * L) char **cmdline = NULL; char **envblock = NULL; int i; - - if (lua_gettop(L) != 1) { + int top = lua_gettop(L); + if (top != 1 && top != 2) { lua_pushnil(L); lua_pushliteral(L, "invalid arguments passed"); return 2; @@ -533,6 +533,26 @@ static int os_spawn(lua_State * L) } else if (lua_type(L, 1) == LUA_TTABLE) { cmdline = do_flatten_command(L, &runcmd); } + /* Allow setting the environment */ + if (restrictedshell == 0 && top == 2 && lua_istable(L, 2)) { + const char *key, *val; + char *value; + int size = 0; + lua_pushnil(L); + while (lua_next(L, 2) != 0) { + if (lua_type(L, -2) == LUA_TSTRING && + lua_type(L, -1) == LUA_TSTRING) { + key = lua_tostring(L, -2); + val = lua_tostring(L, -1); + value = xmalloc((unsigned) (strlen(key) + strlen(val) + 2)); + sprintf(value, "%s=%s", key, val); + envblock = xreallocarray(envblock, char*, size++ + 1); + envblock[size] = value; + } + lua_pop(L, 1); + } + envblock[size++] = NULL; + } /* If restrictedshell == 0, any command is allowed. */ /* this is a little different from \write18/ os.execute processing * because it does not test for commands with fixed arguments, diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.c b/Build/source/texk/web2c/luatexdir/lua/luastuff.c index 62d21c3216e..808f12765aa 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luastuff.c +++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.c @@ -389,9 +389,7 @@ void luainterpreter(void) luaopen_pdf(L); luaopen_pdfe(L); luaopen_pdfscanner(L); - if (!lua_only) { - luaopen_img(L); - } + luaopen_img(L); lua_createtable(L, 0, 0); lua_setglobal(L, "texconfig"); Luas = L; |