diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2015-11-14 00:48:08 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2015-11-14 00:48:08 +0000 |
commit | 64322869cd45fa0029198b6ef544363a0cf49eb6 (patch) | |
tree | faa34b755a1bd7b9b5ca4a66d204deebf841d119 /Build/source/texk/web2c/luatexdir/lua | |
parent | 6d37525a79984eea934633c34944113831e3fecb (diff) |
web2c/luatexdir: Sync with the upstream trunk.
git-svn-id: svn://tug.org/texlive/trunk@38844 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua')
21 files changed, 2351 insertions, 1838 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c index 96eafa8a22a..dee8057bb7b 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c @@ -1,5 +1,5 @@ /* lcallbacklib.c - + Copyright 2006-2008 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -20,15 +20,15 @@ #include "ptexlib.h" #include "lua/luatex-api.h" - int callback_count = 0; int saved_callback_count = 0; int callback_set[total_callbacks] = { 0 }; /* See also callback_callback_type in luatexcallbackids.h: they must have the same order ! */ + static const char *const callbacknames[] = { - "", /* empty on purpose */ + "", /* empty on purpose */ "find_write_file", "find_output_file", "find_image_file", @@ -62,18 +62,20 @@ static const char *const callbacknames[] = { "pre_linebreak_filter", "linebreak_filter", "post_linebreak_filter", + "append_to_vlist_filter", "mlist_to_hlist", "finish_pdffile", "finish_pdfpage", "pre_dump","start_file", "stop_file", "show_error_message","show_lua_error_hook", - "pdf_stream_filter_callback", + "show_warning_message", + "hpack_quality", "vpack_quality", NULL }; int callback_callbacks_id = 0; -int debug_callback_defined(int i) +int debug_callback_defined(int i) { printf ("callback_defined(%s)\n", callbacknames[i]); return callback_set[i]; @@ -82,14 +84,16 @@ int debug_callback_defined(int i) void get_lua_boolean(const char *table, const char *name, boolean * target) { int stacktop; + int t; stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_getglobal(Luas, table); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); - if (lua_isboolean(Luas, -1)) { + t = lua_type(Luas, -1); + if (t == LUA_TBOOLEAN) { *target = (boolean) (lua_toboolean(Luas, -1)); - } else if (lua_isnumber(Luas, -1)) { + } else if (t == LUA_TNUMBER) { *target = (boolean) (lua_tonumber(Luas, -1) == 0 ? 0 : 1); } } @@ -100,14 +104,16 @@ void get_lua_boolean(const char *table, const char *name, boolean * target) void get_saved_lua_boolean(int r, const char *name, boolean * target) { int stacktop; + int t; stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); - if (lua_isboolean(Luas, -1)) { + t = lua_type(Luas, -1); + if (t == LUA_TBOOLEAN) { *target = (boolean) lua_toboolean(Luas, -1); - } else if (lua_isnumber(Luas, -1)) { + } else if (t == LUA_TNUMBER) { *target = (boolean) (lua_tonumber(Luas, -1) == 0 ? 0 : 1); } } @@ -123,7 +129,7 @@ void get_lua_number(const char *table, const char *name, int *target) lua_getglobal(Luas, table); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); - if (lua_isnumber(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TNUMBER) { *target = (int)lua_tonumber(Luas, -1); } } @@ -139,7 +145,7 @@ void get_saved_lua_number(int r, const char *name, int *target) lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); if (lua_istable(Luas, -1)) { lua_getfield(Luas, -1, name); - if (lua_isnumber(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TNUMBER) { *target=(int)lua_tonumber(Luas, -1); } } @@ -147,16 +153,15 @@ void get_saved_lua_number(int r, const char *name, int *target) return; } - void get_lua_string(const char *table, const char *name, char **target) { int stacktop; stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_getglobal(Luas, table); - if (lua_istable(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TTABLE) { lua_getfield(Luas, -1, name); - if (lua_isstring(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TSTRING) { *target = xstrdup(lua_tostring(Luas, -1)); } } @@ -170,9 +175,9 @@ void get_saved_lua_string(int r, const char *name, char **target) stacktop = lua_gettop(Luas); luaL_checkstack(Luas, 2, "out of stack space"); lua_rawgeti(Luas, LUA_REGISTRYINDEX, r); - if (lua_istable(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TTABLE) { lua_getfield(Luas, -1, name); - if (lua_isstring(Luas, -1)) { + if (lua_type(Luas, -1) == LUA_TSTRING) { *target = xstrdup(lua_tostring(Luas, -1)); } } @@ -180,7 +185,6 @@ void get_saved_lua_string(int r, const char *name, char **target) return; } - #define CALLBACK_BOOLEAN 'b' #define CALLBACK_INTEGER 'd' #define CALLBACK_LINE 'l' @@ -188,7 +192,8 @@ void get_saved_lua_string(int r, const char *name, char **target) #define CALLBACK_STRING 'S' #define CALLBACK_CHARNUM 'c' #define CALLBACK_LSTRING 'L' - +#define CALLBACK_NODE 'N' +#define CALLBACK_DIR 'D' int run_saved_callback(int r, const char *name, const char *values, ...) { @@ -211,7 +216,6 @@ int run_saved_callback(int r, const char *name, const char *values, ...) return ret; } - boolean get_callback(lua_State * L, int i) { luaL_checkstack(L, 2, "out of stack space"); @@ -243,7 +247,6 @@ int run_and_save_callback(int i, const char *values, ...) return ret; } - int run_callback(int i, const char *values, ...) { va_list args; @@ -304,8 +307,13 @@ int do_run_callback(int special, const char *values, va_list vl) lua_pushboolean(L, va_arg(vl, int)); break; case CALLBACK_LINE: /* a buffer section, with implied start */ - lua_pushlstring(L, (char *) (buffer + first), - (size_t) va_arg(vl, int)); + lua_pushlstring(L, (char *) (buffer + first), (size_t) va_arg(vl, int)); + break; + case CALLBACK_NODE: + lua_nodelib_push_fast(L,va_arg(vl, int)); + break; + case CALLBACK_DIR: + lua_push_dir_par(L,va_arg(vl, int)); break; case '-': narg--; @@ -331,8 +339,8 @@ int do_run_callback(int special, const char *values, va_list vl) lua_active--; /* lua_remove(L, base); *//* remove traceback function */ if (i != 0) { - /* Can't be more precise here, could be called before - * TeX initialization is complete + /* Can't be more precise here, could be called before + * TeX initialization is complete */ if (!log_opened_global) { fprintf(stderr, "This went wrong: %s\n", lua_tostring(L, -1)); @@ -349,37 +357,38 @@ int do_run_callback(int special, const char *values, va_list vl) } nres = -nres; while (*values) { - int b; + int b, t; + halfword p; switch (*values++) { case CALLBACK_BOOLEAN: - if (!lua_isboolean(L, nres)) { - fprintf(stderr, "Expected a boolean, not: %s\n", - lua_typename(L, lua_type(L, nres))); + if (lua_type(L, nres) != LUA_TBOOLEAN) { + fprintf(stderr, "Expected a boolean, not: %s\n", lua_typename(L, lua_type(L, nres))); goto EXIT; } b = lua_toboolean(L, nres); *va_arg(vl, boolean *) = (boolean) b; break; case CALLBACK_INTEGER: - if (!lua_isnumber(L, nres)) { - fprintf(stderr, "Expected a number, not: %s\n", - lua_typename(L, lua_type(L, nres))); + if (lua_type(L, nres) != LUA_TNUMBER) { + fprintf(stderr, "Expected a number, not: %s\n", lua_typename(L, lua_type(L, nres))); goto EXIT; } - b=(int)lua_tonumber(L, nres); + b = (int) lua_tonumber(L, nres); *va_arg(vl, int *) = b; break; - case CALLBACK_LINE: /* TeX line */ - if (!lua_isstring(L, nres)) { - if (!lua_isnil(L, nres)) - fprintf(stderr, "Expected a string for (l), not: %s\n", - lua_typename(L, lua_type(L, nres))); + case CALLBACK_LINE: /* TeX line ... happens frequently when we have a plug-in */ + t = lua_type(L, nres); + if (t == LUA_TNIL) { + bufloc = 0; goto EXIT; - } - s = lua_tolstring(L, nres, &len); - if (s != NULL) { /* |len| can be zero */ - bufloc = va_arg(vl, int *); - if (len != 0) { + } else if (t == LUA_TSTRING) { + s = lua_tolstring(L, nres, &len); + if (s == NULL) { /* |len| can be zero */ + bufloc = 0; + } else if (len == 0) { + bufloc = 0; + } else { + bufloc = va_arg(vl, int *); ret = *bufloc; check_buffer_overflow(ret + (int) len); strncpy((char *) (buffer + ret), s, len); @@ -389,16 +398,14 @@ int do_run_callback(int special, const char *values, va_list vl) (*bufloc)--; } } else { - bufloc = 0; + fprintf(stderr, "Expected a string for (l), not: %s\n", lua_typename(L, lua_type(L, nres))); + goto EXIT; } break; case CALLBACK_STRNUMBER: /* TeX string */ - if (!lua_isstring(L, nres)) { - if (!lua_isnil(L, nres)) { - fprintf(stderr, "Expected a string for (s), not: %s\n", - lua_typename(L, lua_type(L, nres))); - goto EXIT; - } + if (lua_type(L, nres) != LUA_TSTRING) { + fprintf(stderr, "Expected a string for (s), not: %s\n", lua_typename(L, lua_type(L, nres))); + goto EXIT; } s = lua_tolstring(L, nres, &len); if (s == NULL) /* |len| can be zero */ @@ -408,15 +415,11 @@ int do_run_callback(int special, const char *values, va_list vl) } break; case CALLBACK_STRING: /* C string aka buffer */ - if (!lua_isstring(L, nres)) { - if (!lua_isnil(L, nres)) { - fprintf(stderr, "Expected a string for (S), not: %s\n", - lua_typename(L, lua_type(L, nres))); - goto EXIT; - } + if (lua_type(L, nres) != LUA_TSTRING) { + fprintf(stderr, "Expected a string for (S), not: %s\n", lua_typename(L, lua_type(L, nres))); + goto EXIT; } s = lua_tolstring(L, nres, &len); - if (s == NULL) /* |len| can be zero */ *va_arg(vl, int *) = 0; else { @@ -426,25 +429,29 @@ int do_run_callback(int special, const char *values, va_list vl) } break; case CALLBACK_LSTRING: /* lstring */ - if (!lua_isstring(L, nres)) { - if (!lua_isnil(L, nres)) { - fprintf(stderr, "Expected a string for (S), not: %s\n", - lua_typename(L, lua_type(L, nres))); - goto EXIT; - } + if (lua_type(L, nres) != LUA_TSTRING) { + fprintf(stderr, "Expected a string for (S), not: %s\n", lua_typename(L, lua_type(L, nres))); + goto EXIT; } s = lua_tolstring(L, nres, &len); - if (s == NULL) /* |len| can be zero */ *va_arg(vl, int *) = 0; else { - lstring *ret = xmalloc(sizeof(lstring)); + lstring *ret = xmalloc(sizeof(lstring)); ret->s = xmalloc((unsigned) (len + 1)); (void) memcpy(ret->s, s, (len + 1)); - ret->l = len; + ret->l = len; *va_arg(vl, lstring **) = ret; } break; + case CALLBACK_NODE: + if (lua_type(L,nres) == LUA_TNIL) { + p = null; + } else { + p = *check_isnode(L,nres); + } + *va_arg(vl, int *) = p; + break; default: fprintf(stdout, "invalid return value type"); goto EXIT; @@ -465,10 +472,15 @@ static int callback_register(lua_State * L) { int cb; const char *s; - if (!lua_isstring(L, 1) || - ((!lua_isfunction(L, 2)) && - (!lua_isnil(L, 2)) && - (!(lua_isboolean(L, 2) && lua_toboolean(L, 2) == 0)))) { + int t1, t2; + t1 = lua_type(L,1); + if (t1 != LUA_TSTRING) { + lua_pushnil(L); + lua_pushstring(L, "Invalid arguments to callback.register, first argument must be string."); + return 2; + } + t2 = lua_type(L,2); + if ((t2 != LUA_TFUNCTION) && (t2 != LUA_TNIL) && ((t2 != LUA_TBOOLEAN) && (lua_toboolean(L, 2) == 0))) { lua_pushnil(L); lua_pushstring(L, "Invalid arguments to callback.register."); return 2; @@ -483,9 +495,9 @@ static int callback_register(lua_State * L) lua_pushstring(L, "No such callback exists."); return 2; } - if (lua_isfunction(L, 2)) { + if (t2 == LUA_TFUNCTION) { callback_set[cb] = cb; - } else if (lua_isboolean(L, 2)) { + } else if (t2 == LUA_TBOOLEAN) { callback_set[cb] = -1; } else { callback_set[cb] = 0; @@ -503,7 +515,7 @@ static int callback_find(lua_State * L) { int cb; const char *s; - if (!lua_isstring(L, 1)) { + if (lua_type(L, 1) != LUA_TSTRING) { lua_pushnil(L); lua_pushstring(L, "Invalid arguments to callback.find."); return 2; @@ -524,7 +536,6 @@ static int callback_find(lua_State * L) return 1; } - static int callback_listf(lua_State * L) { int i; diff --git a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c index d6d52ae68fd..fa40150370c 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c @@ -41,9 +41,9 @@ static int font_read_tfm(lua_State * L) scaled s; int k; const char *cnom; - if (lua_isstring(L, 1)) { + if (lua_type(L, 1) == LUA_TSTRING) { cnom = lua_tostring(L, 1); - if (lua_isnumber(L, 2)) { + if (lua_type(L, 2) == LUA_TNUMBER) { s = (int) lua_tonumber(L, 2); if (strlen(cnom)) { f = get_fontid(); @@ -72,10 +72,10 @@ static int font_read_vf(lua_State * L) { int i; const char *cnom; - if (lua_isstring(L, 1)) { + if (lua_type(L, 1) == LUA_TSTRING) { cnom = lua_tostring(L, 1); if (strlen(cnom)) { - if (lua_isnumber(L, 2)) { + if (lua_type(L, 2) == LUA_TNUMBER) { i = (int) lua_tonumber(L, 2); return make_vf_table(L, cnom, (scaled) i); } else { @@ -296,7 +296,7 @@ static int l_vf_char(lua_State * L) internal_font_number lf = vsp->lf; int ex_glyph = vsp->ex_glyph/1000; if (!vsp->vflua) - pdf_error("vf", "vf.char() outside virtual font"); + normal_error("vf", "vf.char() outside virtual font"); k = (int) luaL_checkinteger(L, 1); if (!char_exists(lf, (int) k)) { char_warning(lf, (int) k); @@ -319,7 +319,7 @@ static int l_vf_down(lua_State * L) vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; if (!vsp->vflua) - pdf_error("vf", "vf.down() outside virtual font"); + normal_error("vf", "vf.down() outside virtual font"); i = (scaled) luaL_checkinteger(L, 1); i = store_scaled_f(i, vsp->fs_f); mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); @@ -332,7 +332,7 @@ static int l_vf_fontid(lua_State * L) { vf_struct *vsp = static_pdf->vfstruct; if (!vsp->vflua) - pdf_error("vf", "vf.fontid() outside virtual font"); + normal_error("vf", "vf.fontid() outside virtual font"); vsp->lf = (int) luaL_checkinteger(L, 1); return 0; } @@ -342,7 +342,7 @@ static int l_vf_image(lua_State * L) int k; vf_struct *vsp = static_pdf->vfstruct; if (!vsp->vflua) - pdf_error("vf", "vf.image() outside virtual font"); + normal_error("vf", "vf.image() outside virtual font"); k = (int) luaL_checkinteger(L, 1); vf_out_image(static_pdf, k); return 0; @@ -353,7 +353,7 @@ static int l_vf_node(lua_State * L) int k; vf_struct *vsp = static_pdf->vfstruct; if (!vsp->vflua) - pdf_error("vf", "vf.node() outside virtual font"); + normal_error("vf", "vf.node() outside virtual font"); k = (int) luaL_checkinteger(L, 1); hlist_out(static_pdf, (halfword) k); return 0; @@ -363,7 +363,7 @@ static int l_vf_nop(lua_State * L) { vf_struct *vsp = static_pdf->vfstruct; if (!vsp->vflua) - pdf_error("vf", "vf.nop() outside virtual font"); + normal_error("vf", "vf.nop() outside virtual font"); return 0; } @@ -372,9 +372,9 @@ static int l_vf_pop(lua_State * L) vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; if (!vsp->vflua) - pdf_error("vf", "vf.pop() outside virtual font"); + normal_error("vf", "vf.pop() outside virtual font"); if (vsp->packet_stack_level == vsp->packet_stack_minlevel) - pdf_error("vf", "packet_stack_level underflow"); + normal_error("vf", "packet_stack_level underflow"); vsp->packet_stack_level--; mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos); @@ -386,11 +386,11 @@ static int l_vf_push(lua_State * L) vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; if (!vsp->vflua) - pdf_error("vf", "vf.push() outside virtual font"); + normal_error("vf", "vf.push() outside virtual font"); mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); vsp->packet_stack_level++; if (vsp->packet_stack_level == packet_stack_size) - pdf_error("vf", "packet_stack_level overflow"); + normal_error("vf", "packet_stack_level overflow"); vsp->packet_stack[vsp->packet_stack_level] = *mat_p; mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); return 0; @@ -402,7 +402,7 @@ static int l_vf_right(lua_State * L) vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; if (!vsp->vflua) - pdf_error("vf", "vf.right() outside virtual font"); + normal_error("vf", "vf.right() outside virtual font"); mat_p = &(vsp->packet_stack[vsp->packet_stack_level]); i = (scaled) luaL_checkinteger(L, 1); i = store_scaled_f(i, vsp->fs_f); @@ -417,7 +417,7 @@ static int l_vf_rule(lua_State * L) vf_struct *vsp = static_pdf->vfstruct; packet_stack_record *mat_p; if (!vsp->vflua) - pdf_error("vf", "vf.rule() outside virtual font"); + normal_error("vf", "vf.rule() outside virtual font"); size.h = (scaled) luaL_checkinteger(L, 1); size.v = (scaled) luaL_checkinteger(L, 2); size.h = store_scaled_f(size.h, vsp->fs_f); @@ -436,7 +436,7 @@ static int l_vf_special(lua_State * L) int texstr; vf_struct *vsp = static_pdf->vfstruct; if (!vsp->vflua) - pdf_error("vf", "vf.special() outside virtual font"); + normal_error("vf", "vf.special() outside virtual font"); st.s = lua_tolstring(L, 1, &(st.l)); texstr = maketexlstring(st.s, st.l); pdf_literal(static_pdf, texstr, scan_special, false); diff --git a/Build/source/texk/web2c/luatexdir/lua/limglib.c b/Build/source/texk/web2c/luatexdir/lua/limglib.c index 127faede0c7..1feb540e4c8 100644 --- a/Build/source/texk/web2c/luatexdir/lua/limglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/limglib.c @@ -1,5 +1,5 @@ /* limglib.c - + Copyright 2006-2013 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -95,12 +95,30 @@ static const parm_struct img_parms[] = { }; #define imgtype_max 7 -const char *imgtype_s[] = - { "none", "pdf", "png", "jpg", "jp2", "jbig2", "stream", "memstream",NULL }; + +const char *imgtype_s[] = { + "none", + "pdf", + "png", + "jpg", + "jp2", + "jbig2", + "stream", + "memstream", + NULL +}; #define pagebox_max 5 -const char *pdfboxspec_s[] = - { "none", "media", "crop", "bleed", "trim", "art", NULL }; + +const char *pdfboxspec_s[] = { + "none", + "media", + "crop", + "bleed", + "trim", + "art", + NULL +}; /**********************************************************************/ @@ -113,9 +131,8 @@ static void image_to_lua(lua_State * L, image * a) lua_gettable(L, LUA_REGISTRYINDEX); /* t k u ... */ lua_pushvalue(L, -2); /* k t k u ... */ lua_gettable(L, -2); /* i? t k u ... */ - if (!lua_isnumber(L, -1)) /* !i t k u ... */ - luaL_error(L, "image_to_lua(): %s is not a valid image key", - lua_tostring(L, -3)); + if (lua_type(L, -1) != LUA_TNUMBER) /* !i t k u ... */ + luaL_error(L, "image_to_lua(): %s is not a valid image key", lua_tostring(L, -3)); i = (int) lua_tointeger(L, -1); /* i t k u ... */ lua_pop(L, 3); /* u ... */ switch (i) { @@ -283,9 +300,8 @@ static void lua_to_image(lua_State * L, image * a) lua_gettable(L, LUA_REGISTRYINDEX); /* t v k t ... */ lua_pushvalue(L, -3); /* k t v k t ... */ lua_gettable(L, -2); /* i? t v k t ... */ - if (!lua_isnumber(L, -1)) /* !i t v k t ... */ - luaL_error(L, "lua_to_image(): %s is not a valid image key", - lua_tostring(L, -4)); + if (lua_type(L, -1) != LUA_TNUMBER) /* !i t v k t ... */ + luaL_error(L, "lua_to_image(): %s is not a valid image key", lua_tostring(L, -4)); i = (int) lua_tointeger(L, -1); /* i t v k t ... */ lua_pop(L, 2); /* v k t ... */ switch (i) { @@ -297,8 +313,7 @@ static void lua_to_image(lua_State * L, image * a) else if (lua_type(L, -1) == LUA_TSTRING) img_width(a) = dimen_to_number(L, lua_tostring(L, -1)); else - luaL_error(L, - "image.width needs integer or nil value or dimension string"); + luaL_error(L, "image.width needs integer or nil value or dimension string"); break; case P_HEIGHT: if (lua_isnil(L, -1)) @@ -308,8 +323,7 @@ static void lua_to_image(lua_State * L, image * a) else if (lua_type(L, -1) == LUA_TSTRING) img_height(a) = dimen_to_number(L, lua_tostring(L, -1)); else - luaL_error(L, - "image.height needs integer or nil value or dimension string"); + luaL_error(L, "image.height needs integer or nil value or dimension string"); break; case P_DEPTH: if (lua_isnil(L, -1)) @@ -319,11 +333,10 @@ static void lua_to_image(lua_State * L, image * a) else if (lua_type(L, -1) == LUA_TSTRING) img_depth(a) = dimen_to_number(L, lua_tostring(L, -1)); else - luaL_error(L, - "image.depth needs integer or nil value or dimension string"); + luaL_error(L, "image.depth needs integer or nil value or dimension string"); break; case P_TRANSFORM: - if (lua_isnumber(L, -1)) + if (lua_type(L, -1) == LUA_TNUMBER) img_transform(a) = (int) lua_tointeger(L, -1); else luaL_error(L, "image.transform needs integer value"); @@ -334,7 +347,7 @@ static void lua_to_image(lua_State * L, image * a) luaL_error(L, "image.filename is now read-only"); if (img_type(d) == IMG_TYPE_PDFSTREAM) luaL_error(L, "image.filename can't be used with image.stream"); - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { xfree(img_filename(d)); img_filename(d) = xstrdup(lua_tostring(L, -1)); } else @@ -344,9 +357,8 @@ static void lua_to_image(lua_State * L, image * a) if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.visiblefilename is now read-only"); if (img_type(d) == IMG_TYPE_PDFSTREAM) - luaL_error(L, - "image.visiblefilename can't be used with image.stream"); - if (lua_isstring(L, -1)) { + luaL_error(L, "image.visiblefilename can't be used with image.stream"); + if (lua_type(L, -1) == LUA_TSTRING) { xfree(img_visiblefilename(d)); img_visiblefilename(d) = xstrdup(lua_tostring(L, -1)); } else @@ -355,10 +367,11 @@ static void lua_to_image(lua_State * L, image * a) case P_ATTR: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.attr is now read-only"); - if (lua_isstring(L, -1) || lua_isnil(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { + xfree(img_attr(d)); + img_attr(d) = xstrdup(lua_tostring(L, -1)); + } else if (lua_type(L, -1) == LUA_TNIL) { xfree(img_attr(d)); - if (lua_isstring(L, -1)) - img_attr(d) = xstrdup(lua_tostring(L, -1)); } else luaL_error(L, "image.attr needs string or nil value"); break; @@ -380,7 +393,7 @@ static void lua_to_image(lua_State * L, image * a) luaL_error(L, "image.colorspace is now read-only"); if (lua_isnil(L, -1)) img_colorspace(d) = 0; - else if (lua_isnumber(L, -1)) + else if (lua_type(L, -1) == LUA_TNUMBER) img_colorspace(d) = (int) lua_tointeger(L, -1); else luaL_error(L, "image.colorspace needs integer or nil value"); @@ -388,9 +401,9 @@ static void lua_to_image(lua_State * L, image * a) case P_PAGEBOX: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.pagebox is now read-only"); - if (lua_isnil(L, -1)) + if (lua_type(L, -1) == LUA_TNIL) img_pagebox(d) = PDF_BOX_SPEC_NONE; - else if (lua_isstring(L, -1)) + else if (lua_type(L, -1) == LUA_TSTRING) img_pagebox(d) = luaL_checkoption(L, -1, "none", pdfboxspec_s); else luaL_error(L, "image.pagebox needs string or nil value"); @@ -410,8 +423,7 @@ static void lua_to_image(lua_State * L, image * a) else if (lua_type(L, -1) == LUA_TSTRING) img_bbox(d)[i - 1] = dimen_to_number(L, lua_tostring(L, -1)); else - luaL_error(L, - "image.bbox table needs integer value or dimension string elements"); + luaL_error(L, "image.bbox table needs integer value or dimension string elements"); lua_pop(L, 1); /* v k t ... */ } img_set_bbox(d); @@ -558,18 +570,25 @@ static halfword img_to_node(image * a) ad = img_dict(a); assert(ad != NULL); assert(img_objnum(ad) != 0); - n = new_node(whatsit_node, pdf_refximage_node); - pdf_ximage_index(n) = img_index(ad); + n = new_rule(image_rule); + rule_index(n) = img_index(ad); width(n) = img_width(a); height(n) = img_height(a); depth(n) = img_depth(a); - pdf_ximage_transform(n) = img_transform(a); + rule_transform(n) = img_transform(a); return n; } -typedef enum { WR_WRITE, WR_IMMEDIATEWRITE, WR_NODE, WR_VF_IMG } wrtype_e; -const char *wrtype_s[] = - { "img.write()", "img.immediatewrite()", "img.node()", "write vf image" }; +typedef enum { + WR_WRITE, + WR_IMMEDIATEWRITE, + WR_NODE, + WR_VF_IMG +} wrtype_e; + +const char *wrtype_s[] = { + "img.write()", "img.immediatewrite()", "img.node()", "write vf image" +}; static void setup_image(PDF pdf, image * a, wrtype_e writetype) { @@ -737,10 +756,10 @@ static int m_img_set(lua_State * L) static int m_img_mul(lua_State * L) { lua_Number scale; - if (lua_isnumber(L, 1)) { /* u? n */ + if (lua_type(L, 1) == LUA_TNUMBER) { /* u? n */ (void) luaL_checkudata(L, 2, TYPE_IMG); /* u n */ lua_insert(L, -2); /* n a */ - } else if (lua_isnumber(L, 2)) { /* n u? */ + } else if (lua_type(L, 2) != LUA_TNUMBER) { /* n u? */ (void) luaL_checkudata(L, 1, TYPE_IMG); /* n a */ } /* n a */ scale = lua_tonumber(L, 2); /* n a */ @@ -756,11 +775,9 @@ static int m_img_print(lua_State * L) aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); d = img_dict(*aa); if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) - lua_pushfstring(L, "<img{filename=\"%s\", page=\"%s\"}>", - img_filename(d), img_pagename(d)); + lua_pushfstring(L, "<img{filename=\"%s\", page=\"%s\"}>", img_filename(d), img_pagename(d)); else - lua_pushfstring(L, "<img{filename=\"%s\", page=%d}>", img_filename(d), - img_pagenum(d)); + lua_pushfstring(L, "<img{filename=\"%s\", page=%d}>", img_filename(d), img_pagenum(d)); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c index d53c50426e4..d2fadcbfc26 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c @@ -1,5 +1,5 @@ /* lkpselib.c - + Copyright 2006-2008 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -184,24 +184,27 @@ int program_name_set = 0; static int find_file(lua_State * L) { - int i; + int i, t; const char *st; unsigned ftype = kpse_tex_format; int mexist = 0; TEST_PROGRAM_NAME_SET; - if (!lua_isstring(L, 1)) { + if (lua_type(L, 1) != LUA_TSTRING) { luaL_error(L, "not a file name"); } st = lua_tostring(L, 1); i = lua_gettop(L); while (i > 1) { - if (lua_isboolean(L, i)) { + t = lua_type(L, i) ; + if (t == LUA_TBOOLEAN) { mexist = lua_toboolean(L, i); - } else if (lua_isnumber(L, i)) { + } else if (t == LUA_TNUMBER) { mexist=(int)lua_tonumber(L, i); - } else if (lua_isstring(L, i)) { + } else if (t == LUA_TSTRING) { int op = luaL_checkoption(L, i, NULL, filetypenames); ftype = filetypes[op]; + } else { + /* ignore */ } i--; } @@ -223,30 +226,30 @@ static int find_file(lua_State * L) static int lua_kpathsea_find_file(lua_State * L) { - int i; + int i, t; unsigned ftype = kpse_tex_format; int mexist = 0; kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *st = luaL_checkstring(L, 2); i = lua_gettop(L); while (i > 2) { - if (lua_isboolean(L, i)) { + t = lua_type(L, i) ; + if (t == LUA_TBOOLEAN) { mexist = (boolean) lua_toboolean(L, i); - } else if (lua_isnumber(L, i)) { + } else if (t == LUA_TNUMBER) { mexist=(int)lua_tonumber(L, i); - } else if (lua_isstring(L, i)) { + } else if (t == LUA_TSTRING) { int op = luaL_checkoption(L, i, NULL, filetypenames); ftype = filetypes[op]; + } else { + /* ignore */ } i--; } - if (ftype == kpse_pk_format || - ftype == kpse_gf_format || ftype == kpse_any_glyph_format) { + if (ftype == kpse_pk_format || ftype == kpse_gf_format || ftype == kpse_any_glyph_format) { /* ret.format, ret.name, ret.dpi */ kpse_glyph_file_type ret; - lua_pushstring(L, - kpathsea_find_glyph(*kp, st, (unsigned) mexist, ftype, - &ret)); + lua_pushstring(L, kpathsea_find_glyph(*kp, st, (unsigned) mexist, ftype, &ret)); } else { if (mexist > 0) mexist = 1; @@ -368,7 +371,7 @@ static unsigned find_dpi(const_string s) is, for a string S in MATCHES, its dirname must end with one of the elements in SUBDIRS. For instance, if subdir=foo/bar, that will match a string foo/bar/baz or /some/texmf/foo/bar/baz. - + We don't reallocate the actual strings, just the list elements. Perhaps later we will implement wildcards or // or something. */ @@ -599,17 +602,17 @@ static int do_lua_kpathsea_lookup(lua_State * L, kpathsea kpse, int idx) if (lua_istable(L, -1)) { lua_pushnil(L); while (lua_next(L, -2) != 0) { /* numeric value */ - if (lua_isstring(L, -1)) { - char *s = xstrdup(lua_tostring(L, -1)); + if (lua_type(L, -1) == LUA_TSTRING) { + char *s = xstrdup(lua_tostring(L, -1)); str_list_add(&subdir_paths, s); - xfree(s); + xfree(s); } lua_pop(L, 1); } - } else if (lua_isstring(L, -1)) { - char *s = xstrdup(lua_tostring(L, -1)); + } else if (lua_type(L, -1) == LUA_TSTRING) { + char *s = xstrdup(lua_tostring(L, -1)); str_list_add(&subdir_paths, s); - xfree(s); + xfree(s); } lua_pop(L, 1); if (STR_LIST_LENGTH(subdir_paths) > 0) { diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c index 616c0713a18..645780ca1c7 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c @@ -62,7 +62,7 @@ static int lang_patterns(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isstring(L, 2)) { + if (lua_type(L, 2) != LUA_TSTRING) { return luaL_error(L, "lang.patterns(): argument should be a string"); } load_patterns(*lang_ptr, (const unsigned char *) lua_tostring(L, 2)); @@ -91,7 +91,7 @@ static int lang_hyphenation(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isstring(L, 2)) { + if (lua_type(L, 2) != LUA_TSTRING) { return luaL_error(L, "lang.hyphenation(): argument should be a string"); } @@ -112,9 +112,8 @@ static int lang_pre_hyphen_char(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isnumber(L, 2)) { - return luaL_error(L, - "lang.prehyphenchar(): argument should be a character number"); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.prehyphenchar(): argument should be a character number"); } (*lang_ptr)->pre_hyphen_char=(int)lua_tonumber(L, 2); return 0; @@ -129,9 +128,8 @@ static int lang_post_hyphen_char(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isnumber(L, 2)) { - return luaL_error(L, - "lang.posthyphenchar(): argument should be a character number"); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.posthyphenchar(): argument should be a character number"); } (*lang_ptr)->post_hyphen_char=(int)lua_tonumber(L, 2); return 0; @@ -147,9 +145,8 @@ static int lang_pre_exhyphen_char(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isnumber(L, 2)) { - return luaL_error(L, - "lang.preexhyphenchar(): argument should be a character number"); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.preexhyphenchar(): argument should be a character number"); } (*lang_ptr)->pre_exhyphen_char=(int)lua_tonumber(L, 2); return 0; @@ -164,9 +161,8 @@ static int lang_post_exhyphen_char(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isnumber(L, 2)) { - return luaL_error(L, - "lang.postexhyphenchar(): argument should be a character number"); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.postexhyphenchar(): argument should be a character number"); } (*lang_ptr)->post_exhyphen_char=(int)lua_tonumber(L, 2); return 0; @@ -182,9 +178,8 @@ static int lang_hyphenation_min(lua_State * L) struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { - if (!lua_isnumber(L, 2)) { - return luaL_error(L, - "lang.hyphenationmin(): argument should be a number"); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.hyphenationmin(): argument should be a number"); } (*lang_ptr)->hyphenation_min=(int)lua_tonumber(L, 2); return 0; @@ -206,8 +201,8 @@ static int lang_clear_hyphenation(lua_State * L) static int do_lang_clean(lua_State * L) { char *cleaned; - if (!lua_isstring(L, 1)) { - return luaL_error(L, "lang.clean(): argument should be a string"); + if (lua_type(L, 1) != LUA_TSTRING) { + return luaL_error(L, "lang.clean(): argument should be a string"); } (void) clean_hyphenation(lua_tostring(L, 1), &cleaned); lua_pushstring(L, cleaned); diff --git a/Build/source/texk/web2c/luatexdir/lua/llualib.c b/Build/source/texk/web2c/luatexdir/lua/llualib.c index 23bec6bfc0a..a8760674911 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llualib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llualib.c @@ -1,5 +1,5 @@ /* llualib.c - + Copyright 2006-2008 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -90,7 +90,7 @@ void undump_luac_registers(void) if (luabytecode_max >= 0) { i = (unsigned) (luabytecode_max + 1); if ((int) (UINT_MAX32 / (int) sizeof(bytecode) + 1) <= i) { - lua_fatal_error("Corrupt format file"); + fatal_error("Corrupt format file"); } lua_bytecode_registers = xmalloc((unsigned) (i * sizeof(bytecode))); luabytecode_bytes = (unsigned) (i * sizeof(bytecode)); @@ -278,7 +278,7 @@ static int set_luaname(lua_State * L) free(luanames[k]); luanames[k] = NULL; } - if (lua_isstring(L, 3)) { + if (lua_type(L,3) == LUA_TSTRING) { s = lua_tostring(L, 3); if (s != NULL) luanames[k] = xstrdup(s); diff --git a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c index df7bebf9c67..68bd21199b5 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c @@ -64,7 +64,7 @@ typedef struct saved_tex_scanner { static lua_token *check_istoken(lua_State * L, int ud); -#define TOKEN_METATABLE "luatex_newtoken" +#define TOKEN_METATABLE "luatex_token" #define DEBUG 0 #define DEBUG_OUT stdout @@ -95,7 +95,7 @@ static lua_token *maybe_istoken(lua_State * L, int ud) lua_token *p = lua_touserdata(L, ud); if (p != NULL) { if (lua_getmetatable(L, ud)) { - lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_newtoken)); + lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_token)); lua_gettable(L, LUA_REGISTRYINDEX); if (!lua_rawequal(L, -1, -2)) p = NULL; @@ -126,7 +126,7 @@ static void make_new_token(lua_State * L, int cmd, int chr, int cs) fast_get_avail(thetok->token); tok = (cs ? cs_token_flag + cs : token_val(cmd, chr)); set_token_info(thetok->token, tok); - lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_newtoken)); + lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_token)); lua_gettable(L, LUA_REGISTRYINDEX); lua_setmetatable(L, -2); } @@ -136,7 +136,7 @@ static void push_token(lua_State * L, int tok) lua_token *thetok = lua_newuserdata(L, sizeof(lua_token)); thetok->origin = LUA_ORIGIN; thetok->token = tok; - lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_newtoken)); + lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_token)); lua_gettable(L, LUA_REGISTRYINDEX); lua_setmetatable(L, -2); } @@ -151,7 +151,7 @@ static void push_token(lua_State * L, int tok) /* static int run_get_command_id(lua_State * L) */ /* { */ /* int cs = -1; */ -/* if (lua_isstring(L, -1)) { */ +/* if (lua_type(L, -1) == LUA_TSTRING) { */ /* cs = get_command_id(lua_tostring(L, -1)); */ /* } */ /* lua_pushnumber(L, cs); */ @@ -162,7 +162,7 @@ static void push_token(lua_State * L, int tok) /* { */ /* const char *s; */ /* size_t k, cs = 0; */ -/* if (lua_isstring(L, -1)) { */ +/* if (lua_type(L, -1) == LUA_TSTRING) { */ /* s = lua_tolstring(L, -1, &k); */ /* cs = (size_t) string_lookup(s, k); */ /* } */ @@ -405,7 +405,7 @@ static int run_lookup(lua_State * L) const char *s; size_t l; int cs, cmd, chr; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { s = lua_tolstring(L, -1, &l); if (l > 0) { cs = string_lookup(s, l); @@ -422,7 +422,7 @@ static int run_lookup(lua_State * L) static int run_build(lua_State * L) { int cmd, chr, cs; - if (lua_isnumber(L, 1)) { + if (lua_type(L, 1) == LUA_TNUMBER) { cs = 0; chr = (int) lua_tointeger(L, 1); cmd = (int) luaL_optinteger(L, 2, get_cat_code(int_par(cat_code_table_code),chr)); @@ -460,7 +460,7 @@ static int lua_tokenlib_getfield(lua_State * L) { lua_token *n; const char *s; - halfword t ; + halfword t, e ; n = check_istoken(L, 1); s = lua_tostring(L, 2); t = token_info(n->token); @@ -470,9 +470,40 @@ static int lua_tokenlib_getfield(lua_State * L) } else { lua_pushnumber(L, token_cmd(t)); } + } else if (lua_key_eq(s, index)) { + int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); + e = equiv(t - cs_token_flag); + switch (cmd) { + case assign_int_cmd: + e -= count_base; + break; + case assign_attr_cmd: + e -= attribute_base; + break; + case assign_dimen_cmd: + e -= dimen_base; + break; + case assign_glue_cmd: + e -= skip_base; + break; + case assign_mu_glue_cmd: + e -= mu_skip_base; + break; + case assign_toks_cmd: + e -= toks_base; + break; + default: + e = -1; + break; + } + if ((e >= 0) && (e <= 65535)) { + lua_pushnumber(L, e); + } else { + lua_pushnil(L); + } } else if (lua_key_eq(s, mode)) { if (t >= cs_token_flag) { - lua_pushnumber(L, equiv((t - cs_token_flag))); + lua_pushnumber(L, equiv(t - cs_token_flag)); } else { lua_pushnumber(L, token_chr(t)); } @@ -487,7 +518,7 @@ static int lua_tokenlib_getfield(lua_State * L) else lua_pushstring(L, (char *) s); } else { - lua_pushstring(L, ""); + lua_pushnil(L); } } else if (lua_key_eq(s, id)) { lua_pushnumber(L, n->token); @@ -577,6 +608,7 @@ static int run_scan_token(lua_State * L) /* [catcodetable] csname : \def\csname{} */ /* TODO: check for a quick way to set a macro to empty (HH) */ + static int set_macro(lua_State * L) { const char *name = null; @@ -591,7 +623,7 @@ static int set_macro(lua_State * L) if (n == 0) { return 0 ; } - if (lua_isnumber(L, 1)) { + if (lua_type(L, 1) == LUA_TNUMBER) { if (n == 1) return 0; ct = (int) lua_tointeger(L, 1); @@ -659,7 +691,7 @@ static int set_macro(lua_State * L) } } if (_s > 0) { - /* we havea potential \cs */ + /* we have a potential \cs */ _cs = string_lookup(_name, _lname); if (_cs == undefined_control_sequence) { /* let's play safe and backtrack */ @@ -729,11 +761,11 @@ static const struct luaL_Reg tokenlib_m[] = { -int luaopen_newtoken(lua_State * L) +int luaopen_token(lua_State * L) { /* the main metatable of token userdata */ luaL_newmetatable(L, TOKEN_METATABLE); luaL_register(L, NULL, tokenlib_m); - luaL_register(L, "newtoken", tokenlib); + luaL_register(L, "token", tokenlib); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c index 215297b3be1..437864c87a1 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c @@ -148,7 +148,7 @@ lua_getmetatable(L,1); \ lua_setmetatable(L,-2); \ } else { \ - lua_pushnil(L); \ + lua_pushnil(L); \ } \ } while (0) @@ -192,6 +192,14 @@ } \ } while (0) +#define nodelib_check_glue_spec(n) do { \ + n = glue_ptr(n); \ + if ((!n) || (!valid_node(n))) { \ + n = new_node(glue_spec_node,0); \ + glue_ptr(n) = n; \ + } \ +} while (0) + /* handy sometimes: */ /* static void stackDump (lua_State * L) { */ @@ -224,18 +232,6 @@ #define nodelib_getspec nodelib_getlist #define nodelib_getaction nodelib_getlist -/* a quick helper for dir nodes; there is only a small set of possible values */ - -#define RETURN_DIR_VALUES(a) \ -if (s==luaS_##a##_ptr) { \ - return (dir_##a); \ -} else if (!absolute_only) { \ - if (s==luaS_p##a##_ptr) \ - return (dir_##a); \ - else if (s==luaS_m##a##_ptr) \ - return ((dir_##a)-64); \ -} - /* fetching a field from a node .. we can often use the reuse bot-of-stack metatable */ #define nodelib_pushlist(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); } /* can be: fast_metatable_or_nil(n) */ @@ -270,11 +266,11 @@ while (vlink(t)!=current && t != null) { \ /* maybe these qualify as macros, not functions */ -static halfword *maybe_isnode(lua_State * L, int ud) +static halfword *maybe_isnode(lua_State * L, int i) { - halfword *p = lua_touserdata(L, ud); + halfword *p = lua_touserdata(L, i); if (p != NULL) { - if (lua_getmetatable(L, ud)) { + if (lua_getmetatable(L, i)) { lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_node)); lua_gettable(L, LUA_REGISTRYINDEX); if (!lua_rawequal(L, -1, -2)) @@ -287,12 +283,12 @@ static halfword *maybe_isnode(lua_State * L, int ud) /* we could make the message a function and just inline the rest (via a macro) */ -halfword *check_isnode(lua_State * L, int ud) +halfword *check_isnode(lua_State * L, int i) { - halfword *p = maybe_isnode(L, ud); + halfword *p = maybe_isnode(L, i); if (p != NULL) return p; - luatex_fail("There should have been a lua <node> here, not an object with type %s!", luaL_typename(L, ud)); + luatex_fail("There should have been a lua <node> here, not an object with type %s!", luaL_typename(L, i)); return NULL; } @@ -434,7 +430,7 @@ void lua_nodelib_push(lua_State * L) halfword n; halfword *a; n = -1; - if (lua_isnumber(L, -1)) + if (lua_type(L, -1) == LUA_TNUMBER) n = (int) lua_tointeger(L, -1); lua_pop(L, 1); if ((n == null) || (n < 0) || (n > var_mem_max)) { @@ -456,7 +452,7 @@ static void lua_nodelib_push_spec(lua_State * L) halfword n; halfword *a; n = -1; - if (lua_isnumber(L, -1)) + if (lua_type(L, -1) == LUA_TNUMBER) n = (halfword) lua_tointeger(L, -1); lua_pop(L, 1); if ((n < 0) || (n > var_mem_max)) { @@ -474,11 +470,15 @@ static void lua_nodelib_push_spec(lua_State * L) void lua_nodelib_push_fast(lua_State * L, halfword n) { halfword *a; - a = lua_newuserdata(L, sizeof(halfword)); - *a = n; - lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_node)); - lua_gettable(L, LUA_REGISTRYINDEX); - lua_setmetatable(L, -2); + if (n) { + a = lua_newuserdata(L, sizeof(halfword)); + *a = n; + lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_node)); + lua_gettable(L, LUA_REGISTRYINDEX); + lua_setmetatable(L, -2); + } else { + lua_pushnil(L); + } return; } @@ -1402,8 +1402,6 @@ static int lua_nodelib_copy_list(lua_State * L) if ((lua_gettop(L) > 1) && (!lua_isnil(L,2))) s = *check_isnode(L, 2); m = do_copy_node_list(n, s); -// lua_pushnumber(L, m); -// lua_nodelib_push(L); lua_nodelib_push_fast(L,m); return 1; @@ -1722,8 +1720,7 @@ static int lua_nodelib_dimensions(lua_State * L) int i = 1; int d = -1; halfword n = null, p = null; - /* maybe be more restrictive: LUA_TNUMBER i.e. it's not good to mix numbers and strings with digits */ - if (lua_isnumber(L, 1)) { + if (lua_type(L, 1) == LUA_TNUMBER) { if (top < 4) { lua_pushnil(L); return 1; @@ -1805,7 +1802,7 @@ static int lua_nodelib_mlist_to_hlist(lua_State * L) boolean m; n = *(check_isnode(L, 1)); //w = luaL_checkoption(L, 2, "text", math_style_names); - assign_math_style(L,2,w); + assign_math_style(L,2,w); luaL_checkany(L, 3); m = lua_toboolean(L, 3); mlist_to_hlist_args(n, w, m); @@ -1950,24 +1947,20 @@ static int lua_nodelib_fields(lua_State * L) } lua_checkstack(L, 2); lua_newtable(L); - // lua_pushstring(L, "next"); lua_push_string_by_name(L,next); lua_rawseti(L, -2, 0); - // lua_pushstring(L, "id"); lua_push_string_by_name(L,id); lua_rawseti(L, -2, 1); if (nodetype_has_subtype(t)) { - // lua_pushstring(L, "subtype"); lua_push_string_by_name(L,subtype); lua_rawseti(L, -2, 2); offset++; } + if (nodetype_has_prev(t)) { + lua_push_string_by_name(L,prev); + lua_rawseti(L, -2, -1); + } if (fields != NULL) { - if (nodetype_has_prev(t)) { -// lua_pushstring(L, "prev"); - lua_push_string_by_name(L,prev); - lua_rawseti(L, -2, -1); - } for (i = 0; fields[i] != NULL; i++) { lua_pushstring(L, fields[i]); /* todo */ lua_rawseti(L, -2, (i + offset)); @@ -1976,6 +1969,79 @@ static int lua_nodelib_fields(lua_State * L) return 1; } +static int lua_nodelib_subtypes(lua_State * L) +{ + int i = -1; + int l = 0; + int t; + const char **subtypes = NULL; + const char *s ; + t = lua_type(L,1); + if (t == LUA_TSTRING) { + /* official accessors */ + s = lua_tostring(L,1); + if (lua_key_eq(s,glyph)) subtypes = node_subtypes_glyph; + else if (lua_key_eq(s,glue)) { subtypes = node_subtypes_glue; l = 1; } + else if (lua_key_eq(s,penalty)) subtypes = node_subtypes_penalty; + else if (lua_key_eq(s,kern)) subtypes = node_subtypes_kern; + else if (lua_key_eq(s,rule)) subtypes = node_subtypes_rule; + else if (lua_key_eq(s,list)) subtypes = node_subtypes_list; + else if (lua_key_eq(s,disc)) subtypes = node_subtypes_disc; + else if (lua_key_eq(s,fill)) subtypes = node_subtypes_fill; + else if (lua_key_eq(s,leader)) { subtypes = node_subtypes_leader; l = 2; } + else if (lua_key_eq(s,marginkern)) subtypes = node_subtypes_marginkern; + else if (lua_key_eq(s,math)) subtypes = node_subtypes_math; + else if (lua_key_eq(s,noad)) subtypes = node_subtypes_noad; + else if (lua_key_eq(s,radical)) subtypes = node_subtypes_radical; + else if (lua_key_eq(s,accent)) subtypes = node_subtypes_accent; + else if (lua_key_eq(s,fence)) subtypes = node_subtypes_fence; + /* backend */ + else if (lua_key_eq(s,pdf_destination)) subtypes = node_subtypes_pdf_destination; + else if (lua_key_eq(s,pdf_literal)) subtypes = node_subtypes_pdf_literal; + } else if (t == LUA_TNUMBER) { + /* maybe */ + t = lua_tonumber(L,1); + if (t == glyph_node) subtypes = node_subtypes_glyph; + else if (t == glue_node) { subtypes = node_subtypes_glue; l = 1; } + else if (t == penalty_node) subtypes = node_subtypes_penalty; + else if (t == kern_node) subtypes = node_subtypes_kern; + else if (t == rule_node) subtypes = node_subtypes_rule; + else if (t == hlist_node) subtypes = node_subtypes_list; + else if (t == vlist_node) subtypes = node_subtypes_list; + else if (t == disc_node) subtypes = node_subtypes_disc; + else if (t == glue_spec_node) subtypes = node_subtypes_fill; + else if (t == margin_kern_node) subtypes = node_subtypes_marginkern; + else if (t == math_node) subtypes = node_subtypes_math; + else if (t == simple_noad) subtypes = node_subtypes_noad; + else if (t == radical_noad) subtypes = node_subtypes_radical; + else if (t == accent_noad) subtypes = node_subtypes_accent; + else if (t == fence_noad) subtypes = node_subtypes_fence; + /* backend */ + else if (t == pdf_dest_node) subtypes = node_subtypes_pdf_destination; + else if (t == pdf_literal_node) subtypes = node_subtypes_pdf_literal; + } + if (subtypes != NULL) { + lua_checkstack(L, 2); + lua_newtable(L); + if (l < 2) { + for (i = 0; subtypes[i] != NULL; i++) { + lua_pushstring(L, subtypes[i]); /* todo */ + lua_rawseti(L, -2, i); + } + } + if (l > 0) { + /* add leaders */ + for (i = 0; node_subtypes_leader[i] != NULL; i++) { + lua_pushstring(L, node_subtypes_leader[i]); /* todo */ + lua_rawseti(L, -2, 100 + i); + } + } + } else { + lua_pushnil(L); + } + return 1; +} + /* node.slide (find the end of a list and add prev links) */ static int lua_nodelib_slide(lua_State * L) @@ -2469,20 +2535,9 @@ static int lua_nodelib_direct_count(lua_State * L) ); } -/* directions (could be a macro) */ - -// static void nodelib_pushdir(lua_State * L, int n, boolean dirnode) -// { -// if (dirnode) { -// lua_pushstring(L, dir_strings[n+64]); -// } else { -// lua_pushstring(L, dir_strings[n+64]+1); -// } -// } - /* getting and setting fields (helpers) */ -static int nodelib_getlist(lua_State * L, int n) +int nodelib_getlist(lua_State * L, int n) { halfword *m; if (lua_isuserdata(L, n)) { @@ -2515,13 +2570,18 @@ static str_number nodelib_getstring(lua_State * L, int a) return maketexlstring(s, k); } - static int nodelib_cantset(lua_State * L, int n, const char *s) { luaL_error(L,"You cannot set field %s in a node of type %s",s,node_data[type(n)].name); return 0; } +static int nodelib_nonwritable(lua_State * L, int n, const char *s) +{ + luaL_error(L,"You cannot set field %s in a non writable node of type %s",s,node_data[type(n)].name); + return 0; +} + /* node.direct.getfield */ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) @@ -2529,20 +2589,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) int t ; t = subtype(n); - if (t == dir_node) { - if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, dir_dir(n), true); - lua_push_dir_text(L, dir_dir(n)); - } else if (lua_key_eq(s, level)) { - lua_pushnumber(L, dir_level(n)); - } else if (lua_key_eq(s, dvi_ptr)) { - lua_pushnumber(L, dir_dvi_ptr(n)); - } else if (lua_key_eq(s, dir_h)) { - lua_pushnumber(L, dir_dvi_h(n)); - } else { - lua_pushnil(L); - } - } else if (t == user_defined_node) { + if (t == user_defined_node) { if (lua_key_eq(s, user_id)) { lua_pushnumber(L, user_node_id(n)); } else if (lua_key_eq(s, type)) { @@ -2578,27 +2625,6 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } else { lua_pushnil(L); } - } else if (t == local_par_node) { - if (lua_key_eq(s, pen_inter)) { - lua_pushnumber(L, local_pen_inter(n)); - } else if (lua_key_eq(s, pen_broken)) { - lua_pushnumber(L, local_pen_broken(n)); - } else if (lua_key_eq(s, dir)) { -// nodelib_pushdir(L, local_par_dir(n), false); - lua_push_dir_par(L, local_par_dir(n)); - } else if (lua_key_eq(s, box_left)) { - /* can be: fast_metatable_or_nil(local_box_left(n)) */ - nodelib_pushlist(L, local_box_left(n)); - } else if (lua_key_eq(s, box_left_width)) { - lua_pushnumber(L, local_box_left_width(n)); - } else if (lua_key_eq(s, box_right)) { - /* can be: fast_metatable_or_nil(local_box_right(n)) */ - nodelib_pushlist(L, local_box_right(n)); - } else if (lua_key_eq(s, box_right_width)) { - lua_pushnumber(L, local_box_right_width(n)); - } else { - lua_pushnil(L); - } } else if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { lua_pushnumber(L, pdf_literal_mode(n)); @@ -2682,32 +2708,6 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } else { lua_pushnil(L); } - } else if (t == pdf_refxform_node) { - if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); - } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); - } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); - } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_xform_objnum(n)); - } else { - lua_pushnil(L); - } - } else if (t == pdf_refximage_node) { - if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); - } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); - } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); - } else if (lua_key_eq(s, transform)) { - lua_pushnumber(L, pdf_ximage_transform(n)); - } else if (lua_key_eq(s, index)) { - lua_pushnumber(L, pdf_ximage_index(n)); - } else { - lua_pushnil(L); - } } else if (t == write_node) { if (lua_key_eq(s, stream)) { lua_pushnumber(L, write_stream(n)); @@ -2738,6 +2738,28 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } else { lua_pushnil(L); } + } else if (t == pdf_action_node) { + if (lua_key_eq(s, action_type)) { + lua_pushnumber(L, pdf_action_type(n)); + } else if (lua_key_eq(s, named_id)) { + lua_pushnumber(L, pdf_action_named_id(n)); + } else if (lua_key_eq(s, action_id)) { + if (pdf_action_named_id(n) == 1) { + tokenlist_to_luastring(L, pdf_action_id(n)); + } else { + lua_pushnumber(L, pdf_action_id(n)); + } + } else if (lua_key_eq(s, file)) { + tokenlist_to_luastring(L, pdf_action_file(n)); + } else if (lua_key_eq(s, new_window)) { + lua_pushnumber(L, pdf_action_new_window(n)); + } else if (lua_key_eq(s, data)) { + tokenlist_to_luastring(L, pdf_action_tokens(n)); + } else if (lua_key_eq(s, ref_count)) { + lua_pushnumber(L, pdf_action_refcount(n)); + } else { + lua_pushnil(L); + } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { lua_pushnumber(L, width(n)); @@ -2900,8 +2922,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, box_dir(n), false); - lua_push_dir_par(L, box_dir(n)); + lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shift)) { lua_pushnumber(L, shift_amount(n)); } else if (lua_key_eq(s, glue_order)) { @@ -2933,7 +2954,22 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if (lua_key_eq(s, leader)) { fast_metatable_or_nil(leader_ptr(n)); } else { - lua_pushnil(L); + n = glue_ptr(n); + if (!n) { + lua_pushnil(L); + } else if (lua_key_eq(s, width)) { + lua_pushnumber(L, width(n)); + } else if (lua_key_eq(s, stretch)) { + lua_pushnumber(L, stretch(n)); + } else if (lua_key_eq(s, shrink)) { + lua_pushnumber(L, shrink(n)); + } else if (lua_key_eq(s, stretch_order)) { + lua_pushnumber(L, stretch_order(n)); + } else if (lua_key_eq(s, shrink_order)) { + lua_pushnumber(L, shrink_order(n)); + } else { + lua_pushnil(L); + } } } else if (t == glue_spec_node) { if (lua_key_eq(s, subtype)) { @@ -2984,8 +3020,44 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, rule_dir(n), false); - lua_push_dir_par(L, rule_dir(n)); + lua_push_dir_par(L, rule_dir(n)); + } else if (lua_key_eq(s, index)) { + lua_pushnumber(L, rule_index(n)); + } else if (lua_key_eq(s, transform)) { + lua_pushnumber(L,rule_transform(n)); + } else { + lua_pushnil(L); + } + } else if (t == dir_node) { + if (lua_key_eq(s, dir)) { + // nodelib_pushdir(L, dir_dir(n), true); + lua_push_dir_text(L, dir_dir(n)); + } else if (lua_key_eq(s, level)) { + lua_pushnumber(L, dir_level(n)); + } else if (lua_key_eq(s, dvi_ptr)) { + lua_pushnumber(L, dir_dvi_ptr(n)); + } else if (lua_key_eq(s, dir_h)) { + lua_pushnumber(L, dir_dvi_h(n)); + } else { + lua_pushnil(L); + } + } else if (t == local_par_node) { + if (lua_key_eq(s, pen_inter)) { + lua_pushnumber(L, local_pen_inter(n)); + } else if (lua_key_eq(s, pen_broken)) { + lua_pushnumber(L, local_pen_broken(n)); + } else if (lua_key_eq(s, dir)) { + lua_push_dir_par(L, local_par_dir(n)); + } else if (lua_key_eq(s, box_left)) { + /* can be: fast_metatable_or_nil(local_box_left(n)) */ + nodelib_pushlist(L, local_box_left(n)); + } else if (lua_key_eq(s, box_left_width)) { + lua_pushnumber(L, local_box_left_width(n)); + } else if (lua_key_eq(s, box_right)) { + /* can be: fast_metatable_or_nil(local_box_right(n)) */ + nodelib_pushlist(L, local_box_right(n)); + } else if (lua_key_eq(s, box_right_width)) { + lua_pushnumber(L, local_box_right_width(n)); } else { lua_pushnil(L); } @@ -3085,10 +3157,12 @@ static int lua_nodelib_fast_getfield(lua_State * L) fast_metatable_or_nil(subscr(n)); } else if (lua_key_eq(s, sup)) { fast_metatable_or_nil(supscr(n)); - } else if (lua_key_eq(s, accent)) { - fast_metatable_or_nil(accent_chr(n)); + } else if ((lua_key_eq(s, top_accent))||(lua_key_eq(s, accent))) { + fast_metatable_or_nil(top_accent_chr(n)); } else if (lua_key_eq(s, bot_accent)) { fast_metatable_or_nil(bot_accent_chr(n)); + } else if (lua_key_eq(s, overlay_accent)) { + fast_metatable_or_nil(overlay_accent_chr(n)); } else { lua_pushnil(L); } @@ -3204,30 +3278,6 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else { lua_pushnil(L); } - } else if (t == action_node) { - if (lua_key_eq(s, subtype)) { - lua_pushnumber(L, subtype(n));/* dummy subtype */ - } else if (lua_key_eq(s, action_type)) { - lua_pushnumber(L, pdf_action_type(n)); - } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_action_named_id(n)); - } else if (lua_key_eq(s, action_id)) { - if (pdf_action_named_id(n) == 1) { - tokenlist_to_luastring(L, pdf_action_id(n)); - } else { - lua_pushnumber(L, pdf_action_id(n)); - } - } else if (lua_key_eq(s, file)) { - tokenlist_to_luastring(L, pdf_action_file(n)); - } else if (lua_key_eq(s, new_window)) { - lua_pushnumber(L, pdf_action_new_window(n)); - } else if (lua_key_eq(s, data)) { - tokenlist_to_luastring(L, pdf_action_tokens(n)); - } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, pdf_action_refcount(n)); - } else { - lua_pushnil(L); - } } else if (t == unset_node) { if (lua_key_eq(s, subtype)) { lua_pushnumber(L, subtype(n)); @@ -3238,8 +3288,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, box_dir(n), false); - lua_push_dir_par(L, box_dir(n)); + lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shrink)) { lua_pushnumber(L, glue_shrink(n)); } else if (lua_key_eq(s, glue_order)) { @@ -3261,6 +3310,14 @@ static int lua_nodelib_fast_getfield(lua_State * L) } else { lua_pushnil(L); } + } else if (t == boundary_node) { + if (lua_key_eq(s, subtype)) { + lua_pushnumber(L, subtype(n)); + } else if (lua_key_eq(s, value)) { + lua_pushnumber(L, boundary_value(n)); + } else { + lua_pushnil(L); + } } else { lua_pushnil(L); } @@ -3295,20 +3352,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char int t ; t = subtype(n); - if (t == dir_node) { - if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, dir_dir(n), true); - lua_push_dir_text(L, dir_dir(n)); - } else if (lua_key_eq(s, level)) { - lua_pushnumber(L, dir_level(n)); - } else if (lua_key_eq(s, dvi_ptr)) { - lua_pushnumber(L, dir_dvi_ptr(n)); - } else if (lua_key_eq(s, dir_h)) { - lua_pushnumber(L, dir_dvi_h(n)); - } else { - lua_pushnil(L); - } - } else if (t == user_defined_node) { + if (t == user_defined_node) { if (lua_key_eq(s, user_id)) { lua_pushnumber(L, user_node_id(n)); } else if (lua_key_eq(s, type)) { @@ -3344,25 +3388,6 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } else { lua_pushnil(L); } - } else if (t == local_par_node) { - if (lua_key_eq(s, pen_inter)) { - lua_pushnumber(L, local_pen_inter(n)); - } else if (lua_key_eq(s, pen_broken)) { - lua_pushnumber(L, local_pen_broken(n)); - } else if (lua_key_eq(s, dir)) { -// nodelib_pushdir(L, local_par_dir(n), false); - lua_push_dir_par(L, local_par_dir(n)); - } else if (lua_key_eq(s, box_left)) { - nodelib_pushdirect_or_nil(local_box_left(n)); - } else if (lua_key_eq(s, box_left_width)) { - lua_pushnumber(L, local_box_left_width(n)); - } else if (lua_key_eq(s, box_right)) { - nodelib_pushdirect_or_nil(local_box_right(n)); - } else if (lua_key_eq(s, box_right_width)) { - lua_pushnumber(L, local_box_right_width(n)); - } else { - lua_pushnil(L); - } } else if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { lua_pushnumber(L, pdf_literal_mode(n)); @@ -3446,32 +3471,6 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } else { lua_pushnil(L); } - } else if (t == pdf_refxform_node) { - if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); - } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); - } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); - } else if (lua_key_eq(s, objnum)) { - lua_pushnumber(L, pdf_xform_objnum(n)); - } else { - lua_pushnil(L); - } - } else if (t == pdf_refximage_node) { - if (lua_key_eq(s, width)) { - lua_pushnumber(L, width(n)); - } else if (lua_key_eq(s, depth)) { - lua_pushnumber(L, depth(n)); - } else if (lua_key_eq(s, height)) { - lua_pushnumber(L, height(n)); - } else if (lua_key_eq(s, transform)) { - lua_pushnumber(L, pdf_ximage_transform(n)); - } else if (lua_key_eq(s, index)) { - lua_pushnumber(L, pdf_ximage_index(n)); - } else { - lua_pushnil(L); - } } else if (t == write_node) { if (lua_key_eq(s, stream)) { lua_pushnumber(L, write_stream(n)); @@ -3502,6 +3501,28 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } else { lua_pushnil(L); } + } else if (t == pdf_action_node) { + if (lua_key_eq(s, action_type)) { + lua_pushnumber(L, pdf_action_type(n)); + } else if (lua_key_eq(s, named_id)) { + lua_pushnumber(L, pdf_action_named_id(n)); + } else if (lua_key_eq(s, action_id)) { + if (pdf_action_named_id(n) == 1) { + tokenlist_to_luastring(L, pdf_action_id(n)); + } else { + lua_pushnumber(L, pdf_action_id(n)); + } + } else if (lua_key_eq(s, file)) { + tokenlist_to_luastring(L, pdf_action_file(n)); + } else if (lua_key_eq(s, new_window)) { + lua_pushnumber(L, pdf_action_new_window(n)); + } else if (lua_key_eq(s, data)) { + tokenlist_to_luastring(L, pdf_action_tokens(n)); + } else if (lua_key_eq(s, ref_count)) { + lua_pushnumber(L, pdf_action_refcount(n)); + } else { + lua_pushnil(L); + } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { lua_pushnumber(L, width(n)); @@ -3652,8 +3673,7 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, box_dir(n), false); - lua_push_dir_par(L, box_dir(n)); + lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shift)) { lua_pushnumber(L, shift_amount(n)); } else if (lua_key_eq(s, glue_order)) { @@ -3681,7 +3701,22 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else if (lua_key_eq(s, leader)) { nodelib_pushdirect_or_nil(leader_ptr(n)); } else { - lua_pushnil(L); + n = glue_ptr(n); + if (!n) { + lua_pushnil(L); + } else if (lua_key_eq(s, width)) { + lua_pushnumber(L, width(n)); + } else if (lua_key_eq(s, stretch)) { + lua_pushnumber(L, stretch(n)); + } else if (lua_key_eq(s, shrink)) { + lua_pushnumber(L, shrink(n)); + } else if (lua_key_eq(s, stretch_order)) { + lua_pushnumber(L, stretch_order(n)); + } else if (lua_key_eq(s, shrink_order)) { + lua_pushnumber(L, shrink_order(n)); + } else { + lua_pushnil(L); + } } } else if (t == glue_spec_node) { if (lua_key_eq(s, width)) { @@ -3724,8 +3759,42 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, rule_dir(n), false); - lua_push_dir_par(L, rule_dir(n)); + lua_push_dir_par(L, rule_dir(n)); + } else if (lua_key_eq(s, index)) { + lua_pushnumber(L, rule_index(n)); + } else if (lua_key_eq(s, transform)) { + lua_pushnumber(L,rule_transform(n)); + } else { + lua_pushnil(L); + } + } else if (t == dir_node) { + if (lua_key_eq(s, dir)) { + // nodelib_pushdir(L, dir_dir(n), true); + lua_push_dir_text(L, dir_dir(n)); + } else if (lua_key_eq(s, level)) { + lua_pushnumber(L, dir_level(n)); + } else if (lua_key_eq(s, dvi_ptr)) { + lua_pushnumber(L, dir_dvi_ptr(n)); + } else if (lua_key_eq(s, dir_h)) { + lua_pushnumber(L, dir_dvi_h(n)); + } else { + lua_pushnil(L); + } + } else if (t == local_par_node) { + if (lua_key_eq(s, pen_inter)) { + lua_pushnumber(L, local_pen_inter(n)); + } else if (lua_key_eq(s, pen_broken)) { + lua_pushnumber(L, local_pen_broken(n)); + } else if (lua_key_eq(s, dir)) { + lua_push_dir_par(L, local_par_dir(n)); + } else if (lua_key_eq(s, box_left)) { + nodelib_pushdirect_or_nil(local_box_left(n)); + } else if (lua_key_eq(s, box_left_width)) { + lua_pushnumber(L, local_box_left_width(n)); + } else if (lua_key_eq(s, box_right)) { + nodelib_pushdirect_or_nil(local_box_right(n)); + } else if (lua_key_eq(s, box_right_width)) { + lua_pushnumber(L, local_box_right_width(n)); } else { lua_pushnil(L); } @@ -3804,10 +3873,12 @@ static int lua_nodelib_direct_getfield(lua_State * L) nodelib_pushdirect_or_nil(subscr(n)); } else if (lua_key_eq(s, sup)) { nodelib_pushdirect_or_nil(supscr(n)); - } else if (lua_key_eq(s, accent)) { - nodelib_pushdirect_or_nil(accent_chr(n)); + } else if ((lua_key_eq(s, top_accent))||(lua_key_eq(s, accent))) { + nodelib_pushdirect_or_nil(top_accent_chr(n)); } else if (lua_key_eq(s, bot_accent)) { nodelib_pushdirect_or_nil(bot_accent_chr(n)); + } else if (lua_key_eq(s, overlay_accent)) { + nodelib_pushdirect_or_nil(overlay_accent_chr(n)); } else { lua_pushnil(L); } @@ -3903,28 +3974,6 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else { lua_pushnil(L); } - } else if (t == action_node) { - if (lua_key_eq(s, action_type)) { - lua_pushnumber(L, pdf_action_type(n)); - } else if (lua_key_eq(s, named_id)) { - lua_pushnumber(L, pdf_action_named_id(n)); - } else if (lua_key_eq(s, action_id)) { - if (pdf_action_named_id(n) == 1) { - tokenlist_to_luastring(L, pdf_action_id(n)); - } else { - lua_pushnumber(L, pdf_action_id(n)); - } - } else if (lua_key_eq(s, file)) { - tokenlist_to_luastring(L, pdf_action_file(n)); - } else if (lua_key_eq(s, new_window)) { - lua_pushnumber(L, pdf_action_new_window(n)); - } else if (lua_key_eq(s, data)) { - tokenlist_to_luastring(L, pdf_action_tokens(n)); - } else if (lua_key_eq(s, ref_count)) { - lua_pushnumber(L, pdf_action_refcount(n)); - } else { - lua_pushnil(L); - } } else if (t == unset_node) { if (lua_key_eq(s, width)) { lua_pushnumber(L, width(n)); @@ -3933,8 +3982,7 @@ static int lua_nodelib_direct_getfield(lua_State * L) } else if (lua_key_eq(s, depth)) { lua_pushnumber(L, depth(n)); } else if (lua_key_eq(s, dir)) { - // nodelib_pushdir(L, box_dir(n), false); - lua_push_dir_par(L, box_dir(n)); + lua_push_dir_par(L, box_dir(n)); } else if (lua_key_eq(s, shrink)) { lua_pushnumber(L, glue_shrink(n)); } else if (lua_key_eq(s, glue_order)) { @@ -3952,6 +4000,14 @@ static int lua_nodelib_direct_getfield(lua_State * L) } /* } else if (t == attribute_list_node) { */ /* lua_pushnil(L); */ + } else if (t == boundary_node) { + if (lua_key_eq(s, subtype)) { + lua_pushnumber(L, subtype(n)); + } else if (lua_key_eq(s, value)) { + lua_pushnumber(L, boundary_value(n)); + } else { + lua_pushnil(L); + } } else { lua_pushnil(L); } @@ -4091,7 +4147,6 @@ static int font_tex_kerning(lua_State * L) return 3; } - /* node.protect_glyphs (returns also boolean because that signals callback) */ static int lua_nodelib_protect_glyphs(lua_State * L) @@ -4243,9 +4298,6 @@ static int lua_nodelib_direct_first_glyph(lua_State * L) /* return null; \ */ /* } while (0) */ - - - /* node.has_glyph */ static int lua_nodelib_has_glyph(lua_State * L) @@ -4489,19 +4541,7 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) int t ; t = subtype(n); - if (t == dir_node) { - if (lua_key_eq(s, dir)) { - dir_dir(n) = nodelib_getdir(L, 3, 0); - } else if (lua_key_eq(s, level)) { - dir_level(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dvi_ptr)) { - dir_dvi_ptr(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dir_h)) { - dir_dvi_h(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == pdf_literal_node) { + if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { pdf_literal_mode(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, data)) { @@ -4623,50 +4663,6 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) } else { return nodelib_cantset(L, n, s); } - } else if (t == pdf_refxform_node) { - if (lua_key_eq(s, width)) { - width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, depth)) { - depth(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, height)) { - height(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, objnum)) { - pdf_xform_objnum(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == pdf_refximage_node) { - if (lua_key_eq(s, width)) { - width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, depth)) { - depth(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, height)) { - height(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, transform)) { - pdf_ximage_transform(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, index)) { - pdf_ximage_index(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == local_par_node) { - if (lua_key_eq(s, pen_inter)) { - local_pen_inter(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, pen_broken)) { - local_pen_broken(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dir)) { - local_par_dir(n) = nodelib_getdir(L, 3, 1); - } else if (lua_key_eq(s, box_left)) { - local_box_left(n) = nodelib_getlist(L, 3); - } else if (lua_key_eq(s, box_left_width)) { - local_box_left_width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, box_right)) { - local_box_right(n) = nodelib_getlist(L, 3); - } else if (lua_key_eq(s, box_right_width)) { - local_box_right_width(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } } else if (t == pdf_start_link_node) { if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -4701,6 +4697,28 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) } else { return nodelib_cantset(L, n, s); } + } else if (t == pdf_action_node) { + if (lua_key_eq(s, action_type)) { + pdf_action_type(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, named_id)) { + pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, action_id)) { + if (pdf_action_named_id(n) == 1) { + pdf_action_id(n) = nodelib_gettoks(L, 3); + } else { + pdf_action_id(n) = (halfword) lua_tointeger(L, 3); + } + } else if (lua_key_eq(s, file)) { + pdf_action_file(n) = nodelib_gettoks(L, 3); + } else if (lua_key_eq(s, new_window)) { + pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, data)) { + pdf_action_tokens(n) = nodelib_gettoks(L, 3); + /* } else if (lua_key_eq(s, ref_count)) { + pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3); */ + } else { + return nodelib_cantset(L, n, s); + } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -4746,7 +4764,7 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) return nodelib_cantset(L, n, s); } } else if ((t == pdf_end_link_node) || (t == pdf_end_thread_node) || (t == save_pos_node) || - (t == pdf_save_node) || (t == pdf_restore_node) || (t == cancel_boundary_node)) { + (t == pdf_save_node) || (t == pdf_restore_node)) { return nodelib_cantset(L, n, s); } else { /* do nothing */ @@ -4877,11 +4895,28 @@ static int lua_nodelib_fast_setfield(lua_State * L) glue_ptr(n) = nodelib_getspec(L, 3); } else if (lua_key_eq(s, leader)) { leader_ptr(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, width)) { + nodelib_check_glue_spec(n); + width(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, stretch)) { + nodelib_check_glue_spec(n); + stretch(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, shrink)) { + nodelib_check_glue_spec(n); + shrink(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, stretch_order)) { + nodelib_check_glue_spec(n); + stretch_order(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, shrink_order)) { + nodelib_check_glue_spec(n); + shrink_order(n) = (quarterword) lua_tointeger(L, 3); } else { return nodelib_cantset(L, n, s); } } else if (t == glue_spec_node) { - if (lua_key_eq(s, subtype)) { + if (!valid_node(n)) { + return nodelib_nonwritable(L, n, s); + } else if (lua_key_eq(s, subtype)) { subtype(n) = (quarterword) lua_tointeger(L, 3); /* dummy, the only one that prevents move up */ } else if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -4892,12 +4927,7 @@ static int lua_nodelib_fast_setfield(lua_State * L) } else if (lua_key_eq(s, stretch_order)) { stretch_order(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, shrink_order)) { - shrink_order(n) = (quarterword) lua_tointeger(L, 3); - /* } else if (lua_key_eq(s, ref_count)) { - glue_ref_count(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, writable)) { - */ - /* can't be set */ + shrink_order(n) = (quarterword) lua_tointeger(L, 3); } else { return nodelib_cantset(L, n, s); } @@ -4930,6 +4960,40 @@ static int lua_nodelib_fast_setfield(lua_State * L) depth(n) = (halfword) lua_tointeger(L, 3); } else if (lua_key_eq(s, dir)) { rule_dir(n) = nodelib_getdir(L, 3, 1); + } else if (lua_key_eq(s, index)) { + rule_index(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, transform)) { + rule_transform(n) = (halfword) lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } + } else if (t == dir_node) { + if (lua_key_eq(s, dir)) { + dir_dir(n) = nodelib_getdir(L, 3, 0); + } else if (lua_key_eq(s, level)) { + dir_level(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dvi_ptr)) { + dir_dvi_ptr(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dir_h)) { + dir_dvi_h(n) = (halfword) lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } + } else if (t == local_par_node) { + if (lua_key_eq(s, pen_inter)) { + local_pen_inter(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, pen_broken)) { + local_pen_broken(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dir)) { + local_par_dir(n) = nodelib_getdir(L, 3, 1); + } else if (lua_key_eq(s, box_left)) { + local_box_left(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, box_left_width)) { + local_box_left_width(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, box_right)) { + local_box_right(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, box_right_width)) { + local_box_right_width(n) = (halfword) lua_tointeger(L, 3); } else { return nodelib_cantset(L, n, s); } @@ -5015,7 +5079,7 @@ static int lua_nodelib_fast_setfield(lua_State * L) if (lua_key_eq(s, subtype)) { /* dummy subtype */ } else if (lua_key_eq(s, style)) { - assign_math_style(L,3,subtype(n)); + assign_math_style(L,3,subtype(n)); //subtype(n) = (quarterword) luaL_checkoption(L, 3, "text", math_style_names); /* not 2? */ } else { /* return nodelib_cantset(L, n, s); */ @@ -5029,10 +5093,12 @@ static int lua_nodelib_fast_setfield(lua_State * L) subscr(n) = nodelib_getlist(L, 3); } else if (lua_key_eq(s, sup)) { supscr(n) = nodelib_getlist(L, 3); - } else if (lua_key_eq(s, accent)) { - accent_chr(n) = nodelib_getlist(L, 3); + } else if ((lua_key_eq(s, top_accent))||(lua_key_eq(s, accent))) { + top_accent_chr(n) = nodelib_getlist(L, 3); } else if (lua_key_eq(s, bot_accent)) { bot_accent_chr(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, overlay_accent)) { + overlay_accent_chr(n) = nodelib_getlist(L, 3); } else { return nodelib_cantset(L, n, s); } @@ -5148,30 +5214,6 @@ static int lua_nodelib_fast_setfield(lua_State * L) } else { return nodelib_cantset(L, n, s); } - } else if (t == action_node) { - if (lua_key_eq(s, subtype)) { - /* dummy subtype */ - } else if (lua_key_eq(s, action_type)) { - pdf_action_type(n) = (quarterword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, named_id)) { - pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, action_id)) { - if (pdf_action_named_id(n) == 1) { - pdf_action_id(n) = nodelib_gettoks(L, 3); - } else { - pdf_action_id(n) = (halfword) lua_tointeger(L, 3); - } - } else if (lua_key_eq(s, file)) { - pdf_action_file(n) = nodelib_gettoks(L, 3); - } else if (lua_key_eq(s, new_window)) { - pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, data)) { - pdf_action_tokens(n) = nodelib_gettoks(L, 3); - /* } else if (lua_key_eq(s, ref_count)) { - pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3); */ - } else { - return nodelib_cantset(L, n, s); - } } else if (t == unset_node) { if (lua_key_eq(s, subtype)) { /* dummy subtype */ @@ -5204,6 +5246,14 @@ static int lua_nodelib_fast_setfield(lua_State * L) } else { return nodelib_cantset(L, n, s); } + } else if (t == boundary_node) { + if (lua_key_eq(s, subtype)) { + subtype(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, value)) { + boundary_value(n) = lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } } else { return luaL_error(L, "You can't assign to this %s node (%d)\n", node_data[t].name, n); } @@ -5236,19 +5286,7 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char int t ; t = subtype(n); - if (t == dir_node) { - if (lua_key_eq(s, dir)) { - dir_dir(n) = nodelib_getdir(L, 3, 0); - } else if (lua_key_eq(s, level)) { - dir_level(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dvi_ptr)) { - dir_dvi_ptr(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dir_h)) { - dir_dvi_h(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == pdf_literal_node) { + if (t == pdf_literal_node) { if (lua_key_eq(s, mode)) { pdf_literal_mode(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, data)) { @@ -5369,50 +5407,6 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char } else { return nodelib_cantset(L, n, s); } - } else if (t == pdf_refxform_node) { - if (lua_key_eq(s, width)) { - width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, depth)) { - depth(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, height)) { - height(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, objnum)) { - pdf_xform_objnum(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == pdf_refximage_node) { - if (lua_key_eq(s, width)) { - width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, depth)) { - depth(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, height)) { - height(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, transform)) { - pdf_ximage_transform(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, index)) { - pdf_ximage_index(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } - } else if (t == local_par_node) { - if (lua_key_eq(s, pen_inter)) { - local_pen_inter(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, pen_broken)) { - local_pen_broken(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, dir)) { - local_par_dir(n) = nodelib_getdir(L, 3, 1); - } else if (lua_key_eq(s, box_left)) { - local_box_left(n) = nodelib_getlist(L, 3); - } else if (lua_key_eq(s, box_left_width)) { - local_box_left_width(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, box_right)) { - local_box_right(n) = nodelib_getlist(L, 3); - } else if (lua_key_eq(s, box_right_width)) { - local_box_right_width(n) = (halfword) lua_tointeger(L, 3); - } else { - return nodelib_cantset(L, n, s); - } } else if (t == pdf_start_link_node) { if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -5447,6 +5441,28 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char } else { return nodelib_cantset(L, n, s); } + } else if (t == pdf_action_node) { + if (lua_key_eq(s, action_type)) { + pdf_action_type(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, named_id)) { + pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, action_id)) { + if (pdf_action_named_id(n) == 1) { + pdf_action_id(n) = nodelib_gettoks(L, 3); + } else { + pdf_action_id(n) = (halfword) lua_tointeger(L, 3); + } + } else if (lua_key_eq(s, file)) { + pdf_action_file(n) = nodelib_gettoks(L, 3); + } else if (lua_key_eq(s, new_window)) { + pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, data)) { + pdf_action_tokens(n) = nodelib_gettoks(L, 3); + /* } else if (lua_key_eq(s, ref_count)) { + pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3); */ + } else { + return nodelib_cantset(L, n, s); + } } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) { if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -5492,7 +5508,7 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char return nodelib_cantset(L, n, s); } } else if ((t == pdf_end_link_node) || (t == pdf_end_thread_node) || (t == save_pos_node) || - (t == pdf_save_node) || (t == pdf_restore_node) || (t == cancel_boundary_node)) { + (t == pdf_save_node) || (t == pdf_restore_node)) { return nodelib_cantset(L, n, s); } else { /* do nothing */ @@ -5661,7 +5677,7 @@ static int lua_nodelib_direct_setfield(lua_State * L) /*if (lua_key_eq(s, id)) { type(n) = (quarteword) lua_tointeger(L, 3); - } else*/ + } else*/ if (lua_key_eq(s, next)) { halfword x = nodelib_popdirect(3); if (x>0 && type(x) == glue_spec_node) { @@ -5753,11 +5769,28 @@ static int lua_nodelib_direct_setfield(lua_State * L) glue_ptr(n) = nodelib_popdirect(3); } else if (lua_key_eq(s, leader)) { leader_ptr(n) = nodelib_popdirect(3); + } else if (lua_key_eq(s, width)) { + nodelib_check_glue_spec(n); + width(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, stretch)) { + nodelib_check_glue_spec(n); + stretch(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, shrink)) { + nodelib_check_glue_spec(n); + shrink(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, stretch_order)) { + nodelib_check_glue_spec(n); + stretch_order(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, shrink_order)) { + nodelib_check_glue_spec(n); + shrink_order(n) = (quarterword) lua_tointeger(L, 3); } else { return nodelib_cantset(L, n, s); } } else if (t == glue_spec_node) { - if (lua_key_eq(s, subtype)) { + if (!valid_node(n)) { + return nodelib_nonwritable(L, n, s); + } else if (lua_key_eq(s, subtype)) { subtype(n) = (quarterword) lua_tointeger(L, 3); /* dummy, the only one that prevents move up */ } else if (lua_key_eq(s, width)) { width(n) = (halfword) lua_tointeger(L, 3); @@ -5769,10 +5802,6 @@ static int lua_nodelib_direct_setfield(lua_State * L) stretch_order(n) = (quarterword) lua_tointeger(L, 3); } else if (lua_key_eq(s, shrink_order)) { shrink_order(n) = (quarterword) lua_tointeger(L, 3); - /* } else if (lua_key_eq(s, ref_count)) { - glue_ref_count(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, writable)) { - */ } else { return nodelib_cantset(L, n, s); } @@ -5805,15 +5834,49 @@ static int lua_nodelib_direct_setfield(lua_State * L) depth(n) = (halfword) lua_tointeger(L, 3); } else if (lua_key_eq(s, dir)) { rule_dir(n) = nodelib_getdir(L, 3, 1); + } else if (lua_key_eq(s, index)) { + rule_index(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, transform)) { + rule_transform(n) = (halfword) lua_tointeger(L, 3); } else { return nodelib_cantset(L, n, s); } - } else if (t == whatsit_node) { + } else if (t == dir_node) { + if (lua_key_eq(s, dir)) { + dir_dir(n) = nodelib_getdir(L, 3, 0); + } else if (lua_key_eq(s, level)) { + dir_level(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dvi_ptr)) { + dir_dvi_ptr(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dir_h)) { + dir_dvi_h(n) = (halfword) lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } + } else if (t == whatsit_node) { if (lua_key_eq(s, subtype)) { subtype(n) = (quarterword) lua_tointeger(L, 3); } else { lua_nodelib_direct_setfield_whatsit(L, n, s); } + } else if (t == local_par_node) { + if (lua_key_eq(s, pen_inter)) { + local_pen_inter(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, pen_broken)) { + local_pen_broken(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, dir)) { + local_par_dir(n) = nodelib_getdir(L, 3, 1); + } else if (lua_key_eq(s, box_left)) { + local_box_left(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, box_left_width)) { + local_box_left_width(n) = (halfword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, box_right)) { + local_box_right(n) = nodelib_getlist(L, 3); + } else if (lua_key_eq(s, box_right_width)) { + local_box_right_width(n) = (halfword) lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } } else if (t == simple_noad) { if (lua_key_eq(s, subtype)) { subtype(n) = (quarterword) lua_tointeger(L, 3); @@ -5890,7 +5953,7 @@ static int lua_nodelib_direct_setfield(lua_State * L) if (lua_key_eq(s, subtype)) { /* dummy subtype */ } else if (lua_key_eq(s, style)) { - assign_math_style(L,2,subtype(n)); + assign_math_style(L,2,subtype(n)); //subtype(n) = (quarterword) luaL_checkoption(L, 2, "text", math_style_names); /* was 3 */ } else { /* return nodelib_cantset(L, n, s); */ @@ -5904,10 +5967,12 @@ static int lua_nodelib_direct_setfield(lua_State * L) subscr(n) = nodelib_popdirect(3); } else if (lua_key_eq(s, sup)) { supscr(n) = nodelib_popdirect(3); - } else if (lua_key_eq(s, accent)) { - accent_chr(n) = nodelib_popdirect(3); + } else if ((lua_key_eq(s, top_accent))||(lua_key_eq(s, accent))) { + top_accent_chr(n) = nodelib_popdirect(3); } else if (lua_key_eq(s, bot_accent)) { bot_accent_chr(n) = nodelib_popdirect(3); + } else if (lua_key_eq(s, overlay_accent)) { + overlay_accent_chr(n) = nodelib_popdirect(3); } else { return nodelib_cantset(L, n, s); } @@ -6023,30 +6088,6 @@ static int lua_nodelib_direct_setfield(lua_State * L) } else { return nodelib_cantset(L, n, s); } - } else if (t == action_node) { - if (lua_key_eq(s, subtype)) { - /* dummy subtype */ - } else if (lua_key_eq(s, action_type)) { - pdf_action_type(n) = (quarterword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, named_id)) { - pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, action_id)) { - if (pdf_action_named_id(n) == 1) { - pdf_action_id(n) = nodelib_gettoks(L, 3); - } else { - pdf_action_id(n) = (halfword) lua_tointeger(L, 3); - } - } else if (lua_key_eq(s, file)) { - pdf_action_file(n) = nodelib_gettoks(L, 3); - } else if (lua_key_eq(s, new_window)) { - pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3); - } else if (lua_key_eq(s, data)) { - pdf_action_tokens(n) = nodelib_gettoks(L, 3); - /* } else if (lua_key_eq(s, ref_count)) { - pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3); */ - } else { - return nodelib_cantset(L, n, s); - } } else if (t == unset_node) { if (lua_key_eq(s, subtype)) { /* dummy subtype */ @@ -6079,6 +6120,14 @@ static int lua_nodelib_direct_setfield(lua_State * L) } else { return nodelib_cantset(L, n, s); } + } else if (t == boundary_node) { + if (lua_key_eq(s, subtype)) { + subtype(n) = (quarterword) lua_tointeger(L, 3); + } else if (lua_key_eq(s, value)) { + boundary_value(n) = lua_tointeger(L, 3); + } else { + return nodelib_cantset(L, n, s); + } } else { return luaL_error(L, "You can't assign to this %s node (%d)\n", node_data[t].name, n); } @@ -6164,7 +6213,7 @@ static int lua_nodelib_direct_setbox(lua_State * L) { int isglobal = 0; int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { + if (n == 3 && (lua_type(L, 1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); if (lua_key_eq(s, global)) isglobal = 1; @@ -6245,7 +6294,7 @@ static int lua_nodelib_attributes_to_table(lua_State * L) // hh { // <node|direct> halfword n; register halfword attribute; - if (lua_isnumber(L,1)) { + if (lua_type(L,1) == LUA_TNUMBER) { n = lua_tonumber(L,1); } else { n = *((halfword *) lua_touserdata(L, 1)); @@ -6279,7 +6328,7 @@ static int lua_nodelib_attributes_to_properties(lua_State * L) { // <node|direct> halfword n; register halfword attribute; - if (lua_isnumber(L,1)) { + if (lua_type(L,1) == LUA_TNUMBER) { n = lua_tonumber(L,1); } else { n = *((halfword *) lua_touserdata(L, 1)); @@ -6454,7 +6503,7 @@ static int lua_nodelib_set_property_t(lua_State * L) /* hh */ /* extra helpers */ -static int lua_nodelib_effective_glue(lua_State * L) +static int lua_nodelib_effective_glue(lua_State * L) { halfword *glue; halfword *parent; @@ -6484,7 +6533,7 @@ static int lua_nodelib_effective_glue(lua_State * L) } -static int lua_nodelib_direct_effective_glue(lua_State * L) +static int lua_nodelib_direct_effective_glue(lua_State * L) { halfword glue; halfword parent; @@ -6636,6 +6685,7 @@ static const struct luaL_Reg nodelib_f[] = { {"end_of_math", lua_nodelib_end_of_math}, {"family_font", lua_nodelib_mfont}, {"fields", lua_nodelib_fields}, + {"subtypes", lua_nodelib_subtypes}, {"first_character", lua_nodelib_first_character}, {"first_glyph", lua_nodelib_first_glyph}, {"flush_list", lua_nodelib_flush_list}, diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index 71580145ba7..b1dca1b5c1e 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -20,6 +20,7 @@ #include "ptexlib.h" #include "lua/luatex-api.h" +#include "pdf/pdftables.h" static int luapdfprint(lua_State * L) { @@ -29,52 +30,49 @@ static int luapdfprint(lua_State * L) ctm_transform_modes literal_mode; st.s = modestr_s = NULL; n = lua_gettop(L); - if (!lua_isstring(L, -1)) { + if (!lua_isstring(L, -1)) { /* or number */ luaL_error(L, "no string to print"); } literal_mode = set_origin; if (n == 2) { - if (!lua_isstring(L, -2)) { - luaL_error(L, "invalid argument for print literal mode"); + if (lua_type(L,-2) != LUA_TSTRING) { + luaL_error(L, "invalid first argument for print literal mode"); } else { - modestr_s = lua_tostring(L, -2); - if (lua_key_eq(modestr_s,direct)) - literal_mode = direct_always; - else if (lua_key_eq(modestr_s,page)) + modestr_s = lua_tostring(L, -2); + if (lua_key_eq(modestr_s,direct)) + literal_mode = direct_always; + else if (lua_key_eq(modestr_s,page)) literal_mode = direct_page; else { - luaL_error(L, "invalid argument for print literal mode"); + luaL_error(L, "invalid first argument for print literal mode"); } } - } else { - if (n != 1) { - luaL_error(L, "invalid number of arguments"); - } + } else if (n != 1) { + luaL_error(L, "invalid number of arguments"); } check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); switch (literal_mode) { - case (set_origin): - pdf_goto_pagemode(static_pdf); - pdf_set_pos(static_pdf, static_pdf->posstruct->pos); - (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); - break; - case (direct_page): - pdf_goto_pagemode(static_pdf); - (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); - break; - case (direct_always): - pdf_end_string_nl(static_pdf); - break; - default: - assert(0); + case (set_origin): + pdf_goto_pagemode(static_pdf); + pdf_set_pos(static_pdf, static_pdf->posstruct->pos); + (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); + break; + case (direct_page): + pdf_goto_pagemode(static_pdf); + (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); + break; + case (direct_always): + pdf_end_string_nl(static_pdf); + break; + default: + assert(0); } st.s = lua_tolstring(L, n, &st.l); pdf_out_block(static_pdf, st.s, st.l); return 0; } -static unsigned char *fread_to_buf(lua_State * L, const char *filename, - size_t * len) +static unsigned char *fread_to_buf(lua_State * L, const char *filename, size_t * len) { int ilen = 0; FILE *f; @@ -100,7 +98,7 @@ static int l_immediateobj(lua_State * L) if (global_shipping_mode != NOT_SHIPPING) luaL_error(L, "pdf.immediateobj() can not be used with \\latelua"); n = lua_gettop(L); - if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) { + if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { first_arg++; k=(int)lua_tonumber(L, 1); check_obj_type(static_pdf, obj_type_obj, k); @@ -112,69 +110,61 @@ static int l_immediateobj(lua_State * L) } pdf_last_obj = k; switch (n - first_arg + 1) { - case 0: - luaL_error(L, "pdf.immediateobj() needs at least one argument"); - break; - case 1: - if (!lua_isstring(L, first_arg)) - luaL_error(L, "pdf.immediateobj() 1st argument must be string"); - pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); - st1.s = lua_tolstring(L, first_arg, &st1.l); - pdf_out_block(static_pdf, st1.s, st1.l); - /* already in pdf_end_obj: - if (st1.s[st1.l - 1] != '\n') - pdf_out(static_pdf, '\n'); - */ - pdf_end_obj(static_pdf); - break; - case 2: - case 3: - if (!lua_isstring(L, first_arg)) - luaL_error(L, "pdf.immediateobj() 1st argument must be string"); - if (!lua_isstring(L, first_arg + 1)) - luaL_error(L, "pdf.immediateobj() 2nd argument must be string"); - st1_s = lua_tostring(L, first_arg); - st2.s = lua_tolstring(L, first_arg + 1, &st2.l); - if (lua_key_eq(st1_s, file)) { - if (n == first_arg + 2) - luaL_error(L, "pdf.immediateobj() 3rd argument forbidden in file mode"); + case 0: + luaL_error(L, "pdf.immediateobj() needs at least one argument"); + break; + case 1: + if (!lua_isstring(L, first_arg)) /* or number */ + luaL_error(L, "pdf.immediateobj() 1st argument must be string"); pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); - buf.s = fread_to_buf(L, st2.s, &buf.l); - pdf_out_block(static_pdf, (const char *) buf.s, buf.l); - /* already in pdf_end_obj: - if (buf.s[buf.l - 1] != '\n') - pdf_out(static_pdf, '\n'); - */ - xfree(buf.s); + st1.s = lua_tolstring(L, first_arg, &st1.l); + pdf_out_block(static_pdf, st1.s, st1.l); pdf_end_obj(static_pdf); - } else { - pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* not an object stream candidate! */ - pdf_begin_dict(static_pdf); - if (n == first_arg + 2) { /* write attr text */ - if (!lua_isstring(L, first_arg + 2)) - luaL_error(L, "pdf.immediateobj() 3rd argument must be string"); - st3.s = lua_tolstring(L, first_arg + 2, &st3.l); - pdf_out_block(static_pdf, st3.s, st3.l); - if (st3.s[st3.l - 1] != '\n') - pdf_out(static_pdf, '\n'); - } - pdf_dict_add_streaminfo(static_pdf); - pdf_end_dict(static_pdf); - pdf_begin_stream(static_pdf); - if (lua_key_eq(st1_s, stream)) { - pdf_out_block(static_pdf, st2.s, st2.l); - } else if (lua_key_eq(st1_s, streamfile)) { + break; + case 2: + case 3: + if (lua_type(L,first_arg) != LUA_TSTRING) + luaL_error(L, "pdf.immediateobj() 1st argument must be string"); + if (!lua_isstring(L, first_arg + 1)) /* or number */ + luaL_error(L, "pdf.immediateobj() 2nd argument must be string"); + st1_s = lua_tostring(L, first_arg); + st2.s = lua_tolstring(L, first_arg + 1, &st2.l); + if (lua_key_eq(st1_s, file)) { + if (n == first_arg + 2) + luaL_error(L, "pdf.immediateobj() 3rd argument forbidden in file mode"); + pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); buf.s = fread_to_buf(L, st2.s, &buf.l); pdf_out_block(static_pdf, (const char *) buf.s, buf.l); xfree(buf.s); - } else - luaL_error(L, "pdf.immediateobj() invalid argument"); - pdf_end_stream(static_pdf); - pdf_end_obj(static_pdf); - } - break; - default: - luaL_error(L, "pdf.immediateobj() allows max. 3 arguments"); + pdf_end_obj(static_pdf); + } else { + pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* not an object stream candidate! */ + pdf_begin_dict(static_pdf); + if (n == first_arg + 2) { /* write attr text */ + if (!lua_isstring(L, first_arg + 2)) /* or number (maybe only string as it's an attr) */ + luaL_error(L, "pdf.immediateobj() 3rd argument must be string"); + st3.s = lua_tolstring(L, first_arg + 2, &st3.l); + pdf_out_block(static_pdf, st3.s, st3.l); + if (st3.s[st3.l - 1] != '\n') + pdf_out(static_pdf, '\n'); + } + pdf_dict_add_streaminfo(static_pdf); + pdf_end_dict(static_pdf); + pdf_begin_stream(static_pdf); + if (lua_key_eq(st1_s, stream)) { + pdf_out_block(static_pdf, st2.s, st2.l); + } else if (lua_key_eq(st1_s, streamfile)) { + buf.s = fread_to_buf(L, st2.s, &buf.l); + pdf_out_block(static_pdf, (const char *) buf.s, buf.l); + xfree(buf.s); + } else + luaL_error(L, "pdf.immediateobj() invalid argument"); + pdf_end_stream(static_pdf); + pdf_end_obj(static_pdf); + } + break; + default: + luaL_error(L, "pdf.immediateobj() allows max. 3 arguments"); } lua_pushinteger(L, k); return 1; @@ -193,23 +183,16 @@ static int table_obj(lua_State * L) attr.s = st.s = NULL; attr.l = 0; assert(lua_istable(L, 1)); /* t */ - - /* get object "type" */ - lua_key_rawgeti(type); if (lua_isnil(L, -1)) /* !vs t */ luaL_error(L, "pdf.obj(): object \"type\" missing"); - if (!lua_isstring(L, -1)) /* !vs t */ + if (lua_type(L,-1) != LUA_TSTRING) /* !vs t */ luaL_error(L, "pdf.obj(): object \"type\" must be string"); type = lua_tostring(L, -1); - if (! (lua_key_eq(type, raw) || lua_key_eq(type, stream))) { luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", type); /* i vs t */ } lua_pop(L, 1); /* t */ - - /* get optional "immediate" */ - lua_key_rawgeti(immediate); if (!lua_isnil(L, -1)) { /* b? t */ if (!lua_isboolean(L, -1)) /* !b t */ @@ -222,7 +205,7 @@ static int table_obj(lua_State * L) lua_key_rawgeti(objnum); if (!lua_isnil(L, -1)) { /* vi? t */ - if (!lua_isnumber(L, -1)) /* !vi t */ + if (lua_type(L,-1) != LUA_TNUMBER) /* !vi t */ luaL_error(L, "pdf.obj(): \"objnum\" must be integer"); k = (int) lua_tointeger(L, -1); /* vi t */ check_obj_type(static_pdf, obj_type_obj, k); @@ -245,7 +228,7 @@ static int table_obj(lua_State * L) if (!lua_isnil(L, -1)) { /* attr-s? t */ if (! lua_key_eq(type, stream)) luaL_error(L, "pdf.obj(): \"attr\" key not allowed for non-stream object"); - if (!lua_isstring(L, -1)) /* !attr-s t */ + if (!lua_isstring(L, -1)) /* or number */ /* !attr-s t */ luaL_error(L, "pdf.obj(): object \"attr\" must be string"); if (immediate == 1) { attr.s = lua_tolstring(L, -1, &attr.l); /* attr-s t */ @@ -262,7 +245,7 @@ static int table_obj(lua_State * L) if (!lua_isnil(L, -1)) { /* vi? t */ if (lua_key_eq(type, raw)) luaL_error(L, "pdf.obj(): \"compresslevel\" key not allowed for raw object"); - if (!lua_isnumber(L, -1)) /* !vi t */ + if (lua_type(L, -1) != LUA_TNUMBER) /* !vi t */ luaL_error(L, "pdf.obj(): \"compresslevel\" must be integer"); compress_level = (int) lua_tointeger(L, -1); /* vi t */ if (compress_level > 9) @@ -309,20 +292,16 @@ static int table_obj(lua_State * L) if (!lua_isnil(L, -2)) { /* file-s? string-s? t */ /* from string */ lua_pop(L, 1); /* string-s? t */ - if (!lua_isstring(L, -1)) /* !string-s t */ + if (!lua_isstring(L, -1)) /* or number */ /* !string-s t */ luaL_error(L, "pdf.obj(): \"string\" must be string for raw object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); pdf_out_block(static_pdf, st.s, st.l); - /* already in pdf_end_obj: - if (st.s[st.l - 1] != '\n') - pdf_out(static_pdf, '\n'); - */ } else obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ } else { /* from file */ - if (!lua_isstring(L, -1)) /* !file-s nil t */ + if (lua_type(L, -1) != LUA_TSTRING) /* !file-s nil t */ luaL_error(L, "pdf.obj(): \"file\" name must be string for raw object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ @@ -362,7 +341,7 @@ static int table_obj(lua_State * L) if (!lua_isnil(L, -2)) { /* file-s? string-s? t */ /* from string */ lua_pop(L, 1); /* string-s? t */ - if (!lua_isstring(L, -1)) /* !string-s t */ + if (!lua_isstring(L, -1)) /* or number */ /* !string-s t */ luaL_error(L, "pdf.obj(): \"string\" must be string for stream object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* string-s t */ @@ -371,7 +350,7 @@ static int table_obj(lua_State * L) obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ } else { /* from file */ - if (!lua_isstring(L, -1)) /* !file-s nil t */ + if (lua_type(L, -1) != LUA_TSTRING) /* !file-s nil t */ luaL_error(L, "pdf.obj(): \"file\" name must be string for stream object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ @@ -398,7 +377,7 @@ static int orig_obj(lua_State * L) int k; const char *st_s = NULL ; n = lua_gettop(L); - if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) { + if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { first_arg++; k=(int)lua_tonumber(L, 1); check_obj_type(static_pdf, obj_type_obj, k); @@ -416,14 +395,14 @@ static int orig_obj(lua_State * L) luaL_error(L, "pdf.obj() needs at least one argument"); break; case 1: - if (!lua_isstring(L, first_arg)) + if (!lua_isstring(L, first_arg)) /* or number */ luaL_error(L, "pdf.obj() 1st argument must be string"); break; case 2: case 3: - if (!lua_isstring(L, first_arg)) + if (lua_type(L, first_arg) != LUA_TSTRING) luaL_error(L, "pdf.obj() 1st argument must be string"); - if (!lua_isstring(L, first_arg + 1)) + if (!lua_isstring(L, first_arg + 1)) /* or number */ luaL_error(L, "pdf.obj() 2nd argument must be string"); st_s = lua_tostring(L, first_arg); if (lua_key_eq(st_s, file)) { @@ -432,7 +411,7 @@ static int orig_obj(lua_State * L) set_obj_obj_is_file(static_pdf, k); } else { if (n == first_arg + 2) { /* write attr text */ - if (!lua_isstring(L, -1)) + if (!lua_isstring(L, -1)) /* or number */ luaL_error(L, "pdf.obj() 3rd argument must be string"); obj_obj_stream_attr(static_pdf, k) = luaL_ref(Luas, LUA_REGISTRYINDEX); @@ -488,11 +467,10 @@ static int l_reserveobj(lua_State * L) switch (n) { case 0: static_pdf->obj_count++; - pdf_last_obj = - pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); + pdf_last_obj = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); break; case 1: - if (!lua_isstring(L, -1)) + if (lua_type(L, -1) != LUA_TSTRING) luaL_error(L, "pdf.reserveobj() optional argument must be string"); st_s = luaL_checkstring(L, 1); if (lua_key_eq(st_s, annot)) { @@ -538,6 +516,7 @@ static int l_get_pdf_value(lua_State * L, int key) lua_rawget(L,-2); return 1; } + static int l_get_pageresources(lua_State * L) { return l_get_pdf_value(L,lua_key_index(pageresources)); } @@ -556,12 +535,25 @@ static int l_get_info(lua_State * L) { static int l_get_names(lua_State * L) { return l_get_pdf_value(L,lua_key_index(names)); } - - static int l_get_trailer(lua_State * L) { return l_get_pdf_value(L,lua_key_index(trailer)); } +static int l_get_xformresources(lua_State * L) { + return l_get_pdf_value(L,lua_key_index(xformresources)); +} +static int l_get_xformattributes(lua_State * L) { + return l_get_pdf_value(L,lua_key_index(xformattributes)); +} +# define valid_pdf_key ( \ + lua_key_eq(s,catalog) || \ + lua_key_eq(s,info) || \ + lua_key_eq(s,trailer) || \ + lua_key_eq(s,names) || \ + lua_key_eq(s,pageattributes) || \ + lua_key_eq(s,pagesattributes) || \ + lua_key_eq(s,pageresources) \ +) static int getpdf(lua_State * L) { @@ -570,36 +562,30 @@ static int getpdf(lua_State * L) if (lua_gettop(L) != 2) { return 0; } - if (lua_isstring(L, -1)) { + if (lua_type(L,-1) == LUA_TSTRING) { s = lua_tostring(L, -1); if (lua_key_eq(s,h)) { lua_pushnumber(L, static_pdf->posstruct->pos.h); - return 1; + return 1; } else if (lua_key_eq(s,v)) { lua_pushnumber(L, static_pdf->posstruct->pos.v); - return 1; - } else if ( - lua_key_eq(s,catalog) || lua_key_eq(s,info) || lua_key_eq(s,trailer) || lua_key_eq(s,names) || - lua_key_eq(s,pageattributes) || lua_key_eq(s,pagesattributes) || lua_key_eq(s,pageresources) - ) { + return 1; + } else if (valid_pdf_key) { lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(pdf_data)); lua_gettable(L, LUA_REGISTRYINDEX); /* [pdf table] [key] [pdf.data table] */ lua_replace(L, -3); /* [pdf.data table] [key] */ - lua_rawget(L, -2); - return 1; + lua_rawget(L, -2); + return 1; } } return 0; } - - - static int l_set_pdf_value(lua_State * L, int key) { - if (lua_isstring(L, -1)) { + if (lua_type(L,-1) == LUA_TSTRING) { /* [value] */ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(pdf_data)); lua_gettable(L, LUA_REGISTRYINDEX); @@ -612,6 +598,7 @@ static int l_set_pdf_value(lua_State * L, int key) } return 0; } + static int l_set_pageresources(lua_State * L) { return l_set_pdf_value(L,lua_key_index(pageresources)); } @@ -633,7 +620,12 @@ static int l_set_names(lua_State * L) { static int l_set_trailer(lua_State * L) { return l_set_pdf_value(L,lua_key_index(trailer)); } - +static int l_set_xformresources(lua_State * L) { + return l_set_pdf_value(L,lua_key_index(xformresources)); +} +static int l_set_xformattributes(lua_State * L) { + return l_set_pdf_value(L,lua_key_index(xformattributes)); +} static int setpdf(lua_State * L) { @@ -642,12 +634,9 @@ static int setpdf(lua_State * L) if (lua_gettop(L) != 3) { return 0; } - if (lua_isstring(L, -2)) { - s = lua_tostring(L, -1); - if ( - lua_key_eq(s,catalog) || lua_key_eq(s,info) || lua_key_eq(s,trailer) || lua_key_eq(s,names) || - lua_key_eq(s,pageattributes) || lua_key_eq(s,pagesattributes) || lua_key_eq(s,pageresources) - ) { + if (lua_type(L, -2) == LUA_TSTRING) { + s = lua_tostring(L, -1); + if (valid_pdf_key) { lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(pdf_data)); lua_gettable(L, LUA_REGISTRYINDEX); /* [pdf table] [key] [value] [pdf.data table] */ @@ -659,7 +648,6 @@ static int setpdf(lua_State * L) return 0; } - static int l_objtype(lua_State * L) { int n = lua_gettop(L); @@ -686,7 +674,7 @@ static int l_mapfile(lua_State * L) { char *s; const char *st; - if (lua_isstring(L, -1) && (st = lua_tostring(L, -1)) != NULL) { + if ((lua_type(L,-1) == LUA_TSTRING) && (st = lua_tostring(L, -1)) != NULL) { s = xstrdup(st); process_map_item(s, MAPFILE); free(s); @@ -698,7 +686,7 @@ static int l_mapline(lua_State * L) { char *s; const char *st; - if (lua_isstring(L, -1) && (st = lua_tostring(L, -1)) != NULL) { + if ((lua_type(L,-1) == LUA_TSTRING) && (st = lua_tostring(L, -1)) != NULL) { s = xstrdup(st); process_map_item(s, MAPLINE); free(s); @@ -765,43 +753,264 @@ static int l_hasmatrix(lua_State * L) return 1 ; } +static int l_get_lastlink(lua_State * L) +{ + lua_pushnumber(L, (pdf_last_link)); + return 1 ; +} + +static int l_get_retval(lua_State * L) +{ + lua_pushnumber(L, (pdf_retval)); + return 1 ; +} + +static int l_get_lastobj(lua_State * L) +{ + lua_pushnumber(L, (pdf_last_obj)); + return 1 ; +} + +static int l_get_lastannot(lua_State * L) +{ + lua_pushnumber(L, (pdf_last_annot)); + return 1 ; +} + +/* maybe: + + get_fontname : set_ff(i) obj_info(static_pdf, pdf_font_num(ff)) + get_fontobjnum : set_ff(i) pdf_font_num(ff) + get_fontsize : font_size(i) + get_xformname : obj_info(static_pdf, i) + +*/ + +static int l_get_compresslevel(lua_State * L) +{ + lua_pushnumber(L, (pdf_compress_level)); + return 1 ; +} + +static int l_get_objcompresslevel(lua_State * L) +{ + lua_pushnumber(L, (pdf_objcompresslevel)); + return 1 ; +} + +static int l_set_compresslevel(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + if (c<0) + c = 0 ; + else if (c>9) + c = 9 ; + set_pdf_objcompresslevel(c); + } + return 0 ; +} + +static int l_set_objcompresslevel(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + if (c<0) + c = 0 ; + else if (c>9) + c = 9 ; + set_pdf_compress_level(c); + } + return 0 ; +} + +/* pdf stuff */ + +static int getpdffontname(lua_State * L) +{ + int c, ff ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + pdf_check_vf(c); + if (!font_used(c)) + pdf_init_font(static_pdf,c); + set_ff(c); + lua_pushnumber(L, (obj_info(static_pdf, pdf_font_num(ff)))); + } else { + lua_pushnil(L); + } + return 1 ; +} + +static int getpdffontobjnum(lua_State * L) +{ + int c, ff ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + pdf_check_vf(c); + if (!font_used(c)) + pdf_init_font(static_pdf,c); + set_ff(c); + lua_pushnumber(L, (pdf_font_num(ff))); + } else { + lua_pushnil(L); + } + return 1 ; +} + +static int getpdffontsize(lua_State * L) +{ + int c; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + lua_pushnumber(L, (font_size(c))); + } else { + lua_pushnil(L); + } + return 1 ; +} + +static int getpdfpageref(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + lua_pushnumber(L, (pdf_get_obj(static_pdf, obj_type_page, c, false))); + } else { + lua_pushnil(L); + } + return 1 ; +} + +static int getpdfxformname(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + check_obj_type(static_pdf, obj_type_xform, c); + lua_pushnumber(L, (obj_info(static_pdf, c))); + } else { + lua_pushnil(L); + } + return 1 ; +} + +static int getpdfversion(lua_State * L) +{ + lua_pushnumber(L,1); + return 1 ; +} + +static int getpdfminorversion(lua_State * L) +{ + /* lua_pushnumber(L,static_pdf->minor_version); */ + lua_pushnumber(L,pdf_minor_version); + return 1 ; +} + +static int setpdfminorversion(lua_State * L) +{ + int c ; + if (lua_type(L, 1) == LUA_TNUMBER) { + c = (int) lua_tointeger(L, 1); + if ((c >= 0) && (c <= 9)) { + static_pdf->minor_version = c; + set_pdf_minor_version(c); + } + } + return 0 ; +} + +static int newpdfcolorstack(lua_State * L) +{ + const char *s = NULL; + const char *l = NULL; + int literal_mode = 0; /* set_origin */ + boolean page_start = false; + int id ; + if (lua_type(L,1) != LUA_TSTRING) { + luaL_error(L, "pdf.newcolorstack() expects a string as first argument"); + } + s = lua_tostring(L, 1); + if (lua_type(L,2) == LUA_TSTRING) { + l = lua_tostring(L, 2); + if (lua_key_eq(l,origin)) { + literal_mode = 0; + } else if (lua_key_eq(l,page)) { + literal_mode = 1; /* direct_page */ + } else if (lua_key_eq(l,direct)) { + literal_mode = 2; /* direct_always */ + } else { + luaL_error(L, "invalid literal mode in pdf.newcolorstack()"); + } + } + if (lua_isboolean(L, 3)) { + page_start = lua_toboolean(L, 3); + } + id = newcolorstack(s, literal_mode, page_start); + lua_pushnumber(L, id); + return 1 ; +} static const struct luaL_Reg pdflib[] = { - {"immediateobj", l_immediateobj}, - {"mapfile", l_mapfile}, - {"mapline", l_mapline}, - {"maxobjnum", l_maxobjnum}, - {"obj", l_obj}, - {"objtype", l_objtype}, - {"pageref", l_pageref}, - {"print", luapdfprint}, - {"refobj", l_refobj}, - {"registerannot", l_registerannot}, - {"reserveobj", l_reserveobj}, - {"getpos", l_getpos}, - {"gethpos", l_gethpos}, - {"getvpos", l_getvpos}, - {"getmatrix", l_getmatrix}, - {"hasmatrix", l_hasmatrix}, - {"setcatalog", l_set_catalog}, - {"setinfo", l_set_info}, - {"setnames", l_set_names}, - {"settrailer", l_set_trailer}, - {"setpageresources", l_set_pageresources}, - {"setpageattributes", l_set_pageattributes}, - {"setpagesattributes", l_set_pagesattributes}, - {"getcatalog", l_get_catalog}, - {"getinfo", l_get_info}, - {"getnames", l_get_names}, - {"gettrailer", l_get_trailer}, - {"getpageresources", l_get_pageresources}, - {"getpageattributes", l_get_pageattributes}, - {"getpagesattributes", l_get_pagesattributes}, - {NULL, NULL} /* sentinel */ + { "immediateobj", l_immediateobj }, + { "mapfile", l_mapfile }, + { "mapline", l_mapline }, + { "maxobjnum", l_maxobjnum }, + { "obj", l_obj }, + { "objtype", l_objtype }, + { "pageref", l_pageref }, + { "print", luapdfprint }, + { "refobj", l_refobj }, + { "registerannot", l_registerannot }, + { "reserveobj", l_reserveobj }, + { "getpos", l_getpos }, + { "gethpos", l_gethpos }, + { "getvpos", l_getvpos }, + { "getmatrix", l_getmatrix }, + { "hasmatrix", l_hasmatrix }, + { "setcatalog", l_set_catalog }, + { "setinfo", l_set_info }, + { "setnames", l_set_names }, + { "settrailer", l_set_trailer }, + { "setpageresources", l_set_pageresources }, + { "setpageattributes", l_set_pageattributes }, + { "setpagesattributes", l_set_pagesattributes }, + { "setxformresources", l_set_xformresources }, + { "setxformattributes", l_set_xformattributes }, + { "getcatalog", l_get_catalog }, + { "getinfo", l_get_info }, + { "getnames", l_get_names }, + { "gettrailer", l_get_trailer }, + { "getpageresources", l_get_pageresources }, + { "getpageattributes", l_get_pageattributes }, + { "getpagesattributes", l_get_pagesattributes }, + { "getxformresources", l_get_xformresources }, + { "getxformattributes", l_get_xformattributes }, + { "getlastlink", l_get_lastlink }, + { "getretval", l_get_retval }, + { "getlastobj", l_get_lastobj }, + { "getlastannot", l_get_lastannot }, + { "getcompresslevel", l_get_compresslevel }, + { "getobjcompresslevel", l_get_objcompresslevel }, + { "setcompresslevel", l_set_compresslevel }, + { "setobjcompresslevel", l_set_objcompresslevel }, + /* moved from tex table */ + { "fontname", getpdffontname}, + { "fontobjnum", getpdffontobjnum}, + { "fontsize", getpdffontsize}, + { "pageref", getpdfpageref}, + { "xformname", getpdfxformname}, + { "getversion", getpdfversion}, + { "getminorversion", getpdfminorversion}, + { "setminorversion", setpdfminorversion}, + { "newcolorstack", newpdfcolorstack}, + /* sentinel */ + {NULL, NULL} }; -/**********************************************************************/ - int luaopen_pdf(lua_State * L) { lua_pushstring(L,"pdf.data"); diff --git a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c index eeb447f5064..74781cbd6af 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c @@ -31,8 +31,6 @@ typedef const char *(*charfunc) (void); typedef lua_Number(*numfunc) (void); typedef int (*intfunc) (void); -const char *last_lua_error; - static const char *getbanner(void) { return (const char *) luatex_banner; @@ -43,7 +41,6 @@ static const char *getlogname(void) return (const char *) texmf_log_name; } - static const char *get_output_file_name(void) { if (static_pdf != NULL) @@ -73,7 +70,20 @@ static const char *getlastluaerror(void) return last_lua_error; } +static const char *getlastwarningtag(void) +{ + return last_warning_tag; +} +static const char *getlastwarningstr(void) +{ + return last_warning_str; +} + +static const char *getlasterrorcontext(void) +{ + return last_error_context; +} static const char *luatexrevision(void) { @@ -189,6 +199,9 @@ static struct statistic stats[] = { {"lasterrorstring", 'S', (void *) &getlasterror}, {"lastluaerrorstring", 'S', (void *) &getlastluaerror}, + {"lastwarningtag", 'S', (void *) &getlastwarningtag}, + {"lastwarningstring", 'S', (void *) &getlastwarningstr}, + {"lasterrorcontext", 'S', (void *) &getlasterrorcontext}, /* seldom or never accessed */ @@ -240,6 +253,7 @@ static struct statistic stats[] = { {"param_size", 'g', ¶m_size}, {"buf_size", 'g', &buf_size}, {"save_size", 'g', &save_size}, + {"input_ptr", 'g', &input_ptr}, /* pdf stats */ {"obj_ptr", 'N', &get_obj_ptr}, {"obj_tab_size", 'N', &get_obj_tab_size}, @@ -331,7 +345,7 @@ static int getstats(lua_State * L) { const char *st; int i; - if (lua_isstring(L, -1)) { + if (lua_type(L,-1) == LUA_TSTRING) { st = lua_tostring(L, -1); i = stats_name_to_id(st); if (i >= 0) { @@ -361,10 +375,22 @@ static int statslist(lua_State * L) return 1; } - +static int resetmessages(lua_State * L) +{ + xfree(last_warning_str); + xfree(last_warning_tag); + xfree(last_error); + xfree(last_lua_error); + last_warning_str = NULL; + last_warning_tag = NULL; + last_error = NULL; + last_lua_error = NULL; + return 0; +} static const struct luaL_Reg statslib[] = { {"list", statslist}, + {"resetmessages", resetmessages}, {NULL, NULL} /* sentinel */ }; diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c index 5e4d515a848..2ae5812af22 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c @@ -1,5 +1,5 @@ /* ltexiolib.c - + Copyright 2006-2010 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -20,29 +20,40 @@ #include "ptexlib.h" #include "lua/luatex-api.h" - typedef void (*texio_printer) (const char *); static char *loggable_info = NULL; - static boolean get_selector_value(lua_State * L, int i, int *l) { boolean r = false; - if (lua_isstring(L, i)) { + int t = lua_type(L,i); + if (t == LUA_TSTRING) { const char *s = lua_tostring(L, i); - if (lua_key_eq(s,log)) { + if (lua_key_eq(s,term_and_log)) { + *l = term_and_log; + r = true; + } else if (lua_key_eq(s,log)) { *l = log_only; r = true; } else if (lua_key_eq(s,term)) { *l = term_only; r = true; - } else if (lua_key_eq(s,term_and_log)) { + } else { + *l = term_and_log; + r = true; + } + } else if (t == LUA_TNUMBER) { + int n = lua_tonumber(L,i); + if (file_can_be_written(n)) { + *l = n; + r = true; + } else { *l = term_and_log; r = true; } } else { - luaL_error(L, "first argument is not a string"); + luaL_error(L, "first argument is not 'term and log', 'term', 'log' or a number"); } return r; } @@ -53,19 +64,20 @@ static int do_texio_print(lua_State * L, texio_printer printfunction) int i = 1; int save_selector = selector; int n = lua_gettop(L); - if (n == 0 || !lua_isstring(L, -1)) { - luaL_error(L, "no string to print"); + if (n == 0 || !lua_isstring(L, -1)) { /* or number */ + luaL_error(L, "no string to print"); /* or number */ } if (n > 1) { if (get_selector_value(L, i, &selector)) i++; } - if (selector != log_only && selector != term_only - && selector != term_and_log) { - normalize_selector(); /* sets selector */ + if (selector != log_only && selector != term_only && selector != term_and_log) { + if (! valid_write_file(selector)) { + normalize_selector(); /* sets selector */ + } } for (; i <= n; i++) { - if (lua_isstring(L, i)) { + if (lua_isstring(L, i)) { /* or number */ s = lua_tostring(L, i); printfunction(s); } else { @@ -87,7 +99,7 @@ static void do_texio_ini_print(lua_State * L, const char *extra) i++; } for (; i <= n; i++) { - if (lua_isstring(L, i)) { + if (lua_isstring(L, i)) { /* or number */ s = lua_tostring(L, i); if (l == term_and_log || l == term_only) fprintf(stdout, "%s%s", extra, s); @@ -123,6 +135,7 @@ static int texio_printnl(lua_State * L) } /* at the point this function is called, the selector is log_only */ + void flush_loggable_info(void) { if (loggable_info != NULL) { @@ -132,11 +145,10 @@ void flush_loggable_info(void) } } - static const struct luaL_Reg texiolib[] = { {"write", texio_print}, {"write_nl", texio_printnl}, - {NULL, NULL} /* sentinel */ + {NULL, NULL} }; int luaopen_texio(lua_State * L) diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index f3e12f9d4b3..e0b37f68fec 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -24,7 +24,6 @@ setter no prev link is created so we can presume that it's not used later on. */ #include "ptexlib.h" #include "lua/luatex-api.h" - #define attribute(A) eqtb[attribute_base+(A)].hh.rh #define dimen(A) eqtb[scaled_base+(A)].hh.rh #undef skip @@ -38,7 +37,6 @@ extern int unif_rand(int ); extern int norm_rand(void ); extern void init_randoms(int ); - typedef struct { char *text; unsigned int tsize; @@ -53,18 +51,16 @@ typedef struct { char complete; /* currently still writing ? */ } spindle; -#define PARTIAL_LINE 1 -#define FULL_LINE 0 +#define PARTIAL_LINE 1 +#define FULL_LINE 0 #define write_spindle spindles[spindle_index] #define read_spindle spindles[(spindle_index-1)] -static int spindle_size = 0; +static int spindle_size = 0; static spindle *spindles = NULL; static int spindle_index = 0; - - static void luac_store(lua_State * L, int i, int partial, int cattable) { char *st; @@ -93,7 +89,6 @@ static void luac_store(lua_State * L, int i, int partial, int cattable) } } - static int do_luacprint(lua_State * L, int partial, int deftable) { int i, n; @@ -112,7 +107,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) if (lua_type(L, startstrings) == LUA_TTABLE) { for (i = 1;; i++) { lua_rawgeti(L, startstrings, i); - if (lua_isstring(L, -1)) { + if (lua_isstring(L,-1)) { /* or number */ luac_store(L, -1, partial, cattable); lua_pop(L, 1); } else { @@ -121,7 +116,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) } } else { for (i = startstrings; i <= n; i++) { - if (!lua_isstring(L, i)) { + if (!lua_isstring(L,1)) { /* or number */ luaL_error(L, "no string to print"); } luac_store(L, i, partial, cattable); @@ -141,9 +136,6 @@ static int do_luacprint(lua_State * L, int partial, int deftable) return 0; } - - - static int luacwrite(lua_State * L) { return do_luacprint(L, FULL_LINE, NO_CAT_TABLE); @@ -177,15 +169,15 @@ static int luactprint(lua_State * L) cattable=(int)lua_tonumber(L, -1); startstrings = 2; if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) { - cattable = DEFAULT_CAT_TABLE; - } + cattable = DEFAULT_CAT_TABLE; + } } lua_pop(L, 1); for (j = startstrings;; j++) { lua_pushnumber(L, j); lua_gettable(L, -2); - if (lua_type(L, -1) == LUA_TSTRING) { + if (lua_isstring(L, -1)) { /* or number */ luac_store(L, -1, PARTIAL_LINE, cattable); lua_pop(L, 1); } else { @@ -259,10 +251,7 @@ void luacstring_start(int n) (void) n; /* for -W */ spindle_index++; if (spindle_size == spindle_index) { /* add a new one */ - spindles = - xrealloc(spindles, - (unsigned) (sizeof(spindle) * - (unsigned) (spindle_size + 1))); + spindles = xrealloc(spindles, (unsigned) (sizeof(spindle) * (unsigned) (spindle_size + 1))); spindles[spindle_index].head = NULL; spindles[spindle_index].tail = NULL; spindles[spindle_index].complete = 0; @@ -297,13 +286,21 @@ void luacstring_close(int n) /* local (static) versions */ -#define check_index_range(j,s) \ - if (j<0 || j > 65535) { \ - luaL_error(L, "incorrect index value %d for tex.%s()", (int)j, s); } +#define check_index_range(j,s) \ + if (j<0 || j > 65535) { \ + luaL_error(L, "incorrect index specification for tex.%s()", s); } +#define check_register(base) do { \ + int k = get_item_index(L, lua_gettop(L), base); \ + if ((k>=0) && (k <= 65535)) { \ + lua_pushnumber(L,k); \ + } else { \ + lua_pushboolean(L,false); \ + } \ + return 1; \ +} while (1) -static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, - int *radix_ret) +static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, int *radix_ret) { boolean negative = false; /* should the answer be negated? */ int m; /* |$2^{31}$ / radix|, the threshold of danger */ @@ -359,7 +356,7 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, vacuous = false; if ((val >= m) && ((val > m) || (d > 7) || (radix1 != 10))) { if (OK_so_far) { - luaL_error(L, "Number too big"); + luaL_error(L, "Number too big"); val = infinity; OK_so_far = false; } @@ -470,7 +467,7 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) v = (x_height(get_cur_font())); } else if (strncmp(s, "px", 2) == 0) { s += 2; - v = dimen_par(pdf_px_dimen_code); + v = dimen_par(px_dimen_code); } else { goto NOT_FOUND; } @@ -585,19 +582,17 @@ int dimen_to_number(lua_State * L, const char *s) return j; } - static int tex_scaledimen(lua_State * L) -{ /* following vsetdimen() */ +{ int sp; - if (!lua_isnumber(L, 1)) { - if (lua_isstring(L, 1)) { - sp = dimen_to_number(L, lua_tostring(L, 1)); - } else { - luaL_error(L, "argument must be a string or a number"); - return 0; - } + int t = lua_type(L, 1); + if (t == LUA_TNUMBER) { + sp = (int) lua_tonumber(L, 1); + } else if (t == LUA_TSTRING) { + sp = dimen_to_number(L, lua_tostring(L, 1)); } else { - sp=(int)lua_tonumber(L, 1); + luaL_error(L, "argument must be a string or a number"); + return 0; } lua_pushnumber(L, sp); return 1; @@ -613,7 +608,7 @@ static int texerror (lua_State * L) l = 1; /* |errhlp| is terminated by a NULL entry */ for (i = 1;; i++) { lua_rawgeti(L, n, i); - if (lua_isstring(L, -1)) { + if (lua_type(L,-1) == LUA_TSTRING) { l++; lua_pop(L, 1); } else { @@ -626,7 +621,7 @@ static int texerror (lua_State * L) memset(errhlp,0,l * sizeof(char *)); for (i = 1;; i++) { lua_rawgeti(L, n, i); - if (lua_isstring(L, -1)) { + if (lua_type(L,-1) == LUA_TSTRING) { errhlp[(i-1)] = lua_tostring(L,-1); lua_pop(L, 1); } else { @@ -650,218 +645,290 @@ static int get_item_index(lua_State * L, int i, int base) int cur_cs1; const char *s; switch (lua_type(L, i)) { - case LUA_TSTRING: - s = lua_tolstring(L, i, &kk); - cur_cs1 = string_lookup(s, kk); - if (cur_cs1 == undefined_control_sequence || cur_cs1 == undefined_cs_cmd) - k = -1; /* guarandeed invalid */ - else - k = (equiv(cur_cs1) - base); - break; - case LUA_TNUMBER: - k = (int) luaL_checkinteger(L, i); - break; - default: - luaL_error(L, "argument must be a string or a number"); - k = -1; /* not a valid index */ + case LUA_TSTRING: + s = lua_tolstring(L, i, &kk); + cur_cs1 = string_lookup(s, kk); + if (cur_cs1 == undefined_control_sequence || cur_cs1 == undefined_cs_cmd) + k = -1; /* guarandeed invalid */ + else + k = (equiv(cur_cs1) - base); + break; + case LUA_TNUMBER: + k = (int) luaL_checkinteger(L, i); + break; + default: + luaL_error(L, "argument must be a string or a number"); + k = -1; /* not a valid index */ } return k; } -static int vsetdimen(lua_State * L, int is_global) -{ - int i, j, err; - int k; - int save_global_defs = int_par(global_defs_code); - if (is_global) - int_par(global_defs_code) = 1; - i = lua_gettop(L); - j = 0; - /* find the value */ - if (!lua_isnumber(L, i)) { - if (lua_isstring(L, i)) { - j = dimen_to_number(L, lua_tostring(L, i)); - } else { - luaL_error(L, "unsupported value type"); - } - } else { - j=(int)lua_tonumber(L, i); - } - k = get_item_index(L, (i - 1), scaled_base); - check_index_range(k, "setdimen"); - err = set_tex_dimen_register(k, j); - int_par(global_defs_code) = save_global_defs; - if (err) { - luaL_error(L, "incorrect value"); - } - return 0; +#define check_item_global(L,top,isglobal) \ + if (top == 3 && (lua_type(L,1) == LUA_TSTRING)) { \ + const char *s = lua_tostring(L, 1); \ + if (lua_key_eq(s,global)) { \ + isglobal = 1; \ + } \ + } + +#define set_item_index_plus(L, where, base, what, value, is_global, is_assign, set_register, glue) { \ + size_t len; \ + const char *str; \ + int key, err, cs; \ + int save_global_defs = int_par(global_defs_code); \ + if (is_global) { \ + int_par(global_defs_code) = 1; \ + } \ + switch (lua_type(L, where)) { \ + case LUA_TSTRING: \ + str = lua_tolstring(L, where, &len); \ + cs = string_lookup(str, len); \ + if (cs == undefined_control_sequence || cs == undefined_cs_cmd) { \ + luaL_error(L, "incorrect %s name", what); \ + } else { \ + key = equiv(cs) - base; \ + if (key >= 0 && key <= 65535) { \ + err = set_register(key, value); \ + if (err) { \ + luaL_error(L, "incorrect %s value", what); \ + } \ + } else if (is_assign(eq_type(cs))) { \ + if (glue) { \ + int a = is_global; \ + define(equiv(cs), assign_glue_cmd, value); \ + } else { \ + assign_internal_value((is_global ? 4 : 0), equiv(cs), value); \ + } \ + } else { \ + luaL_error(L, "incorrect %s name", what); \ + } \ + } \ + break; \ + case LUA_TNUMBER: \ + key = (int) luaL_checkinteger(L, where); \ + if (key>=0 && key <= 65535) { \ + err = set_register(key, value); \ + if (err) { \ + luaL_error(L, "incorrect %s value", what); \ + } \ + } else { \ + luaL_error(L, "incorrect %s index", what); \ + } \ + break; \ + default: \ + luaL_error(L, "argument of 'set%s' must be a string or a number", what); \ + } \ + int_par(global_defs_code) = save_global_defs; \ +} + +static int gettex(lua_State * L); + +#define get_item_index_plus(L, where, base, what, value, is_assign, get_register, glue) { \ + size_t len; \ + const char *str; \ + int key, cs; \ + switch (lua_type(L, where)) { \ + case LUA_TSTRING: \ + str = lua_tolstring(L, where, &len); \ + cs = string_lookup(str, len); \ + if (cs == undefined_control_sequence || cs == undefined_cs_cmd) { \ + luaL_error(L, "incorrect %s name", what); \ + } else { \ + key = equiv(cs) - base; \ + if (key >= 0 && key <= 65535) { \ + value = get_register(key); \ + } else if (is_assign(eq_type(cs))) { \ + gettex(L); /* lazy */ \ + } else { \ + luaL_error(L, "incorrect %s name", what); \ + } \ + } \ + break; \ + case LUA_TNUMBER: \ + key = (int) luaL_checkinteger(L, where); \ + if (key>=0 && key <= 65535) { \ + value = get_register(key); \ + } else { \ + luaL_error(L, "incorrect %s index", what); \ + } \ + break; \ + default: \ + luaL_error(L, "argument of 'set%s' must be a string or a number", what); \ + } \ +} + +static int isdimen(lua_State * L) +{ + check_register(scaled_base); } static int setdimen(lua_State * L) { int isglobal = 0; - int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (lua_key_eq(s,global)) - isglobal = 1; + int value = 0; + int top = lua_gettop(L); + int t = lua_type(L, top); + check_item_global(L,top,isglobal); + if (t == LUA_TNUMBER) { + value = (int) lua_tonumber(L, top); + } else if (t == LUA_TSTRING) { + value = dimen_to_number(L, lua_tostring(L, top)); + } else { + luaL_error(L, "unsupported %s value type","dimen"); } - return vsetdimen(L, isglobal); + set_item_index_plus(L, top-1, scaled_base, "dimen", value, isglobal, is_dim_assign, set_tex_dimen_register, false); + return 0; } static int getdimen(lua_State * L) { - int j; - int k; - k = get_item_index(L, lua_gettop(L), scaled_base); - check_index_range(k, "getdimen"); - j = get_tex_dimen_register(k); - lua_pushnumber(L, j); + int value = 0; + get_item_index_plus(L, lua_gettop(L), scaled_base, "dimen", value, is_dim_assign, get_tex_dimen_register, false); + lua_pushnumber(L, value); return 1; } -static int vsetskip(lua_State * L, int is_global) +static int isskip(lua_State * L) { - int i, err; - halfword *j; - int k; - int save_global_defs = int_par(global_defs_code); - if (is_global) - int_par(global_defs_code) = 1; - i = lua_gettop(L); - j = check_isnode(L, i); /* the value */ - k = get_item_index(L, (i - 1), skip_base); - check_index_range(k, "setskip"); /* the index */ - err = set_tex_skip_register(k, *j); - int_par(global_defs_code) = save_global_defs; - if (err) { - luaL_error(L, "incorrect value"); - } - return 0; + check_register(skip_base); } static int setskip(lua_State * L) { int isglobal = 0; - int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (lua_key_eq(s,global)) - isglobal = 1; - } - return vsetskip(L, isglobal); + halfword *value = NULL; + int top = lua_gettop(L); + check_item_global(L,top,isglobal); + value = check_isnode(L, top); + set_item_index_plus(L, top-1, skip_base, "skip", *value, isglobal, is_glue_assign, set_tex_skip_register, true); + return 0; } static int getskip(lua_State * L) { - halfword j; - int k; - k = get_item_index(L, lua_gettop(L), skip_base); - check_index_range(k, "getskip"); - j = get_tex_skip_register(k); - lua_nodelib_push_fast(L, j); + int value = 0; + get_item_index_plus(L, lua_gettop(L), skip_base, "skip", value, is_glue_assign, get_tex_skip_register, true); + if (value == null) { + lua_nodelib_push_fast(L, copy_node(zero_glue)); + } else { + lua_nodelib_push_fast(L, copy_node(value)); + } return 1; } +static int ismuskip(lua_State * L) +{ + check_register(mu_skip_base); +} - -static int vsetcount(lua_State * L, int is_global) +static int setmuskip(lua_State * L) { - int i, j, err; - int k; - int save_global_defs = int_par(global_defs_code); - if (is_global) - int_par(global_defs_code) = 1; - i = lua_gettop(L); - j = (int) luaL_checkinteger(L, i); - k = get_item_index(L, (i - 1), count_base); - check_index_range(k, "setcount"); - err = set_tex_count_register(k, j); - int_par(global_defs_code) = save_global_defs; - if (err) { - luaL_error(L, "incorrect value"); - } + int isglobal = 0; + halfword *value = NULL; + int top = lua_gettop(L); + check_item_global(L,top,isglobal); + value = check_isnode(L, top); + set_item_index_plus(L, top-1, mu_skip_base, "muskip", *value, isglobal, is_mu_glue_assign, set_tex_mu_skip_register, true); return 0; } +static int getmuskip(lua_State * L) +{ + int value = 0; + get_item_index_plus(L, lua_gettop(L), mu_skip_base, "muskip", value, is_mu_glue_assign, get_tex_mu_skip_register, true); + lua_nodelib_push_fast(L, copy_node(value)); + return 1; +} + +static int iscount(lua_State * L) +{ + check_register(count_base); +} + static int setcount(lua_State * L) { + int t; int isglobal = 0; - int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (lua_key_eq(s,global)) - isglobal = 1; + int value = 0; + int top = lua_gettop(L); + check_item_global(L,top,isglobal); + t = lua_type(L,top); + if (t == LUA_TNUMBER || t == LUA_TSTRING) { + value = (int) lua_tonumber(L, top); + } else { + luaL_error(L, "unsupported %s value type","count"); } - return vsetcount(L, isglobal); + set_item_index_plus(L, top-1, count_base, "count", value, isglobal, is_int_assign, set_tex_count_register, false); + return 0; } static int getcount(lua_State * L) { - int j; - int k; - k = get_item_index(L, lua_gettop(L), count_base); - check_index_range(k, "getcount"); - j = get_tex_count_register(k); - lua_pushnumber(L, j); + int value = 0; + get_item_index_plus(L, lua_gettop(L), count_base, "count", value, is_int_assign, get_tex_count_register, false); + lua_pushnumber(L, value); return 1; } - -static int vsetattribute(lua_State * L, int is_global) +static int isattribute(lua_State * L) { - int i, j, err; - int k; - int save_global_defs = int_par(global_defs_code); - if (is_global) - int_par(global_defs_code) = 1; - i = lua_gettop(L); - j = (int) luaL_checkinteger(L, i); - k = get_item_index(L, (i - 1), attribute_base); - check_index_range(k, "setattribute"); - err = set_tex_attribute_register(k, j); - int_par(global_defs_code) = save_global_defs; - if (err) { - luaL_error(L, "incorrect value"); - } - return 0; + check_register(attribute_base); } +/* there are no system set attributes so this is a bit overkill */ + static int setattribute(lua_State * L) { + int t; int isglobal = 0; - int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (lua_key_eq(s,global)) - isglobal = 1; + int value = 0; + int top = lua_gettop(L); + check_item_global(L,top,isglobal); + t = lua_type(L,top); + if (t == LUA_TNUMBER || t == LUA_TSTRING) { + value = (int) lua_tonumber(L, top); + } else { + luaL_error(L, "unsupported %s value type","attribute"); } - return vsetattribute(L, isglobal); + set_item_index_plus(L, top-1, attribute_base, "attribute", value, isglobal, is_attr_assign, set_tex_attribute_register, false); + return 0; } static int getattribute(lua_State * L) { - int j; - int k; - k = get_item_index(L, lua_gettop(L), attribute_base); - check_index_range(k, "getattribute"); - j = get_tex_attribute_register(k); - lua_pushnumber(L, j); + int value = 0; + get_item_index_plus(L, lua_gettop(L), attribute_base, "attribute", value, is_attr_assign, get_tex_attribute_register, false); + lua_pushnumber(L, value); return 1; } -static int vsettoks(lua_State * L, int is_global) +/* todo: we can avoid memcpy as there is no need to go through the pool */ + +/* use string_to_toks */ + +static int istoks(lua_State * L) +{ + check_register(toks_base); +} + +static int settoks(lua_State * L) { - int i, err; - int k; + int i, err, k; lstring str; char *s; const char *ss; + int is_global = 0; int save_global_defs = int_par(global_defs_code); + int n = lua_gettop(L); + if (n == 3 && (lua_type(L,1) == LUA_TSTRING)) { + const char *s = lua_tostring(L, 1); + if (lua_key_eq(s,global)) + is_global = 1; + } if (is_global) int_par(global_defs_code) = 1; i = lua_gettop(L); - if (!lua_isstring(L, i)) { + if (lua_type(L,i) != LUA_TSTRING) { luaL_error(L, "unsupported value type"); } ss = lua_tolstring(L, i, &str.l); @@ -879,16 +946,41 @@ static int vsettoks(lua_State * L, int is_global) return 0; } -static int settoks(lua_State * L) +static int scantoks(lua_State * L) { - int isglobal = 0; + int i, err, k, c; + lstring str; + char *s; + const char *ss; + int is_global = 0; + int save_global_defs = int_par(global_defs_code); int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { + if (n == 4 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); if (lua_key_eq(s,global)) - isglobal = 1; + is_global = 1; } - return vsettoks(L, isglobal); + /* action : vsettokscct(L, is_global); */ + if (is_global) + int_par(global_defs_code) = 1; + i = lua_gettop(L); + if (lua_type(L,i) != LUA_TSTRING) { + luaL_error(L, "unsupported value type"); + } + ss = lua_tolstring(L, i, &str.l); + s = xmalloc (str.l+1); + memcpy (s, ss, str.l+1); + str.s = (unsigned char *)s; + k = get_item_index(L, (i - 2), toks_base); + c = (int) luaL_checkinteger(L, i - 1); + check_index_range(k, "settoks"); + err = scan_tex_toks_register(k, c, str); + xfree(str.s); + int_par(global_defs_code) = save_global_defs; + if (err) { + luaL_error(L, "incorrect value"); + } + return 0; } static int gettoks(lua_State * L) @@ -906,7 +998,7 @@ static int gettoks(lua_State * L) return 1; } -static int get_box_id(lua_State * L, int i) +static int get_box_id(lua_State * L, int i, boolean report) { const char *s; int cur_cs1, cur_cmd1; @@ -926,7 +1018,9 @@ static int get_box_id(lua_State * L, int i) j=(int)lua_tonumber(L, (i)); break; default: - luaL_error(L, "argument must be a string or a number"); + if (report) { + luaL_error(L, "argument must be a string or a number"); + } j = -1; /* not a valid box id */ } return j; @@ -935,20 +1029,27 @@ static int get_box_id(lua_State * L, int i) static int getbox(lua_State * L) { int k, t; - k = get_box_id(L, -1); + k = get_box_id(L, -1, true); check_index_range(k, "getbox"); t = get_tex_box_register(k); nodelist_to_lua(L, t); return 1; } +static int isbox(lua_State * L) +{ + int k = get_box_id(L, -1, false); + lua_pushboolean(L,(k>=0 && k<=65535)); + return 1; +} + static int vsetbox(lua_State * L, int is_global) { int j, k, err; int save_global_defs = int_par(global_defs_code); if (is_global) int_par(global_defs_code) = 1; - k = get_box_id(L, -2); + k = get_box_id(L, -2, true); check_index_range(k, "setbox"); if (lua_isboolean(L, -1)) { j = lua_toboolean(L, -1); @@ -959,8 +1060,7 @@ static int vsetbox(lua_State * L, int is_global) } else { j = nodelist_from_lua(L); if (j != null && type(j) != hlist_node && type(j) != vlist_node) { - luaL_error(L, "setbox: incompatible node type (%s)\n", - get_node_name(type(j), subtype(j))); + luaL_error(L, "setbox: incompatible node type (%s)\n", get_node_name(type(j), subtype(j))); return 0; } @@ -977,7 +1077,7 @@ static int setbox(lua_State * L) { int isglobal = 0; int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { + if (n == 3 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); if (lua_key_eq(s,global)) isglobal = 1; @@ -987,7 +1087,8 @@ static int setbox(lua_State * L) #define check_char_range(j,s,lim) \ if (j<0 || j >= lim) { \ - luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); } + luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); \ + } static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), @@ -1000,12 +1101,12 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) f++; - if (n>2 && lua_isstring(L, f)) { + if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { level = level_one; - f++; - } + f++; + } } ch = (int) luaL_checkinteger(L, f); check_char_range(ch, name, 65536*17); @@ -1015,7 +1116,7 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), if (settwo != NULL && n-f == 2) { ucval = (halfword) luaL_checkinteger(L, f+2); check_char_range(ucval, name, lim); - (settwo)(ch, ucval, level); + (settwo)(ch, ucval, level); } return 0; } @@ -1068,16 +1169,16 @@ static int setcatcode(lua_State * L) int n = lua_gettop(L); int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) - f++; - if (n>2 && lua_isstring(L, f)) { + f++; + if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { level = level_one; - f++; - } + f++; + } } if (n-f == 2) { - cattable = (int) luaL_checkinteger(L, -3); + cattable = (int) luaL_checkinteger(L, -3); } ch = (int) luaL_checkinteger(L, -2); check_char_range(ch, "setcatcode", 65536*17); @@ -1092,7 +1193,7 @@ static int getcatcode(lua_State * L) int cattable = int_par(cat_code_table_code); int ch = (int) luaL_checkinteger(L, -1); if (lua_gettop(L)>=2 && lua_type(L,-2)==LUA_TNUMBER) { - cattable = luaL_checkinteger(L, -2); + cattable = luaL_checkinteger(L, -2); } check_char_range(ch, "getcatcode", 65536*17); lua_pushnumber(L, get_cat_code(cattable, ch)); @@ -1108,16 +1209,16 @@ static int setmathcode(lua_State * L) int n = lua_gettop(L); int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) - f++; - if (n>2 && lua_isstring(L, f)) { + f++; + if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { level = level_one; - f++; - } + f++; + } } if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { - luaL_error(L, "Bad arguments for tex.setmathcode()"); + luaL_error(L, "Bad arguments for tex.setmathcode()"); } ch = (int) luaL_checkinteger(L, -2); check_char_range(ch, "setmathcode", 65536*17); @@ -1153,7 +1254,17 @@ static int getmathcode(lua_State * L) return 1; } - +static int getmathcodes(lua_State * L) +{ + mathcodeval mval = { 0, 0, 0, 0 }; + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getmathcodes", 65536*17); + mval = get_math_code(ch); + lua_pushnumber(L,mval.class_value); + lua_pushnumber(L,mval.family_value); + lua_pushnumber(L,mval.character_value); + return 3; +} static int setdelcode(lua_State * L) { @@ -1163,8 +1274,8 @@ static int setdelcode(lua_State * L) int n = lua_gettop(L); int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) - f++; - if (n>2 && lua_isstring(L, f)) { + f++; + if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { level = level_one; @@ -1215,7 +1326,18 @@ static int getdelcode(lua_State * L) return 1; } - +static int getdelcodes(lua_State * L) +{ + delcodeval mval = { 0, 0, 0, 0, 0, 0 }; + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getdelcodes", 65536*17); + mval = get_del_code(ch); + lua_pushnumber(L,mval.small_family_value); + lua_pushnumber(L,mval.small_character_value); + lua_pushnumber(L,mval.large_family_value); + lua_pushnumber(L,mval.large_character_value); + return 4; +} static int settex(lua_State * L) { @@ -1226,11 +1348,38 @@ static int settex(lua_State * L) int isglobal = 0; j = 0; i = lua_gettop(L); - if (lua_isstring(L, (i - 1))) { + if (lua_type(L,i-1) == LUA_TSTRING) { st = lua_tolstring(L, (i - 1), &k); + + if (lua_key_eq(st,prevdepth)) { + if (lua_type(L, i) == LUA_TNUMBER) { + cur_list.prev_depth_field = lua_tonumber(L, i); + } else if (lua_type(L, i) == LUA_TSTRING) { + cur_list.prev_depth_field = dimen_to_number(L, lua_tostring(L, i)); + } else { + luaL_error(L, "unsupported value type"); + } + return 0; + } else if (lua_key_eq(st,prevgraf)) { + if (lua_type(L, i) != LUA_TNUMBER) { + cur_list.pg_field = lua_tonumber(L, i); + } else { + luaL_error(L, "unsupported value type"); + } + return 0; + } else if (lua_key_eq(st,spacefactor)) { + if (lua_type(L, i) != LUA_TNUMBER) { + cur_list.space_factor_field = lua_tonumber(L, i); + } else { + luaL_error(L, "unsupported value type"); + } + return 0; + } + + texstr = maketexlstring(st, k); if (is_primitive(texstr)) { - if (i == 3 && lua_isstring(L, 1)) { + if (i == 3 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); if (lua_key_eq(s,global)) isglobal = 1; @@ -1239,7 +1388,7 @@ static int settex(lua_State * L) flush_str(texstr); cur_cmd1 = eq_type(cur_cs1); if (is_int_assign(cur_cmd1)) { - if (lua_isnumber(L, i)) { + if (lua_type(L, i) == LUA_TNUMBER) { int luai; luai=(int)lua_tonumber(L, i); assign_internal_value((isglobal ? 4 : 0), @@ -1248,23 +1397,22 @@ static int settex(lua_State * L) luaL_error(L, "unsupported value type"); } } else if (is_dim_assign(cur_cmd1)) { - if (!lua_isnumber(L, i)) { - if (lua_isstring(L, i)) { - j = dimen_to_number(L, lua_tostring(L, i)); - } else { - luaL_error(L, "unsupported value type"); - } - } else { + if (lua_type(L, i) == LUA_TNUMBER) { j=(int)lua_tonumber(L, i); + } else if (lua_type(L, i) == LUA_TSTRING) { + j = dimen_to_number(L, lua_tostring(L, i)); + } else { + luaL_error(L, "unsupported value type"); } assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), j); } else if (is_glue_assign(cur_cmd1)) { halfword *j1 = check_isnode(L, i); /* the value */ - { int a = isglobal; - define(equiv(cur_cs1), assign_glue_cmd, *j1); - } + { + int a = isglobal; + define(equiv(cur_cs1), assign_glue_cmd, *j1); + } } else if (is_toks_assign(cur_cmd1)) { - if (lua_isstring(L, i)) { + if (lua_type(L,i) == LUA_TSTRING) { j = tokenlist_from_lua(L); /* uses stack -1 */ assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), j); @@ -1272,66 +1420,67 @@ static int settex(lua_State * L) luaL_error(L, "unsupported value type"); } - } else { - /* people may want to add keys that are also primitives - (|tex.wd| for example) so creating an error is not - right here */ - if (lua_istable(L, (i - 2))) - lua_rawset(L, (i - 2)); - /* luaL_error(L, "unsupported tex internal assignment"); */ - } - } else { - if (lua_istable(L, (i - 2))) + } else if (lua_istable(L, (i - 2))) { + /* + people may want to add keys that are also primitives |tex.wd| for example) + so creating an error is not right here + */ lua_rawset(L, (i - 2)); - } - } else { - if (lua_istable(L, (i - 2))) + } + } else if (lua_istable(L, (i - 2))) { lua_rawset(L, (i - 2)); + } + } else if (lua_istable(L, (i - 2))) { + lua_rawset(L, (i - 2)); } return 0; } +/* todo: some will to the pdf namespace .. ignore > 31 */ + static int do_convert(lua_State * L, int cur_code) { int texstr; int i = -1; char *str = NULL; switch (cur_code) { - case pdf_creation_date_code: /* ? */ - case pdf_insert_ht_code: /* arg <register int> */ - case pdf_ximage_bbox_code: /* arg 2 ints */ - case lua_code: /* arg complex */ - case lua_escape_string_code: /* arg token list */ - case pdf_colorstack_init_code: /* arg complex */ - case left_margin_kern_code: /* arg box */ - case right_margin_kern_code: /* arg box */ - break; - case string_code: /* arg token */ - case meaning_code: /* arg token */ - break; + /* ignored (yet) */ + + case insert_ht_code: /* arg <register int> */ + case lua_code: /* arg complex */ + case lua_escape_string_code: /* arg token list */ + case left_margin_kern_code: /* arg box */ + case right_margin_kern_code: /* arg box */ + case string_code: /* arg token */ + case meaning_code: /* arg token */ + break; /* the next fall through, and come from 'official' indices! */ - case font_name_code: /* arg fontid */ - case font_identifier_code: /* arg fontid */ - case pdf_font_name_code: /* arg fontid */ - case pdf_font_objnum_code: /* arg fontid */ - case pdf_font_size_code: /* arg fontid */ - case uniform_deviate_code: /* arg int */ - case number_code: /* arg int */ - case roman_numeral_code: /* arg int */ - case pdf_page_ref_code: /* arg int */ - case pdf_xform_name_code: /* arg int */ - if (lua_gettop(L) < 1) { - /* error */ - } - i=(int)lua_tonumber(L, 1); /* these fall through! */ - default: - texstr = the_convert_string(cur_code, i); - if (texstr) { - str = makecstring(texstr); - flush_str(texstr); - } + + case font_name_code: /* arg fontid */ + case font_identifier_code: /* arg fontid */ + case uniform_deviate_code: /* arg int */ + case number_code: /* arg int */ + case roman_numeral_code: /* arg int */ + + if (lua_gettop(L) < 1) { + /* error */ + } + i=(int)lua_tonumber(L, 1); + + /* these fall through! */ + + default: + /* no backend here */ + if (cur_code < 32) { + texstr = the_convert_string(cur_code, i); + if (texstr) { + str = makecstring(texstr); + flush_str(texstr); + } + } } + /* end */ if (str) { lua_pushstring(L, str); free(str); @@ -1341,7 +1490,6 @@ static int do_convert(lua_State * L, int cur_code) return 1; } - static int do_scan_internal(lua_State * L, int cur_cmd1, int cur_code) { int texstr; @@ -1350,22 +1498,27 @@ static int do_scan_internal(lua_State * L, int cur_cmd1, int cur_code) save_cur_val = cur_val; save_cur_val_level = cur_val_level; scan_something_simple(cur_cmd1, cur_code); - - if (cur_val_level == int_val_level || - cur_val_level == dimen_val_level || cur_val_level == attr_val_level) { - lua_pushnumber(L, cur_val); - } else if (cur_val_level == glue_val_level) { - lua_nodelib_push_fast(L, cur_val); - } else { /* dir_val_level, mu_val_level, tok_val_level */ - texstr = the_scanned_result(); - str = makecstring(texstr); - if (str) { - lua_pushstring(L, str); - free(str); - } else { - lua_pushnil(L); - } - flush_str(texstr); + switch (cur_val_level) { + case int_val_level: + case dimen_val_level: + case attr_val_level: + lua_pushnumber(L, cur_val); + break; + case glue_val_level: + case mu_val_level: + lua_nodelib_push_fast(L, copy_node(cur_val)); + break; + default: + texstr = the_scanned_result(); + str = makecstring(texstr); + if (str) { + lua_pushstring(L, str); + free(str); + } else { + lua_pushnil(L); + } + flush_str(texstr); + break; } cur_val = save_cur_val; cur_val_level = save_cur_val_level; @@ -1377,69 +1530,64 @@ static int do_lastitem(lua_State * L, int cur_code) int retval = 1; switch (cur_code) { /* the next two do not actually exist */ - case lastattr_code: - case attrexpr_code: - lua_pushnil(L); - break; - /* the expressions do something complicated with arguments, yuck */ - case numexpr_code: - case dimexpr_code: - case glueexpr_code: - case muexpr_code: - lua_pushnil(L); - break; - /* these read a glue or muglue, todo */ - case mu_to_glue_code: - case glue_to_mu_code: - case glue_stretch_order_code: - case glue_shrink_order_code: - case glue_stretch_code: - case glue_shrink_code: - lua_pushnil(L); - break; - /* these read a fontid and a char, todo */ - case font_char_wd_code: - case font_char_ht_code: - case font_char_dp_code: - case font_char_ic_code: - lua_pushnil(L); - break; - /* these read an integer, todo */ - case par_shape_length_code: - case par_shape_indent_code: - case par_shape_dimen_code: - lua_pushnil(L); - break; - case lastpenalty_code: - case lastkern_code: - case lastskip_code: - case last_node_type_code: - case input_line_no_code: - case badness_code: - case pdf_last_obj_code: - case pdf_last_xform_code: - case pdf_last_ximage_code: - case pdf_last_ximage_pages_code: - case pdf_last_annot_code: - case last_x_pos_code: - case last_y_pos_code: - case pdf_retval_code: - case pdf_last_ximage_colordepth_code: - case random_seed_code: - case pdf_last_link_code: - case luatex_version_code: - case eTeX_minor_version_code: - case eTeX_version_code: - case current_group_level_code: - case current_group_type_code: - case current_if_level_code: - case current_if_type_code: - case current_if_branch_code: - retval = do_scan_internal(L, last_item_cmd, cur_code); - break; - default: - lua_pushnil(L); - break; + case lastattr_code: + case attrexpr_code: + lua_pushnil(L); + break; + /* the expressions do something complicated with arguments, yuck */ + case numexpr_code: + case dimexpr_code: + case glueexpr_code: + case muexpr_code: + lua_pushnil(L); + break; + /* these read a glue or muglue, todo */ + case mu_to_glue_code: + case glue_to_mu_code: + case glue_stretch_order_code: + case glue_shrink_order_code: + case glue_stretch_code: + case glue_shrink_code: + lua_pushnil(L); + break; + /* these read a fontid and a char, todo */ + case font_char_wd_code: + case font_char_ht_code: + case font_char_dp_code: + case font_char_ic_code: + lua_pushnil(L); + break; + /* these read an integer, todo */ + case par_shape_length_code: + case par_shape_indent_code: + case par_shape_dimen_code: + lua_pushnil(L); + break; + case lastpenalty_code: + case lastkern_code: + case lastskip_code: + case last_node_type_code: + case input_line_no_code: + case badness_code: + case last_saved_box_resource_index_code: + case last_saved_image_resource_index_code: + case last_saved_image_resource_pages_code: + case last_x_pos_code: + case last_y_pos_code: + case random_seed_code: + case luatex_version_code: + case eTeX_minor_version_code: + case eTeX_version_code: + case current_group_level_code: + case current_group_type_code: + case current_if_level_code: + case current_if_type_code: + case current_if_branch_code: + retval = do_scan_internal(L, last_item_cmd, cur_code); + break; + default: + lua_pushnil(L); + break; } return retval; } @@ -1450,20 +1598,29 @@ static int tex_setmathparm(lua_State * L) int k; int n; int l = cur_level; + void *p; n = lua_gettop(L); if ((n == 3) || (n == 4)) { - if (n == 4 && lua_isstring(L, 1)) { + if (n == 4 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); if (lua_key_eq(s,global)) l = 1; } i = luaL_checkoption(L, (n - 2), NULL, math_param_names); j = luaL_checkoption(L, (n - 1), NULL, math_style_names); - if (!lua_isnumber(L, n)) - luaL_error(L, "argument must be a number"); - k=(int)lua_tonumber(L, n); - def_math_param(i, j, (scaled) k, l); + if (i<0 && i>=math_param_last) { + /* invalid spec, just ignore it */ + } else if (i>=math_param_first_mu_glue) { + p = lua_touserdata(L, n); + k = *((halfword *)p); + def_math_param(i, j, (scaled) k, l); + } else { + if (lua_type(L, n) == LUA_TNUMBER) + luaL_error(L, "argument must be a number"); + k=(int)lua_tonumber(L, n); + def_math_param(i, j, (scaled) k, l); + } } return 0; } @@ -1476,7 +1633,16 @@ static int tex_getmathparm(lua_State * L) i = luaL_checkoption(L, 1, NULL, math_param_names); j = luaL_checkoption(L, 2, NULL, math_style_names); k = get_math_param(i, j); - lua_pushnumber(L, k); + if (i<0 && i>=math_param_last) { + lua_pushnil(L); + } else if (i>=math_param_first_mu_glue) { + if (k <= thick_mu_skip_code) { + k = glue_par(k); + } + lua_nodelib_push_fast(L, k); + } else { + lua_pushnumber(L, k); + } } return 1; } @@ -1491,21 +1657,6 @@ static int getfontidentifier(lua_State * L) return do_convert(L, font_identifier_code); } -static int getpdffontname(lua_State * L) -{ - return do_convert(L, pdf_font_name_code); -} - -static int getpdffontobjnum(lua_State * L) -{ - return do_convert(L, pdf_font_objnum_code); -} - -static int getpdffontsize(lua_State * L) -{ - return do_convert(L, pdf_font_size_code); -} - static int getuniformdeviate(lua_State * L) { return do_convert(L, uniform_deviate_code); @@ -1521,17 +1672,6 @@ static int getromannumeral(lua_State * L) return do_convert(L, roman_numeral_code); } -static int getpdfpageref(lua_State * L) -{ - return do_convert(L, pdf_page_ref_code); -} - -static int getpdfxformname(lua_State * L) -{ - return do_convert(L, pdf_xform_name_code); -} - - static int get_parshape(lua_State * L) { int n; @@ -1555,16 +1695,27 @@ static int get_parshape(lua_State * L) return 1; } - static int gettex(lua_State * L) { int cur_cs1 = -1; int retval = 1; /* default is to return nil */ int t = lua_gettop(L); - if (lua_isstring(L, t)) { /* 1 == 'tex', 2 == 'boxmaxdepth', or 1 == 'boxmaxdepth' */ + if (lua_type(L,t) == LUA_TSTRING) { /* 1 == 'tex', 2 == 'boxmaxdepth', or 1 == 'boxmaxdepth' */ int texstr; size_t k; const char *st = lua_tolstring(L, t, &k); + + if (lua_key_eq(st,prevdepth)) { + lua_pushnumber(L, cur_list.prev_depth_field); + return 1; + } else if (lua_key_eq(st,prevgraf)) { + lua_pushnumber(L, cur_list.pg_field); + return 1; + } else if (lua_key_eq(st,spacefactor)) { + lua_pushnumber(L, cur_list.space_factor_field); + return 1; + } + texstr = maketexlstring(st, k); cur_cs1 = prim_lookup(texstr); /* not found == relax == 0 */ flush_str(texstr); @@ -1602,19 +1753,16 @@ static int gettex(lua_State * L) lua_pushnil(L); break; } - } else { - if (t == 2) { + } else if (t == 2) { lua_rawget(L, 1); - } } return retval; } - static int getlist(lua_State * L) { const char *str; - if (lua_isstring(L, 2)) { + if (lua_type(L,2) == LUA_TSTRING) { str = lua_tostring(L, 2); if (lua_key_eq(str,page_ins_head)) { if (vlink(page_ins_head) == page_ins_head) @@ -1623,15 +1771,15 @@ static int getlist(lua_State * L) lua_pushnumber(L, vlink(page_ins_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,contrib_head)) { - alink(vlink(contrib_head)) = null ; + alink(vlink(contrib_head)) = null ; lua_pushnumber(L, vlink(contrib_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,page_head)) { - alink(vlink(page_head)) = null ;/*hh-ls */ + alink(vlink(page_head)) = null ;/*hh-ls */ lua_pushnumber(L, vlink(page_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,temp_head)) { - alink(vlink(temp_head)) = null ;/*hh-ls */ + alink(vlink(temp_head)) = null ;/*hh-ls */ lua_pushnumber(L, vlink(temp_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,hold_head)) { @@ -1671,7 +1819,7 @@ static int setlist(lua_State * L) halfword *n_ptr; const char *str; halfword n = 0; - if (lua_isstring(L, 2)) { + if (lua_type(L,2) == LUA_TSTRING) { str = lua_tostring(L, 2); if (lua_key_eq(str,best_size)) { best_size = (int) lua_tointeger(L, 3); @@ -1822,7 +1970,8 @@ static int getnest(lua_State * L) { int ptr; list_state_record **nestitem; - if (lua_isnumber(L, 2)) { + int t = lua_type(L, 2); + if (t == LUA_TNUMBER) { ptr=(int)lua_tonumber(L, 2); if (ptr >= 0 && ptr <= nest_ptr) { nestitem = lua_newuserdata(L, sizeof(list_state_record *)); @@ -1832,7 +1981,7 @@ static int getnest(lua_State * L) } else { lua_pushnil(L); } - } else if (lua_isstring(L, 2)) { + } else if (t == LUA_TSTRING) { const char *s = lua_tostring(L, 2); if (lua_key_eq(s,ptr)) { lua_pushnumber(L, nest_ptr); @@ -1853,8 +2002,8 @@ static int setnest(lua_State * L) static int do_integer_error(double m) { - const char *help[] = - { "I can only go up to 2147483647='17777777777=" "7FFFFFFF,", + const char *help[] = { + "I can only go up to 2147483647='17777777777=" "7FFFFFFF,", "so I'm using that number instead of yours.", NULL }; @@ -1862,7 +2011,6 @@ static int do_integer_error(double m) return (m > 0.0 ? infinity : -infinity); } - static int tex_roundnumber(lua_State * L) { double m = (double) lua_tonumber(L, 1) + 0.5; @@ -1882,7 +2030,7 @@ static int tex_scaletable(lua_State * L) while (lua_next(L, 1) != 0) { /* numeric value */ lua_pushvalue(L, -2); lua_insert(L, -2); - if (lua_isnumber(L, -1)) { + if (lua_type(L,-2) == LUA_TNUMBER) { double m = (double) lua_tonumber(L, -1) * delta + 0.5; lua_pop(L, 1); if (abs(m) > (double) infinity) @@ -1892,7 +2040,7 @@ static int tex_scaletable(lua_State * L) } lua_rawset(L, 3); } - } else if (lua_isnumber(L, 1)) { + } else if (lua_type(L,1) == LUA_TNUMBER) { double m = (double) lua_tonumber(L, 1) * delta + 0.5; if (abs(m) > (double) infinity) lua_pushnumber(L, do_integer_error(m)); @@ -1915,10 +2063,7 @@ static int tex_definefont(lua_State * L) int i = 1; int a = 0; if (!no_new_control_sequence) { - const char *help[] = - { "You can't create a new font inside a \\csname\\endcsname pair", - NULL - }; + const char *help[] = { "You can't create a new font inside a \\csname\\endcsname pair", NULL }; tex_error("Definition active", help); } if ((lua_gettop(L) == 3) && lua_isboolean(L, 1)) { @@ -1991,10 +2136,13 @@ static int tex_extraprimitives(lua_State * L) int cs = 0; n = lua_gettop(L); if (n == 0) { - mask = etex_command + pdftex_command + luatex_command + umath_command; + mask = etex_command + + pdftex_command /* obsolete */ + + umath_command /* obsolete */ + + luatex_command; } else { for (i = 1; i <= n; i++) { - if (lua_isstring(L, i)) { + if (lua_type(L,i) == LUA_TSTRING) { const char *s = lua_tostring(L, i); if (lua_key_eq(s,etex)) { mask |= etex_command; @@ -2002,11 +2150,12 @@ static int tex_extraprimitives(lua_State * L) mask |= tex_command; } else if (lua_key_eq(s,core)) { mask |= core_command; - } else if (lua_key_eq(s,pdftex)) { + } else if (lua_key_eq(s,pdftex)) { /* obsolete */ mask |= pdftex_command; } else if (lua_key_eq(s,luatex)) { - mask |= luatex_command | umath_command; - } else if (lua_key_eq(s,umath)) { + mask |= luatex_command + | umath_command; /* obsolete */ + } else if (lua_key_eq(s,umath)) { /* obsolete */ mask |= umath_command; } } @@ -2045,7 +2194,7 @@ static int tex_enableprimitives(lua_State * L) i = 1; while (1) { lua_rawgeti(L, 2, i); - if (lua_isstring(L, 3)) { + if (lua_type(L,3) == LUA_TSTRING) { const char *prim = lua_tostring(L, 3); str_number s = maketexstring(prim); halfword prim_val = prim_lookup(s); @@ -2068,8 +2217,7 @@ static int tex_enableprimitives(lua_State * L) val = string_lookup(newprim, newl); if (val == undefined_control_sequence || eq_type(val) == undefined_cs_cmd) { - primitive_def(newprim, newl, (quarterword) cur_cmd1, - cur_chr1); + primitive_def(newprim, newl, (quarterword) cur_cmd1, cur_chr1); } free(newprim); } @@ -2090,55 +2238,55 @@ static int tex_enableprimitives(lua_State * L) return 0; } -#define get_int_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ +#define get_int_par(A,B,C) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B=(int)lua_tonumber(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ } while (0) -#define get_intx_par(A,B,C,D,E) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - D = null; \ - } else if (lua_type(L, -1) == LUA_TTABLE){ \ - B = 0; \ - D = nodelib_topenalties(L, lua_gettop(L)); \ - } else { \ - B = (C); \ - D = (E); \ - } \ - lua_pop(L,1); \ +#define get_intx_par(A,B,C,D,E) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B=(int)lua_tonumber(L, -1); \ + D = null; \ + } else if (lua_type(L, -1) == LUA_TTABLE){ \ + B = 0; \ + D = nodelib_topenalties(L, lua_gettop(L)); \ + } else { \ + B = (C); \ + D = (E); \ + } \ + lua_pop(L,1); \ } while (0) -#define get_dimen_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ +#define get_dimen_par(A,B,C) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B=(int)lua_tonumber(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ } while (0) -#define get_glue_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) != LUA_TNIL) { \ - B = *check_isnode(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ +#define get_glue_par(A,B,C) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) != LUA_TNIL) { \ + B = *check_isnode(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ } while (0) @@ -2204,7 +2352,7 @@ static halfword nodelib_topenalties(lua_State * L, int i) j = 2; while (lua_next(L, i) != 0) { j++; - if (lua_isnumber(L, -1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { int pen = 0; pen=(int)lua_tonumber(L, -1); varmem[p+j].cint = pen; @@ -2216,9 +2364,6 @@ static halfword nodelib_topenalties(lua_State * L, int i) return p; } - - - static int tex_run_linebreak(lua_State * L) { @@ -2228,9 +2373,6 @@ static int tex_run_linebreak(lua_State * L) int paragraph_dir = 0; /* locally initialized parameters for line breaking */ int pretolerance, tracingparagraphs, tolerance, looseness, - /* - hyphenpenalty, exhyphenpenalty, - */ adjustspacing, adjdemerits, protrudechars, linepenalty, lastlinefit, doublehyphendemerits, finalhyphendemerits, hangafter, interlinepenalty, widowpenalty, clubpenalty, brokenpenalty; @@ -2245,9 +2387,7 @@ static int tex_run_linebreak(lua_State * L) j = check_isnode(L, 1); /* the value */ vlink(temp_head) = *j; p = *j; - if ((!is_char_node(vlink(*j))) - && ((type(vlink(*j)) == whatsit_node) - && (subtype(vlink(*j)) == local_par_node))) { + if ((!is_char_node(vlink(*j))) && ((type(vlink(*j)) == local_par_node))) { paragraph_dir = local_par_dir(vlink(*j)); } @@ -2277,48 +2417,52 @@ static int tex_run_linebreak(lua_State * L) } lua_pop(L, 1); - get_int_par("pretolerance", pretolerance, int_par(pretolerance_code)); - get_int_par("tracingparagraphs", tracingparagraphs, - int_par(tracing_paragraphs_code)); - get_int_par("tolerance", tolerance, int_par(tolerance_code)); - get_int_par("looseness", looseness, int_par(looseness_code)); - /* - get_int_par("hyphenpenalty", hyphenpenalty, int_par(hyphen_penalty_code)); - get_int_par("exhyphenpenalty", exhyphenpenalty, - int_par(ex_hyphen_penalty_code)); - */ - get_int_par("adjustspacing", adjustspacing, - int_par(adjust_spacing_code)); - get_int_par("adjdemerits", adjdemerits, int_par(adj_demerits_code)); - get_int_par("protrudechars", protrudechars, - int_par(protrude_chars_code)); - get_int_par("linepenalty", linepenalty, int_par(line_penalty_code)); - get_int_par("lastlinefit", lastlinefit, int_par(last_line_fit_code)); - get_int_par("doublehyphendemerits", doublehyphendemerits, - int_par(double_hyphen_demerits_code)); - get_int_par("finalhyphendemerits", finalhyphendemerits, - int_par(final_hyphen_demerits_code)); - get_int_par("hangafter", hangafter, int_par(hang_after_code)); - get_intx_par("interlinepenalty", interlinepenalty,int_par(inter_line_penalty_code), - interlinepenalties, equiv(inter_line_penalties_loc)); - get_intx_par("clubpenalty", clubpenalty, int_par(club_penalty_code), - clubpenalties, equiv(club_penalties_loc)); - get_intx_par("widowpenalty", widowpenalty, int_par(widow_penalty_code), - widowpenalties, equiv(widow_penalties_loc)); - get_int_par("brokenpenalty", brokenpenalty, int_par(broken_penalty_code)); - get_dimen_par("emergencystretch", emergencystretch, - dimen_par(emergency_stretch_code)); - get_dimen_par("hangindent", hangindent, dimen_par(hang_indent_code)); - get_dimen_par("hsize", hsize, dimen_par(hsize_code)); - get_glue_par("leftskip", leftskip, glue_par(left_skip_code)); - get_glue_par("rightskip", rightskip, glue_par(right_skip_code)); + get_int_par("pretolerance", + pretolerance, int_par(pretolerance_code)); + get_int_par("tracingparagraphs", + tracingparagraphs, int_par(tracing_paragraphs_code)); + get_int_par("tolerance", + tolerance, int_par(tolerance_code)); + get_int_par("looseness", + looseness, int_par(looseness_code)); + get_int_par("adjustspacing", + adjustspacing, int_par(adjust_spacing_code)); + get_int_par("adjdemerits", + adjdemerits, int_par(adj_demerits_code)); + get_int_par("protrudechars", + protrudechars, int_par(protrude_chars_code)); + get_int_par("linepenalty", + linepenalty, int_par(line_penalty_code)); + get_int_par("lastlinefit", + lastlinefit, int_par(last_line_fit_code)); + get_int_par("doublehyphendemerits", + doublehyphendemerits, int_par(double_hyphen_demerits_code)); + get_int_par("finalhyphendemerits", + finalhyphendemerits, int_par(final_hyphen_demerits_code)); + get_int_par("hangafter", + hangafter, int_par(hang_after_code)); + get_intx_par("interlinepenalty", + interlinepenalty,int_par(inter_line_penalty_code), interlinepenalties, equiv(inter_line_penalties_loc)); + get_intx_par("clubpenalty", + clubpenalty, int_par(club_penalty_code), clubpenalties, equiv(club_penalties_loc)); + get_intx_par("widowpenalty", + widowpenalty, int_par(widow_penalty_code), widowpenalties, equiv(widow_penalties_loc)); + get_int_par("brokenpenalty", + brokenpenalty, int_par(broken_penalty_code)); + get_dimen_par("emergencystretch", + emergencystretch, dimen_par(emergency_stretch_code)); + get_dimen_par("hangindent", + hangindent, dimen_par(hang_indent_code)); + get_dimen_par("hsize", + hsize, dimen_par(hsize_code)); + get_glue_par("leftskip", + leftskip, glue_par(left_skip_code)); + get_glue_par("rightskip", + rightskip, glue_par(right_skip_code)); ext_do_line_break(paragraph_dir, pretolerance, tracingparagraphs, tolerance, emergencystretch, looseness, - /* - hyphenpenalty, exhyphenpenalty, - */ adjustspacing, parshape, adjdemerits, protrudechars, @@ -2359,7 +2503,7 @@ static int tex_run_linebreak(lua_State * L) static int tex_shipout(lua_State * L) { - int boxnum = get_box_id(L, 1); + int boxnum = get_box_id(L, 1, true); ship_out(static_pdf, box(boxnum), SHIPPING_PAGE); box(boxnum) = null; return 0; @@ -2374,7 +2518,6 @@ static int tex_badness(lua_State * L) return 1; } - static int tex_run_boot(lua_State * L) { int n = lua_gettop(L); @@ -2414,38 +2557,38 @@ static int tex_run_boot(lua_State * L) /* tex is ready to go, now */ unhide_lua_table(Luas, "tex", tex_table_id); unhide_lua_table(Luas, "pdf", pdf_table_id); - unhide_lua_table(Luas, "newtoken", newtoken_table_id); unhide_lua_table(Luas, "token", token_table_id); + unhide_lua_table(Luas, "oldtoken", oldtoken_table_id); unhide_lua_table(Luas, "node", node_table_id); lua_pushboolean(L, 1); /* true */ return 1; - } /* tex random generators */ + static int tex_init_rand(lua_State * L) { - int sp; - if (!lua_isnumber(L, 1)) { - luaL_error(L, "argument must be a number"); - return 0; - } - sp=(int)lua_tonumber(L, 1); - init_randoms(sp); - return 0; + int sp; + if (lua_type(L, 1) != LUA_TNUMBER) { + luaL_error(L, "argument must be a number"); + return 0; + } + sp=(int)lua_tonumber(L, 1); + init_randoms(sp); + return 0; } static int tex_unif_rand(lua_State * L) { - int sp; - if (!lua_isnumber(L, 1)) { - luaL_error(L, "argument must be a number"); - return 0; - } - sp=(int)lua_tonumber(L, 1); - lua_pushnumber(L, unif_rand(sp)); - return 1; + int sp; + if (lua_type(L, 1) != LUA_TNUMBER) { + luaL_error(L, "argument must be a number"); + return 0; + } + sp=(int)lua_tonumber(L, 1); + lua_pushnumber(L, unif_rand(sp)); + return 1; } static int tex_norm_rand(lua_State * L) @@ -2455,68 +2598,35 @@ static int tex_norm_rand(lua_State * L) } /* Same as lua but with tex rng */ -static int lua_math_random (lua_State *L) -{ - lua_Number rand_max = 0x7fffffff ; - lua_Number r = unif_rand(rand_max) ; - r = (r>=0 ? 0+r : 0-r) ; - r = r / rand_max; - switch (lua_gettop(L)) { /* check number of arguments */ - case 0: { /* no arguments */ - lua_pushnumber(L, r); /* Number between 0 and 1 */ - break; - } - case 1: { /* only upper limit */ - lua_Number u = luaL_checknumber(L, 1); - luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty"); - lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* [1, u] */ - break; - } - case 2: { /* lower and upper limits */ - lua_Number l = luaL_checknumber(L, 1); - lua_Number u = luaL_checknumber(L, 2); - luaL_argcheck(L, l <= u, 2, "interval is empty"); - lua_pushnumber(L, floor(r*(u-l+1)) + l); /* [l, u] */ - break; - } - default: return luaL_error(L, "wrong number of arguments"); - } - return 1; -} - - - -/* Experimental code can either become permanent or disappear. It is -undocumented and mostly present in the experimental branch but for -practical reasons we also have the setup code in the regular binary. -The experimental_code array is indexed by i with 1<= i <= max_experimental_code, -position 0 is not used */ -int experimental_code[MAX_EXPERIMENTAL_CODE_SIZE] = { 0 }; - -static int set_experimental_code(lua_State *L) + static int lua_math_random (lua_State *L) { - int e, b, i ; - - if (lua_isboolean(L,1)) { - e = 0 ; - b = lua_toboolean(L,1) ; - } else if (lua_isnumber(L,1) && lua_isboolean(L,2)) { - e = (int) lua_tonumber(L, 1); - b = lua_toboolean(L,2) ; - } else { - return luaL_error(L, "boolean or number and boolean expected"); - } - if (e==0) { - for (i=1;i<=max_experimental_code;i++) { - experimental_code[i] = b; + lua_Number rand_max = 0x7fffffff ; + lua_Number r = unif_rand(rand_max) ; + r = (r>=0 ? 0+r : 0-r) ; + r = r / rand_max; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; } - } else if (0<e && e<=max_experimental_code ) { - experimental_code[e] = b; - } else { - return luaL_error(L, "first number out of range"); + case 1: { /* only upper limit */ + lua_Number u = luaL_checknumber(L, 1); + luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* [1, u] */ + break; + } + case 2: { /* lower and upper limits */ + lua_Number l = luaL_checknumber(L, 1); + lua_Number u = luaL_checknumber(L, 2); + luaL_argcheck(L, l <= u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1)) + l); /* [l, u] */ + break; + } + default: + return luaL_error(L, "wrong number of arguments"); } - return 0; + return 1; } static int tex_run_main(lua_State * L) @@ -2542,6 +2652,91 @@ static int tex_show_context(lua_State * L) return 0; } +static int tex_save_box_resource(lua_State * L) +{ + halfword boxnumber, boxdata; + int index, attributes, resources; + /* box attributes resources */ + boxnumber = (halfword) lua_tonumber(L,1); + if (lua_type(L,2) == LUA_TSTRING) { + lua_pushvalue(L, 2); + attributes = luaL_ref(L, LUA_REGISTRYINDEX); + } else { + attributes = null; + } + if (lua_type(L,3) == LUA_TSTRING) { + lua_pushvalue(L, 3); + resources = luaL_ref(L, LUA_REGISTRYINDEX); + } else { + resources = null; + } + /* more or less same as scanner variant */ + boxdata = box(boxnumber); + if (boxdata == null) + normal_error("pdf backend", "xforms cannot be used with a void box"); + static_pdf->xform_count++; + index = pdf_create_obj(static_pdf, obj_type_xform, static_pdf->xform_count); + set_obj_data_ptr(static_pdf, index, pdf_get_mem(static_pdf, pdfmem_xform_size)); + set_obj_xform_attr(static_pdf, index, null); + set_obj_xform_attr_str(static_pdf, index, attributes); + set_obj_xform_resources(static_pdf, index, null); + set_obj_xform_resources_str(static_pdf, index, resources); + set_obj_xform_box(static_pdf, index, (int) boxdata); + set_obj_xform_width(static_pdf, index, width(boxdata)); + set_obj_xform_height(static_pdf, index, height(boxdata)); + set_obj_xform_depth(static_pdf, index, depth(boxdata)); + box(boxnumber) = null; + last_saved_box_index = index; + lua_pushnumber(L, index); + return 1; +} + +static int tex_use_box_resource(lua_State * L) +{ + halfword rule; + int index = 0; + scaled_whd alt, nat, dim; + int top = lua_gettop(L); + alt.wd = null_flag; + alt.ht = null_flag; + alt.dp = null_flag; + if (top == 0) + return 0; + index = lua_tonumber(L,1); + if (top>1) + alt.wd = (scaled) lua_tonumber(L,2); + if (top>2) + alt.ht = (scaled) lua_tonumber(L,3); + if (top>3) + alt.dp = (scaled) lua_tonumber(L,4); + /* sort of the same as backend */ + check_obj_type(static_pdf, obj_type_xform, index); + nat.wd = obj_xform_width(static_pdf, index); + nat.ht = obj_xform_height(static_pdf, index); + nat.dp = obj_xform_depth(static_pdf, index); + if (alt.wd != null_flag || alt.ht != null_flag || alt.dp != null_flag) { + dim = tex_scale(nat, alt); + } else { + dim = nat; + } + rule = new_rule(box_rule); + rule_index(rule) = index; + width(rule) = dim.wd; + height(rule) = dim.ht; + depth(rule) = dim.dp; + nodelist_to_lua(L, rule); + lua_pushnumber(L, (int) dim.wd); + lua_pushnumber(L, (int) dim.ht); + lua_pushnumber(L, (int) dim.dp); + return 4; +} + +static int tex_build_page(lua_State * L) +{ + build_page(); + return 0; +} + void init_tex_table(lua_State * L) { lua_createtable(L, 0, 3); @@ -2554,9 +2749,6 @@ void init_tex_table(lua_State * L) lua_setglobal(L, "tex"); } - - - static const struct luaL_Reg texlib[] = { {"run", tex_run_main}, /* may be needed */ {"finish", tex_run_end}, /* may be needed */ @@ -2567,16 +2759,26 @@ static const struct luaL_Reg texlib[] = { {"sprint", luacsprint}, {"set", settex}, {"get", gettex}, + {"isdimen", isdimen}, {"setdimen", setdimen}, {"getdimen", getdimen}, + {"isskip", isskip}, {"setskip", setskip}, {"getskip", getskip}, + {"ismuskip", ismuskip}, + {"setmuskip", setmuskip}, + {"getmuskip", getmuskip}, + {"isattribute", isattribute}, {"setattribute", setattribute}, {"getattribute", getattribute}, + {"iscount", iscount}, {"setcount", setcount}, {"getcount", getcount}, + {"istoks", istoks}, {"settoks", settoks}, + {"scantoks", scantoks}, {"gettoks", gettoks}, + {"isbox", isbox}, {"setbox", setbox}, {"getbox", getbox}, {"setlist", setlist}, @@ -2587,10 +2789,12 @@ static const struct luaL_Reg texlib[] = { {"getcatcode", getcatcode}, {"setdelcode", setdelcode}, {"getdelcode", getdelcode}, + {"getdelcodes", getdelcodes}, {"setlccode", setlccode}, {"getlccode", getlccode}, {"setmathcode", setmathcode}, {"getmathcode", getmathcode}, + {"getmathcodes", getmathcodes}, {"setsfcode", setsfcode}, {"getsfcode", getsfcode}, {"setuccode", setuccode}, @@ -2600,14 +2804,9 @@ static const struct luaL_Reg texlib[] = { {"sp", tex_scaledimen}, {"fontname", getfontname}, {"fontidentifier", getfontidentifier}, - {"pdffontname", getpdffontname}, - {"pdffontobjnum", getpdffontobjnum}, - {"pdffontsize", getpdffontsize}, {"uniformdeviate", getuniformdeviate}, {"number", getnumber}, {"romannumeral", getromannumeral}, - {"pdfpageref", getpdfpageref}, - {"pdfxformname", getpdfxformname}, {"definefont", tex_definefont}, {"hashtokens", tex_hashpairs}, {"primitives", tex_primitives}, @@ -2624,29 +2823,34 @@ static const struct luaL_Reg texlib[] = { {"normal_rand", tex_norm_rand}, {"lua_math_randomseed", tex_init_rand}, /* syntactic sugar */ {"lua_math_random", lua_math_random}, - {"set_experimental_code",set_experimental_code}, {"show_context", tex_show_context}, - {NULL, NULL} /* sentinel */ + {"saveboxresource", tex_save_box_resource}, + {"useboxresource", tex_use_box_resource}, + /* just for testing: it will probably stay but maybe with options */ + {"triggerbuildpage", tex_build_page}, + /* sentinel */ + {NULL, NULL} }; int luaopen_tex(lua_State * L) { luaL_register(L, "tex", texlib); /* *INDENT-OFF* */ - make_table(L, "attribute", "tex.attribute" ,"getattribute", "setattribute"); - make_table(L, "skip", "tex.skip" ,"getskip", "setskip"); - make_table(L, "dimen", "tex.dimen" ,"getdimen", "setdimen"); - make_table(L, "count", "tex.count" ,"getcount", "setcount"); - make_table(L, "toks", "tex.toks" ,"gettoks", "settoks"); - make_table(L, "box", "tex.box" ,"getbox", "setbox"); - make_table(L, "sfcode", "tex.sfcode" ,"getsfcode", "setsfcode"); - make_table(L, "lccode", "tex.lccode" ,"getlccode", "setlccode"); - make_table(L, "uccode", "tex.uccode" ,"getuccode", "setuccode"); - make_table(L, "catcode", "tex.catcode" ,"getcatcode", "setcatcode"); - make_table(L, "mathcode", "tex.mathcode" ,"getmathcode", "setmathcode"); - make_table(L, "delcode", "tex.delcode" ,"getdelcode", "setdelcode"); - make_table(L, "lists", "tex.lists" ,"getlist", "setlist"); - make_table(L, "nest", "tex.nest" ,"getnest", "setnest"); + make_table(L, "attribute", "tex.attribute", "getattribute", "setattribute"); + make_table(L, "skip", "tex.skip", "getskip", "setskip"); + make_table(L, "muskip", "tex.muskip", "getmuskip", "setmuskip"); + make_table(L, "dimen", "tex.dimen", "getdimen", "setdimen"); + make_table(L, "count", "tex.count", "getcount", "setcount"); + make_table(L, "toks", "tex.toks", "gettoks", "settoks"); + make_table(L, "box", "tex.box", "getbox", "setbox"); + make_table(L, "sfcode", "tex.sfcode", "getsfcode", "setsfcode"); + make_table(L, "lccode", "tex.lccode", "getlccode", "setlccode"); + make_table(L, "uccode", "tex.uccode", "getuccode", "setuccode"); + make_table(L, "catcode", "tex.catcode", "getcatcode", "setcatcode"); + make_table(L, "mathcode", "tex.mathcode", "getmathcode", "setmathcode"); + make_table(L, "delcode", "tex.delcode", "getdelcode", "setdelcode"); + make_table(L, "lists", "tex.lists", "getlist", "setlist"); + make_table(L, "nest", "tex.nest", "getnest", "setnest"); /* *INDENT-ON* */ init_nest_lib(L); /* make the meta entries */ diff --git a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c index fd3edb2921f..21686c6c3ec 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c @@ -1,5 +1,5 @@ /* ltokenlib.c - + Copyright 2006-2012 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -42,11 +42,13 @@ static unsigned char *get_cs_text(int cs) static int test_expandable(lua_State * L) { int cmd = -1; + int t; if (is_valid_token(L, -1)) { get_token_cmd(L, -1); - if (lua_isnumber(L, -1)) { + t = lua_type(L, -1); + if (t == LUA_TNUMBER) { cmd = (int) lua_tointeger(L, -1); - } else if (lua_isstring(L, -1)) { + } else if (t == LUA_TSTRING) { cmd = get_command_id(lua_tostring(L, -1)); } if (cmd > max_command_cmd) { @@ -64,11 +66,13 @@ static int test_expandable(lua_State * L) static int test_protected(lua_State * L) { int chr = -1; + int t; if (is_valid_token(L, -1)) { get_token_chr(L, -1); - if (lua_isnumber(L, -1)) { + t = lua_type(L, -1); + if (t == LUA_TNUMBER) { chr = (int) lua_tointeger(L, -1); - } else if (lua_isstring(L, -1)) { + } else if (t == LUA_TSTRING) { chr = get_command_id(lua_tostring(L, -1)); } if (token_info(token_link(chr)) == protected_token) { @@ -88,7 +92,7 @@ static int test_activechar(lua_State * L) unsigned char *s; int cs = 0; get_token_cs(L, -1); - if (lua_isnumber(L, -1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { cs = (int) lua_tointeger(L, -1); } lua_pop(L, 1); @@ -111,7 +115,7 @@ static int run_get_command_name(lua_State * L) int cs; if (is_valid_token(L, -1)) { get_token_cmd(L, -1); - if (lua_isnumber(L, -1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { cs = (int) lua_tointeger(L, -1); lua_pushstring(L, command_names[cs].cmd_name); } else { @@ -131,14 +135,14 @@ static int run_get_csname_name(lua_State * L) if (is_valid_token(L, -1)) { get_token_cmd(L, -1); /* - if (lua_isnumber(L, -1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { cmd = (int) lua_tointeger(L, -1); } */ lua_pop(L, 1); cs = 0; get_token_cs(L, -1); - if (lua_isnumber(L, -1)) { + if (lua_type(L, -1) == LUA_TNUMBER) { cs = (int) lua_tointeger(L, -1); } lua_pop(L, 1); @@ -160,7 +164,7 @@ static int run_get_csname_name(lua_State * L) static int run_get_command_id(lua_State * L) { int cs = -1; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { cs = get_command_id(lua_tostring(L, -1)); } lua_pushnumber(L, cs); @@ -172,7 +176,7 @@ static int run_get_csname_id(lua_State * L) { const char *s; size_t k, cs = 0; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { s = lua_tolstring(L, -1, &k); cs = (size_t) string_lookup(s, k); } @@ -217,7 +221,7 @@ static int run_lookup(lua_State * L) size_t l; int cs, cmd, chr; int save_nncs; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { s = lua_tolstring(L, -1, &l); if (l > 0) { save_nncs = no_new_control_sequence; @@ -238,7 +242,7 @@ static int run_lookup(lua_State * L) static int run_build(lua_State * L) { int cmd, chr, cs; - if (lua_isnumber(L, 1)) { + if (lua_type(L, 1) == LUA_TNUMBER) { cs = 0; chr = (int) lua_tointeger(L, 1); cmd = (int) luaL_optinteger(L, 2, get_char_cat_code(chr)); @@ -277,8 +281,8 @@ static const struct luaL_Reg tokenlib[] = { {NULL, NULL} /* sentinel */ }; -int luaopen_token(lua_State * L) +int luaopen_oldtoken(lua_State * L) { - luaL_register(L, "token", tokenlib); + luaL_register(L, "oldtoken", tokenlib); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.h b/Build/source/texk/web2c/luatexdir/lua/luagen.h index ae30fa1313b..d49f60f02b8 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luagen.h +++ b/Build/source/texk/web2c/luatexdir/lua/luagen.h @@ -1,5 +1,5 @@ /* luagen.h - + Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> This file is part of LuaTeX. @@ -17,10 +17,4 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ - -extern void lua_begin_page(PDF pdf); -extern void lua_end_page(PDF pdf); - -extern void lua_place_glyph(PDF pdf, internal_font_number f, int c, int ex); -extern void lua_place_rule(PDF pdf, scaledpos size); -extern void finish_lua_file(PDF pdf); +/* obsolete, one can intercept nodelist and flush as lua if needed */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.w b/Build/source/texk/web2c/luatexdir/lua/luagen.w index caf377ae445..f5b01df8505 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luagen.w +++ b/Build/source/texk/web2c/luatexdir/lua/luagen.w @@ -17,37 +17,4 @@ % You should have received a copy of the GNU General Public License along % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -@ @c - - -#include "ptexlib.h" -#include "pdf/pdfpage.h" - -@ @c -void lua_begin_page(PDF pdf) -{ - (void) pdf; -} - -void lua_end_page(PDF pdf) -{ - (void) pdf; -} - -void lua_place_glyph(PDF pdf, internal_font_number f, int c, int ex) -{ - (void) pdf; - (void) f; - printf("%c", (int) c); -} - -void lua_place_rule(PDF pdf, scaledpos size) -{ - (void) pdf; - (void) size; -} - -void finish_lua_file(PDF pdf) -{ - (void) pdf; -} +/* obsolete */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luainit.w b/Build/source/texk/web2c/luatexdir/lua/luainit.w index 610aa06ec42..1fe90a888ac 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luainit.w +++ b/Build/source/texk/web2c/luatexdir/lua/luainit.w @@ -27,7 +27,7 @@ #include "lua/luatex-api.h" /* internalized strings: see luatex-api.h */ -set_make_keys; +set_make_keys; @ @@ -68,14 +68,9 @@ const_string LUATEX_IHELP[] = { "", " The following regular options are understood: ", "", - " --8bit ignored, input is assumed to be in UTF-8 encoding", " --credits display credits and exit", " --debug-format enable format debugging", - " --default-translate-file=FILE ignored, input is assumed to be in UTF-8 encoding", - " --disable-write18 disable \\write18{SHELL COMMAND}", " --draftmode switch on draft mode (generates no output PDF)", - " --enable-write18 enable \\write18{SHELL COMMAND}", - " --etex ignored, the etex extensions are always active", " --[no-]file-line-error disable/enable file:line:error style messages", " --[no-]file-line-error-style aliases of --[no-]file-line-error", " --fmt=FORMAT load the format file FORMAT", @@ -91,30 +86,38 @@ const_string LUATEX_IHELP[] = { " --output-comment=STRING use STRING for DVI file comment instead of date (no effect for PDF)", " --output-directory=DIR use existing DIR as the directory to write files in", " --output-format=FORMAT use FORMAT for job output; FORMAT is 'dvi' or 'pdf'", - " --[no-]parse-first-line ignored", " --progname=STRING set the program name to STRING", " --recorder enable filename recorder", " --safer disable easily exploitable lua commands", " --[no-]shell-escape disable/enable \\write18{SHELL COMMAND}", " --shell-restricted restrict \\write18 to a list of commands given in texmf.cnf", " --synctex=NUMBER enable synctex", - " --translate-file=FILE ignored, input is assumed to be in UTF-8 encoding", " --version display version and exit", "", "Alternate behaviour models can be obtained by special switches", "", - " --luaonly run a lua file, then exit", - " --luaconly byte-compile a lua file, then exit", - " --luahashchars the bits used by current Lua interpreter for strings hashing", + " --luaonly run a lua file, then exit", + " --luaconly byte-compile a lua file, then exit", + " --luahashchars the bits used by current Lua interpreter for strings hashing", #ifdef LuajitTeX - " --jiton turns the JIT compiler on (default off)", - " --jithash=STRING choose the hash function for the lua strings (lua51|luajit20: default lua51)", + " --jiton turns the JIT compiler on (default off)", + " --jithash=STRING choose the hash function for the lua strings (lua51|luajit20: default lua51)", #endif "", "See the reference manual for more information about the startup process.", NULL }; +/* + " --8bit ignored, input is assumed to be in UTF-8 encoding", + " --default-translate-file=FILE ignored, input is assumed to be in UTF-8 encoding", + " --etex ignored, the etex extensions are always active", + " --disable-write18 disable \\write18{SHELL COMMAND}", + " --enable-write18 enable \\write18{SHELL COMMAND}", + " --[no-]parse-first-line ignored", + " --translate-file=FILE ignored, input is assumed to be in UTF-8 encoding", +*/ + @ The return value will be the directory of the executable, e.g.: \.{c:/TeX/bin} @c static char *ex_selfdir(char *argv0) @@ -198,54 +201,66 @@ option table in a variable |long_options|. @c #define ARGUMENT_IS(a) STREQ (long_options[option_index].name, a) -/* SunOS cc can't initialize automatic structs, so make this static. */ -static struct option long_options[] -= { {"fmt", 1, 0, 0}, -{"lua", 1, 0, 0}, -{"luaonly", 0, 0, 0}, -{"luahashchars", 0, 0, 0}, +/* + SunOS cc can't initialize automatic structs, so make this static. +*/ + +/* + Nota Bene: we still intercept some options that other engines handle + so that existing scripted usage will not fail. +*/ + +static struct option long_options[] = { + {"fmt", 1, 0, 0}, + {"lua", 1, 0, 0}, + {"luaonly", 0, 0, 0}, + {"luahashchars", 0, 0, 0}, #ifdef LuajitTeX -{"jiton", 0, 0, 0}, -{"jithash", 1, 0, 0}, + {"jiton", 0, 0, 0}, + {"jithash", 1, 0, 0}, #endif -{"safer", 0, &safer_option, 1}, -{"nosocket", 0, &nosocket_option, 1}, -{"help", 0, 0, 0}, -{"ini", 0, &ini_version, 1}, -{"interaction", 1, 0, 0}, -{"halt-on-error", 0, &haltonerrorp, 1}, -{"kpathsea-debug", 1, 0, 0}, -{"progname", 1, 0, 0}, -{"version", 0, 0, 0}, -{"credits", 0, 0, 0}, -{"recorder", 0, &recorder_enabled, 1}, -{"etex", 0, 0, 0}, -{"output-comment", 1, 0, 0}, -{"output-directory", 1, 0, 0}, -{"draftmode", 0, 0, 0}, -{"output-format", 1, 0, 0}, -{"shell-escape", 0, &shellenabledp, 1}, -{"no-shell-escape", 0, &shellenabledp, -1}, -{"enable-write18", 0, &shellenabledp, 1}, -{"disable-write18", 0, &shellenabledp, -1}, -{"shell-restricted", 0, 0, 0}, -{"debug-format", 0, &debug_format_file, 1}, -{"file-line-error-style", 0, &filelineerrorstylep, 1}, -{"no-file-line-error-style", 0, &filelineerrorstylep, -1}, - /* Shorter option names for the above. */ -{"file-line-error", 0, &filelineerrorstylep, 1}, -{"no-file-line-error", 0, &filelineerrorstylep, -1}, -{"jobname", 1, 0, 0}, -{"parse-first-line", 0, &parsefirstlinep, 1}, -{"no-parse-first-line", 0, &parsefirstlinep, -1}, -{"translate-file", 1, 0, 0}, -{"default-translate-file", 1, 0, 0}, -{"8bit", 0, 0, 0}, -{"mktex", 1, 0, 0}, -{"no-mktex", 1, 0, 0}, -/* Synchronization: just like "interaction" above */ -{"synctex", 1, 0, 0}, -{0, 0, 0, 0} + {"safer", 0, &safer_option, 1}, + {"nosocket", 0, &nosocket_option, 1}, + {"help", 0, 0, 0}, + {"ini", 0, &ini_version, 1}, + {"interaction", 1, 0, 0}, + {"halt-on-error", 0, &haltonerrorp, 1}, + {"kpathsea-debug", 1, 0, 0}, + {"progname", 1, 0, 0}, + {"version", 0, 0, 0}, + {"credits", 0, 0, 0}, + {"recorder", 0, &recorder_enabled, 1}, + {"etex", 0, 0, 0}, + {"output-comment", 1, 0, 0}, + {"output-directory", 1, 0, 0}, + {"draftmode", 0, 0, 0}, + {"output-format", 1, 0, 0}, + {"shell-escape", 0, &shellenabledp, 1}, + {"no-shell-escape", 0, &shellenabledp, -1}, + {"enable-write18", 0, &shellenabledp, 1}, + {"disable-write18", 0, &shellenabledp, -1}, + {"shell-restricted", 0, 0, 0}, + {"debug-format", 0, &debug_format_file, 1}, + {"file-line-error-style", 0, &filelineerrorstylep, 1}, + {"no-file-line-error-style", 0, &filelineerrorstylep, -1}, + + /* Shorter option names for the above. */ + + {"file-line-error", 0, &filelineerrorstylep, 1}, + {"no-file-line-error", 0, &filelineerrorstylep, -1}, + {"jobname", 1, 0, 0}, + {"parse-first-line", 0, &parsefirstlinep, 1}, + {"no-parse-first-line", 0, &parsefirstlinep, -1}, + {"translate-file", 1, 0, 0}, + {"default-translate-file", 1, 0, 0}, + {"8bit", 0, 0, 0}, + {"mktex", 1, 0, 0}, + {"no-mktex", 1, 0, 0}, + + /* Synchronization: just like "interaction" above */ + + {"synctex", 1, 0, 0}, + {0, 0, 0, 0} }; @ @c @@ -370,20 +385,19 @@ static void parse_options(int ac, char **av) restrictedshell = 1; } else if (ARGUMENT_IS("output-format")) { - pdf_output_option = 1; + output_mode_option = 1; if (strcmp(optarg, "dvi") == 0) { - pdf_output_value = 0; + output_mode_value = 0; } else if (strcmp(optarg, "pdf") == 0) { - pdf_output_value = 2; + output_mode_value = 1; } else { - WARNING1("Ignoring unknown value `%s' for --output-format", - optarg); - pdf_output_option = 0; + WARNING1("Ignoring unknown value `%s' for --output-format",optarg); + output_mode_option = 0; } } else if (ARGUMENT_IS("draftmode")) { - pdf_draftmode_option = 1; - pdf_draftmode_value = 1; + draft_mode_option = 1; + draft_mode_value = 1; } else if (ARGUMENT_IS("mktex")) { kpse_maketex_option(optarg, true); @@ -421,12 +435,7 @@ static void parse_options(int ac, char **av) "the terms of the GNU General Public License, version 2 or (at your option)\n" "any later version. For more information about these matters, see the file\n" "named COPYING and the LuaTeX source.\n\n" -#ifdef LuajitTeX - "LuaTeX is Copyright 2015 Taco Hoekwater, the LuaTeX Team.\n" - "Libraries and JIT extensions by Luigi Scarso, the LuaTeX SwigLib team.\n"); -#else - "Copyright 2015 Taco Hoekwater, the LuaTeX Team.\n"); -#endif + "LuaTeX is Copyright 2015 Taco Hoekwater and the LuaTeX Team.\n"); /* *INDENT-ON* */ uexit(0); } else if (ARGUMENT_IS("credits")) { @@ -434,33 +443,19 @@ static void parse_options(int ac, char **av) initversionstring(&versions); print_version_banner(); /* *INDENT-OFF* */ - puts("\n\nThe LuaTeX team is Hans Hagen, Hartmut Henkel, Taco Hoekwater.\n" + puts("\n\nThe LuaTeX team is Hans Hagen, Hartmut Henkel, Taco Hoekwater, Luigi Scarso.\n\n" MyName " merges and builds upon (parts of) the code from these projects:\n\n" - "tex by Donald Knuth\n" - "etex by Peter Breitenlohner, Phil Taylor and friends\n" - "omega by John Plaice and Yannis Haralambous\n" - "aleph by Giuseppe Bilotta\n" - "pdftex by Han The Thanh and friends\n" - "kpathsea by Karl Berry, Olaf Weber and others\n" - "lua by Roberto Ierusalimschy, Waldemar Celes\n" - " and Luiz Henrique de Figueiredo\n" - "metapost by John Hobby, Taco Hoekwater and friends.\n" - "poppler by Derek Noonburg, Kristian H\\ogsberg (partial)\n" -#ifdef LuajitTeX - "fontforge by George Williams (partial)\n" - "luajit by Mike Pall\n\n" -#else - "fontforge by George Williams (partial)\n\n" -#endif - "Some extensions to lua and additional lua libraries are used, as well as\n" - "libraries for graphic inclusion. More details can be found in the source.\n" - "Code development was sponsored by a grant from Colorado State University\n" -#ifdef LuajitTeX - "via the 'oriental tex' project, the TeX User Groups, and donations.\n" - "The additional libraries and the LuaJIT extensions are provided by the LuaTeX SwigLib project.\n"); -#else - "via the 'oriental tex' project, the TeX User Groups, and donations.\n"); -#endif + "tex : Donald Knuth\n" + "etex : Peter Breitenlohner, Phil Taylor and friends\n" + "omega : John Plaice and Yannis Haralambous\n" + "aleph : Giuseppe Bilotta\n" + "pdftex : Han The Thanh and friends\n" + "kpathsea : Karl Berry, Olaf Weber and others\n" + "lua : Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo\n" + "metapost : John Hobby, Taco Hoekwater and friends.\n" + "poppler : Derek Noonburg, Kristian H\\ogsberg (partial)\n" + "fontforge : George Williams (partial)\n" + "luajit : Mike Pall (used in LuajitTeX)\n"); /* *INDENT-ON* */ puts(versions); uexit(0); @@ -556,8 +551,8 @@ static char *find_filename(char *name, const char *envkey) } filename = xmalloc((unsigned) (strlen(dirname) + strlen(name) + 2)); filename = concat3(dirname, "/", name); + xfree(dirname); if (is_readable(filename)) { - xfree(dirname); return filename; } xfree(filename); @@ -787,8 +782,8 @@ static void setup_lua_path(lua_State * L) @c int tex_table_id; int pdf_table_id; -int newtoken_table_id; int token_table_id; +int oldtoken_table_id; int node_table_id; @ @c @@ -798,7 +793,6 @@ int l_math_style_name_index [MATH_STYLE_NAME_SIZE]; int l_dir_par_index [DIR_PAR_SIZE]; int l_dir_text_index [DIR_TEXT_SIZE]; - #if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__) char **suffixlist; @@ -946,7 +940,7 @@ void lua_initialize(int ac, char **av) lua_settable(Luas,LUA_REGISTRYINDEX); /* here start the key definitions */ - set_pack_type_index; + set_l_pack_type_index; set_l_group_code_index; set_l_math_style_name_index; set_l_dir_par_index; @@ -957,15 +951,18 @@ void lua_initialize(int ac, char **av) if (startup_filename != NULL) { given_file = xstrdup(startup_filename); - startup_filename = find_filename(startup_filename, "LUATEXDIR"); + if (lua_only) { + xfree(startup_filename); + } + startup_filename = find_filename(given_file, "LUATEXDIR"); } /* now run the file */ if (startup_filename != NULL) { char *v1; /* hide the 'tex' and 'pdf' table */ tex_table_id = hide_lua_table(Luas, "tex"); - newtoken_table_id = hide_lua_table(Luas, "newtoken"); token_table_id = hide_lua_table(Luas, "token"); + oldtoken_table_id = hide_lua_table(Luas, "oldtoken"); node_table_id = hide_lua_table(Luas, "node"); pdf_table_id = hide_lua_table(Luas, "pdf"); @@ -997,8 +994,8 @@ void lua_initialize(int ac, char **av) /* unhide the 'tex' and 'pdf' table */ unhide_lua_table(Luas, "tex", tex_table_id); unhide_lua_table(Luas, "pdf", pdf_table_id); - unhide_lua_table(Luas, "newtoken", newtoken_table_id); unhide_lua_table(Luas, "token", token_table_id); + unhide_lua_table(Luas, "oldtoken", oldtoken_table_id); unhide_lua_table(Luas, "node", node_table_id); /* |kpse_init| */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w b/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w index 9ecd4d6d528..1305505fe2f 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w +++ b/Build/source/texk/web2c/luatexdir/lua/luajitstuff.w @@ -18,8 +18,6 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c - - #include "ptexlib.h" #include "lua/luatex-api.h" #include "lua/lauxlib_bridge.h" @@ -28,7 +26,6 @@ lua_State *Luas = NULL; int luastate_bytes = 0; - int lua_active = 0; @ @c @@ -57,8 +54,7 @@ void make_table(lua_State * L, const char *tab, const char *mttab, const char *g } @ @c -static -const char *getS(lua_State * L, void *ud, size_t * size) +static const char *getS(lua_State * L, void *ud, size_t * size) { LoadS *ls = (LoadS *) ud; (void) L; @@ -118,9 +114,6 @@ void luafunctioncall(int slot) lua_active--; } - - - @ @c static const luaL_Reg lualibs[] = { {"", luaopen_base}, @@ -143,12 +136,12 @@ static const luaL_Reg lualibs[] = { {"bit", luaopen_bit }, {NULL, NULL} }; + static const luaL_Reg lualibs_nofenv[] = { {"lpeg", luaopen_lpeg}, {NULL, NULL} }; - @ @c static void do_openlibs(lua_State * L) { @@ -220,29 +213,27 @@ static int luatex_dofile (lua_State *L) { return lua_gettop(L) - n; } - @ @c void luainterpreter(void) { lua_State *L; - + if (jithash_hashname==NULL){ - /* default lua51 */ + /* default lua51 */ luajittex_choose_hash_function = 0; jithash_hashname = (char *) xmalloc(strlen("lua51")+1); - jithash_hashname = strcpy ( jithash_hashname, "lua51"); + jithash_hashname = strcpy ( jithash_hashname, "lua51"); } else { if (strcmp((const char*)jithash_hashname,"lua51")==0){ luajittex_choose_hash_function = 0; }else if (strcmp((const char*)jithash_hashname,"luajit20")==0){ luajittex_choose_hash_function = 1; } else { - /* default lua51 */ + /* default lua51 */ luajittex_choose_hash_function = 0; - jithash_hashname = strcpy ( jithash_hashname, "lua51"); + jithash_hashname = strcpy ( jithash_hashname, "lua51"); } } - L = luaL_newstate() ; /*L = lua_newstate(my_luaalloc, NULL);*/ @@ -261,7 +252,6 @@ void luainterpreter(void) luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF); } - lua_pushcfunction(L,luatex_dofile); lua_setglobal(L, "dofile"); lua_pushcfunction(L,luatex_loadfile); @@ -311,8 +301,8 @@ void luainterpreter(void) /* our own libraries */ luaopen_ff(L); luaopen_tex(L); - luaopen_newtoken(L); luaopen_token(L); + luaopen_oldtoken(L); luaopen_node(L); luaopen_texio(L); luaopen_kpse(L); @@ -418,7 +408,6 @@ void unhide_lua_value(lua_State * L, const char *name, const char *item, int r) } } - @ @c int lua_traceback(lua_State * L) { @@ -514,7 +503,6 @@ static void luacall(int p, int nameptr, boolean is_string) /* hh-ls: optimized l lua_active--; } - @ @c void late_lua(PDF pdf, halfword p) { @@ -581,24 +569,23 @@ lua_State *luatex_error(lua_State * L, int is_fatal) const_lstring luaerr; char *err = NULL; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { luaerr.s = lua_tolstring(L, -1, &luaerr.l); + /* free last one ? */ err = (char *) xmalloc((unsigned) (luaerr.l + 1)); snprintf(err, (luaerr.l + 1), "%s", luaerr.s); - last_lua_error = err; + last_lua_error = err; /* hm, what if we have several .. not freed */ } if (is_fatal > 0) { /* Normally a memory error from lua. The pool may overflow during the |maketexlstring()|, but we are crashing anyway so we may as well abort on the pool size */ - lua_fatal_error(err); + normal_error("lua",err); /* never reached */ - xfree(err); lua_close(L); return (lua_State *) NULL; } else { - lua_norm_error(err); - /* last_lua_error = err so no need to xfree(err) */ + normal_warning("lua",err,true,true); return L; } } @@ -624,83 +611,77 @@ void preset_environment(lua_State * L, const parm_struct * p, const char *s) lua_settable(L, LUA_REGISTRYINDEX); /* - */ } - @ @c /* -int luaL_typerror (void *LL, int narg, const char *tname) -{ - lua_State *L = (lua_State *)LL; - const char *msg = lua_pushfstring(L, "%s expected, got %s", - tname, luaL_typename(L, narg)); - return luaL_argerror(L, narg, msg); -} + int luaL_typerror (void *LL, int narg, const char *tname) + { + lua_State *L = (lua_State *)LL; + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); + } */ - /* - - -Compatibility layer for luatex lua5.2 - + Compatibility layer for luatex lua5.2 */ - - @ @c LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { - void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - luaL_getmetatable(L, tname); /* get correct metatable */ - if (!lua_rawequal(L, -1, -2)) /* not the same? */ - p = NULL; /* value is a userdata with wrong metatable */ - lua_pop(L, 2); /* remove both metatables */ - return p; + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + luaL_getmetatable(L, tname); /* get correct metatable */ + if (!lua_rawequal(L, -1, -2)) /* not the same? */ + p = NULL; /* value is a userdata with wrong metatable */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } } - } - return NULL; /* value is not a userdata with a metatable */ + return NULL; /* value is not a userdata with a metatable */ } @ @c + /* It's not ok. See lua-users.org/wiki/CompatibilityWithLuaFive for another solution */ + LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { - /*luaL_checkversion(L);*/ - luaL_checkstack(L, nup, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - int i; - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -nup); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ - lua_setfield(L, -(nup + 2), l->name); - } - lua_pop(L, nup); /* remove upvalues */ + /*luaL_checkversion(L);*/ + luaL_checkstack(L, nup, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_setfield(L, -(nup + 2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ } - @ @c LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { - lua_State *L = B->L; - if (sz > LUAL_BUFFERSIZE ) - luaL_error(L, "buffer too large"); - return luaL_prepbuffer(B) ; + lua_State *L = B->L; + if (sz > LUAL_BUFFERSIZE ) + luaL_error(L, "buffer too large"); + return luaL_prepbuffer(B) ; } @ @c LUA_API int lua_compare (lua_State *L, int o1, int o2, int op) { - /*StkId o1, o2;*/ - int i = 0; - lua_lock(L); /* may call tag method */ - /* o1 = index2addr(L, index1); */ - /* o2 = index2addr(L, index2); */ - /*if (isvalid(o1) && isvalid(o2)) {*/ + /*StkId o1, o2;*/ + int i = 0; + lua_lock(L); /* may call tag method */ + /* o1 = index2addr(L, index1); */ + /* o2 = index2addr(L, index2); */ + /*if (isvalid(o1) && isvalid(o2)) {*/ switch (op) { - case LUA_OPEQ: i = lua_equal(L, o1, o2); break; - case LUA_OPLT: i = lua_lessthan(L, o1, o2); break; - case LUA_OPLE: i = (lua_lessthan(L, o1, o2) || lua_equal(L, o1, o2)) ; break; - default: luaL_error(L, "invalid option"); + case LUA_OPEQ: i = lua_equal(L, o1, o2); break; + case LUA_OPLT: i = lua_lessthan(L, o1, o2); break; + case LUA_OPLE: i = (lua_lessthan(L, o1, o2) || lua_equal(L, o1, o2)) ; break; + default: luaL_error(L, "invalid option"); } - /*}*/ - lua_unlock(L); - return i; + /*}*/ + lua_unlock(L); + return i; } diff --git a/Build/source/texk/web2c/luatexdir/lua/luanode.w b/Build/source/texk/web2c/luatexdir/lua/luanode.w index a9da3cb1c34..c1da8f2d1ca 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luanode.w +++ b/Build/source/texk/web2c/luatexdir/lua/luanode.w @@ -18,47 +18,15 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. /* hh-ls: we make sure that lua never sees prev of head but also that when -nodes are removedor inserted, temp nodes don't interfere */ +nodes are removed or inserted, temp nodes don't interfere */ @ @c - #include "ptexlib.h" #include "lua/luatex-api.h" -/* TO BE REMOVED -static const char *group_code_names[] = { - "", - "simple", - "hbox", - "adjusted_hbox", - "vbox", - "vtop", - "align", - "no_align", - "output", - "math", - "disc", - "insert", - "vcenter", - "math_choice", - "semi_simple", - "math_shift", - "math_left", - "local_box", - "split_off", - "split_keep", - "preamble", - "align_set", - "fin_row" -}; - -const char *pack_type_name[] = { "exactly", "additional" }; -*/ - @ @c -void -lua_node_filter_s(int filterid, int extrainfo) +void lua_node_filter_s(int filterid, int extrainfo) { lua_State *L = Luas; int callback_id = callback_defined(filterid); @@ -82,10 +50,8 @@ lua_node_filter_s(int filterid, int extrainfo) return; } - @ @c -void -lua_node_filter(int filterid, int extrainfo, halfword head_node, halfword * tail_node) +void lua_node_filter(int filterid, int extrainfo, halfword head_node, halfword * tail_node) { halfword ret; int a; @@ -134,8 +100,7 @@ lua_node_filter(int filterid, int extrainfo, halfword head_node, halfword * tail } @ @c -int -lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) +int lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) { int a; register halfword *p; @@ -160,7 +125,6 @@ lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) error(); return ret; } - p = lua_touserdata(L, -1); if (p != NULL) { a = nodelist_from_lua(L); @@ -171,12 +135,48 @@ lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) return ret; } - +@ @c +int lua_appendtovlist_callback(halfword box, int location, halfword prev_depth, boolean is_mirrored, halfword * result, int * next_depth, boolean * prev_set) +{ + register halfword *p; + lua_State *L = Luas; + int s_top = lua_gettop(L); + int callback_id = callback_defined(append_to_vlist_filter_callback); + if (box == null || callback_id <= 0) { + lua_settop(L, s_top); + return 0; + } + if (!get_callback(L, callback_id)) { + lua_settop(L, s_top); + return 0; + } + nodelist_to_lua(L, box); + lua_push_string_by_index(L,location); + lua_pushnumber(L, (int) prev_depth); + lua_pushboolean(L, is_mirrored); + if (lua_pcall(L, 4, 2, 0) != 0) { + fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); + lua_settop(L, s_top); + error(); + return 0; + } + if (lua_type(L,-1) == LUA_TNUMBER) { + *next_depth = lua_tonumber(L,-1); + *prev_set = true; + if (lua_type(L, -2) != LUA_TNIL) { + p = check_isnode(L, -2); + *result = *p; + } + } else if (lua_type(L, -1) != LUA_TNIL) { + p = check_isnode(L, -1); + *result = *p; + } + lua_settop(L, s_top); + return 1; +} @ @c -halfword -lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, - int pack_direction) +halfword lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, int pack_direction) { halfword ret; lua_State *L = Luas; @@ -224,8 +224,7 @@ lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, } @ @c -halfword -lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, +halfword lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, int extrainfo, int pack_direction) { halfword ret; @@ -283,7 +282,6 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, return ret; } - @ This is a quick hack to fix etex's \.{\\lastnodetype} now that there are many more visible node types. TODO: check the eTeX manual for the expected return values. @@ -292,20 +290,12 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, int visible_last_node_type(int n) { int i = type(n); - if (i == whatsit_node && subtype(n) == local_par_node) - return -1; - if (i == glyph_node) { - if (is_ligature(n)) - return 7; /* old ligature value */ - else - return 0; /* old character value */ - } - if (i <= unset_node) { - return i + 1; - } else if (i <= delim_node) { - return 15; /* so-called math nodes */ + if (i != glyph_node) { + return get_etex_code(i); + } else if (is_ligature(n)) { + return 7; /* old ligature value */ } else { - return -1; + return 0; /* old character value */ } } @@ -359,7 +349,6 @@ void copy_user_lua(pointer r, pointer p) } } - @ @c void free_pdf_literal(pointer p) { @@ -389,7 +378,6 @@ void free_user_lua(pointer p) } } - @ @c void show_pdf_literal(pointer p) { diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.w b/Build/source/texk/web2c/luatexdir/lua/luastuff.w index d247bb882b0..2ac671ae7a7 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luastuff.w +++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.w @@ -18,8 +18,6 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c - - #include "ptexlib.h" #include "lua/luatex-api.h" @@ -27,7 +25,6 @@ lua_State *Luas = NULL; int luastate_bytes = 0; - int lua_active = 0; @ @c @@ -56,8 +53,7 @@ void make_table(lua_State * L, const char *tab, const char *mttab, const char *g } @ @c -static -const char *getS(lua_State * L, void *ud, size_t * size) +static const char *getS(lua_State * L, void *ud, size_t * size) { LoadS *ls = (LoadS *) ud; (void) L; @@ -85,12 +81,10 @@ static void *my_luaalloc(void *ud, void *ptr, size_t osize, size_t nsize) static int my_luapanic(lua_State * L) { (void) L; /* to avoid warnings */ - fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", - lua_tostring(L, -1)); + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1)); return 0; } - @ @c void luafunctioncall(int slot) { @@ -116,10 +110,6 @@ void luafunctioncall(int slot) lua_active--; } - - - - @ @c static const luaL_Reg lualibs[] = { {"", luaopen_base}, @@ -141,7 +131,6 @@ static const luaL_Reg lualibs[] = { {NULL, NULL} }; - @ @c static void do_openlibs(lua_State * L) { @@ -204,7 +193,6 @@ static int luatex_dofile (lua_State *L) { return lua_gettop(L) - n; } - @ @c void luainterpreter(void) { @@ -267,8 +255,8 @@ void luainterpreter(void) /* our own libraries */ luaopen_ff(L); luaopen_tex(L); + luaopen_oldtoken(L); luaopen_token(L); - luaopen_newtoken(L); luaopen_node(L); luaopen_texio(L); luaopen_kpse(L); @@ -368,10 +356,9 @@ void unhide_lua_value(lua_State * L, const char *name, const char *item, int r) } } - @ @c int lua_traceback(lua_State * L) -{ +{ lua_getglobal(L, "debug"); if (!lua_istable(L, -1)) { lua_pop(L, 1); @@ -464,8 +451,6 @@ static void luacall(int p, int nameptr, boolean is_string) /* hh-ls: optimized l lua_active--; } - - @ @c void late_lua(PDF pdf, halfword p) { @@ -532,24 +517,23 @@ lua_State *luatex_error(lua_State * L, int is_fatal) const_lstring luaerr; char *err = NULL; - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { luaerr.s = lua_tolstring(L, -1, &luaerr.l); + /* free last one ? */ err = (char *) xmalloc((unsigned) (luaerr.l + 1)); snprintf(err, (luaerr.l + 1), "%s", luaerr.s); - last_lua_error = err; + last_lua_error = err; /* hm, what if we have several .. not freed */ } if (is_fatal > 0) { /* Normally a memory error from lua. The pool may overflow during the |maketexlstring()|, but we are crashing anyway so we may as well abort on the pool size */ - lua_fatal_error(err); + normal_error("lua",err); /* never reached */ - xfree(err); lua_close(L); return (lua_State *) NULL; } else { - lua_norm_error(err); - /* last_lua_error = err so no need to xfree(err) */ + normal_warning("lua",err,true,true); return L; } } diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h index 3dff78d9b3c..8c99cf72519 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h +++ b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h @@ -17,10 +17,29 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ - #ifndef LUATEX_API_H # define LUATEX_API_H 1 +/* output modes, a bad place but this compiles at least */ + +typedef enum { OMODE_NONE, OMODE_DVI, OMODE_PDF } output_mode ; + +# define MAX_OMODE 2 /* largest index in enum output_mode */ + +extern int output_mode_used; +extern int output_mode_option; +extern int output_mode_value; +extern int draft_mode_option; +extern int draft_mode_value; + +/* get_o_mode translates from output_mode to output_mode_used */ +/* fix_o_mode freezes output_mode as soon as anything goes through the backend */ + +extern output_mode get_o_mode(void); +extern void fix_o_mode(void); + +/* till here */ + # include <stdlib.h> # include <stdio.h> # include <stdarg.h> @@ -53,15 +72,12 @@ extern void make_table(lua_State * L, const char *tab, const char *mttab, const extern int luac_main(int argc, char *argv[]); extern int luaopen_tex(lua_State * L); - extern int luaopen_pdf(lua_State * L); - -# define LUA_TEXFILEHANDLE "TEXFILE*" - extern int luaopen_texio(lua_State * L); - extern int luaopen_lang(lua_State * L); +# define LUA_TEXFILEHANDLE "TEXFILE*" + extern lua_State *luatex_error(lua_State * L, int fatal); extern int luaopen_unicode(lua_State * L); @@ -112,14 +128,15 @@ extern int luaopen_vf(lua_State * L); extern int font_to_lua(lua_State * L, int f); extern int font_from_lua(lua_State * L, int f); /* return is boolean */ +extern int luaopen_oldtoken(lua_State * L); extern int luaopen_token(lua_State * L); -extern int luaopen_newtoken(lua_State * L); extern void tokenlist_to_lua(lua_State * L, int p); extern void tokenlist_to_luastring(lua_State * L, int p); extern int tokenlist_from_lua(lua_State * L); extern void lua_nodelib_push(lua_State * L); extern int nodelib_getdir(lua_State * L, int n, int absolute_only); +extern int nodelib_getlist(lua_State * L, int n); extern int luaopen_node(lua_State * L); extern void nodelist_to_lua(lua_State * L, int n); @@ -172,9 +189,6 @@ extern int saved_callback_count; extern const char *luatex_banner; -extern const char *last_lua_error; - - /* luastuff.h */ typedef struct { @@ -182,8 +196,7 @@ typedef struct { int idx; /* index within img_parms array */ } parm_struct; -extern void preset_environment(lua_State * L, const parm_struct * p, - const char *s); +extern void preset_environment(lua_State * L, const parm_struct * p, const char *s); extern char *startup_filename; extern int safer_option; @@ -198,17 +211,15 @@ extern int program_name_set; /* in lkpselib.c */ extern char **argv; extern int argc; -extern int loader_C_luatex(lua_State * L, const char *name, - const char *filename); -extern int loader_Call_luatex(lua_State * L, const char *name, - const char *filename); +extern int loader_C_luatex(lua_State * L, const char *name, const char *filename); +extern int loader_Call_luatex(lua_State * L, const char *name, const char *filename); extern void init_tex_table(lua_State * L); extern int tex_table_id; extern int pdf_table_id; -extern int newtoken_table_id; extern int token_table_id; +extern int oldtoken_table_id; extern int node_table_id; extern int main_initialize(void); @@ -217,7 +228,6 @@ extern int lua_traceback(lua_State * L); extern int luainit; - extern char *luanames[]; extern int ff_get_ttc_index(char *ffname, char *psname); /* luafontloader/src/luafflib.c */ @@ -242,27 +252,22 @@ extern char **environ; */ -/*#define init_luaS_index(a) do { */ #define init_lua_key(a) do { \ lua_pushliteral(Luas,#a); \ luaS_##a##_ptr = lua_tostring(Luas,-1); \ luaS_##a##_index = luaL_ref (Luas,LUA_REGISTRYINDEX); \ } while (0) - /*#define init_luaS_index_s(a,b) do { */ #define init_lua_key_alias(a,b) do { \ lua_pushliteral(Luas,b); \ luaS_##a##_ptr = lua_tostring(Luas,-1); \ luaS_##a##_index = luaL_ref (Luas,LUA_REGISTRYINDEX); \ } while (0) - /*#define make_luaS_index(a) */ #define make_lua_key(a) \ int luaS_##a##_index = 0; \ const char * luaS_##a##_ptr = NULL - -/*#define luaS_ptr_eq(a,b) (a==luaS_##b##_ptr)*/ #define lua_key_eq(a,b) (a==luaS_##b##_ptr) #define luaS_index(a) luaS_##a##_index @@ -272,7 +277,6 @@ extern char **environ; extern int luaS_##a##_index ; \ extern const char * luaS_##a##_ptr - #define lua_key_rawgeti(a) \ lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_##a##_index);\ lua_rawget(L, -2) @@ -282,9 +286,9 @@ extern char **environ; lua_rawget(L, -1+n) /* -Unfortunately floor is already redefined as +Unfortunately floor is already redefined as #define floor ((integer)floor((double)(a))) -so +so #define lua_uroundnumber(a,b) (unsigned int)floor((double)(lua_tonumber(a,b)+0.5)) is useless. */ @@ -294,7 +298,6 @@ is useless. extern int lua_numeric_field_by_index(lua_State *, int , int); extern unsigned int lua_unsigned_numeric_field_by_index(lua_State *, int , int); - /* Currently we sometimes use numbers and sometimes strings in node properties. We can make that consistent by having a check on number and if not then assign a string. The strings are prehashed and we make a bunch of lua tables that have these values. We can @@ -305,27 +308,26 @@ preassign these at startup time. */ #define PACK_TYPE_SIZE 4 #define GROUP_CODE_SIZE 23 #define MATH_STYLE_NAME_SIZE 8 -#define DIR_PAR_SIZE 128 -#define DIR_TEXT_SIZE 128 +#define APPEND_LIST_SIZE 5 +#define DIR_PAR_SIZE 8 +#define DIR_TEXT_SIZE 8 -extern int l_pack_type_index [PACK_TYPE_SIZE] ; +extern int l_pack_type_index [PACK_TYPE_SIZE]; extern int l_group_code_index [GROUP_CODE_SIZE]; extern int l_math_style_name_index [MATH_STYLE_NAME_SIZE]; extern int l_dir_par_index [DIR_PAR_SIZE]; extern int l_dir_text_index [DIR_TEXT_SIZE]; -#define lua_push_pack_type(L,pack_type) lua_rawgeti(L, LUA_REGISTRYINDEX, l_pack_type_index [pack_type] ); -#define lua_push_group_code(L,group_code) lua_rawgeti(L, LUA_REGISTRYINDEX, l_group_code_index [group_code]); +#define lua_push_pack_type(L,pack_type) lua_rawgeti(L, LUA_REGISTRYINDEX, l_pack_type_index[pack_type] ); +#define lua_push_group_code(L,group_code) lua_rawgeti(L, LUA_REGISTRYINDEX, l_group_code_index[group_code]); #define lua_push_math_style_name(L,style_name) lua_rawgeti(L, LUA_REGISTRYINDEX, l_math_style_name_index[style_name]); -#define lua_push_dir_par(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_par_index[dir+64]) -#define lua_push_dir_text(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_text_index[dir+64]) - +#define lua_push_dir_par(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_par_index[dir+dir_swap]) +#define lua_push_dir_text(L,dir) lua_rawgeti(L, LUA_REGISTRYINDEX, l_dir_text_index[dir+dir_swap]) #define lua_push_string_by_index(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, index) #define lua_push_string_by_name(L,index) lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(index)) - -#define set_pack_type_index \ +#define set_l_pack_type_index \ l_pack_type_index[0] = lua_key_index(exactly); \ l_pack_type_index[1] = lua_key_index(additional); \ l_pack_type_index[2] = lua_key_index(cal_expand_ratio);\ @@ -368,24 +370,23 @@ l_math_style_name_index[7] = lua_key_index(crampedscriptscript) #define set_l_dir_par_index \ l_dir_par_index[0] = lua_key_index(TLT);\ -l_dir_par_index[4] = lua_key_index(TRT);\ -l_dir_par_index[9] = lua_key_index(LTL);\ -l_dir_par_index[24] = lua_key_index(RTT);\ -l_dir_par_index[64] = lua_key_index(TLT);\ -l_dir_par_index[68] = lua_key_index(TRT);\ -l_dir_par_index[73] = lua_key_index(LTL);\ -l_dir_par_index[88] = lua_key_index(RTT);\ +l_dir_par_index[1] = lua_key_index(TRT);\ +l_dir_par_index[2] = lua_key_index(LTL);\ +l_dir_par_index[3] = lua_key_index(RTT);\ +l_dir_par_index[4] = lua_key_index(TLT);\ +l_dir_par_index[5] = lua_key_index(TRT);\ +l_dir_par_index[6] = lua_key_index(LTL);\ +l_dir_par_index[7] = lua_key_index(RTT);\ #define set_l_dir_text_index \ l_dir_text_index[0] = lua_key_index(mTLT);\ -l_dir_text_index[4] = lua_key_index(mTRT);\ -l_dir_text_index[9] = lua_key_index(mLTL);\ -l_dir_text_index[24] = lua_key_index(mRTT);\ -l_dir_text_index[64] = lua_key_index(pTLT);\ -l_dir_text_index[68] = lua_key_index(pTRT);\ -l_dir_text_index[73] = lua_key_index(pLTL);\ -l_dir_text_index[88] = lua_key_index(pRTT);\ - +l_dir_text_index[1] = lua_key_index(mTRT);\ +l_dir_text_index[2] = lua_key_index(mLTL);\ +l_dir_text_index[3] = lua_key_index(mRTT);\ +l_dir_text_index[4] = lua_key_index(pTLT);\ +l_dir_text_index[5] = lua_key_index(pTRT);\ +l_dir_text_index[6] = lua_key_index(pLTL);\ +l_dir_text_index[7] = lua_key_index(pRTT);\ #define set_make_keys \ make_lua_key(cmdname);make_lua_key(expandable);make_lua_key(protected);\ @@ -476,6 +477,8 @@ make_lua_key(encodingbytes);\ make_lua_key(encodingname);\ make_lua_key(end);\ make_lua_key(etex);\ +make_lua_key(equation);\ +make_lua_key(equation_number);\ make_lua_key(exactly);\ make_lua_key(expansion_factor);\ make_lua_key(ext);\ @@ -485,14 +488,17 @@ make_lua_key(extensible);\ make_lua_key(extra_space);\ make_lua_key(fam);\ make_lua_key(fast);\ +make_lua_key(fence);\ make_lua_key(file);\ make_lua_key(filename);\ +make_lua_key(fill);\ make_lua_key(fin_row);\ make_lua_key(font);\ make_lua_key(fonts);\ make_lua_key(format);\ make_lua_key(fullname);\ make_lua_key(global);\ +make_lua_key(glue);\ make_lua_key(glue_order);\ make_lua_key(glue_set);\ make_lua_key(glue_sign);\ @@ -532,12 +538,14 @@ make_lua_key(log);\ make_lua_key(lua);\ make_lua_key(lua_functions);\ make_lua_key(luatex);\ -make_lua_key(luatex_newtoken);\ make_lua_key(luatex_node);\ +make_lua_key(luatex_oldtoken);\ +make_lua_key(luatex_token);\ make_lua_key(mLTL);\ make_lua_key(mRTT);\ make_lua_key(mTLT);\ make_lua_key(mTRT);\ +make_lua_key(marginkern);\ make_lua_key(mark);\ make_lua_key(math);\ make_lua_key(math_choice);\ @@ -568,8 +576,11 @@ make_lua_key(num);\ make_lua_key(number);\ make_lua_key(objcompression);\ make_lua_key(objnum);\ +make_lua_key(oldmath);\ make_lua_key(ordering);\ +make_lua_key(origin);\ make_lua_key(output);\ +make_lua_key(overlay_accent);\ make_lua_key(pLTL);\ make_lua_key(pRTT);\ make_lua_key(pTLT);\ @@ -583,11 +594,14 @@ make_lua_key(pagesattributes);\ make_lua_key(parameters);\ make_lua_key(pdf_data);\ make_lua_key(pdftex);\ +make_lua_key(pdf_destination);\ +make_lua_key(pdf_literal);\ make_lua_key(pen_broken);\ make_lua_key(pen_inter);\ make_lua_key(penalty);\ make_lua_key(pop);\ make_lua_key(post);\ +make_lua_key(post_linebreak);\ make_lua_key(pre);\ make_lua_key(pre_adjust);\ make_lua_key(pre_adjust_head);\ @@ -601,6 +615,7 @@ make_lua_key(psname);\ make_lua_key(ptr);\ make_lua_key(push);\ make_lua_key(quad);\ +make_lua_key(radical);\ make_lua_key(raw);\ make_lua_key(ref_count);\ make_lua_key(reg);\ @@ -608,6 +623,7 @@ make_lua_key(registry);\ make_lua_key(renew);\ make_lua_key(rep);\ make_lua_key(replace);\ +make_lua_key(resources);\ make_lua_key(right);\ make_lua_key(right_boundary);\ make_lua_key(right_protruding);\ @@ -677,17 +693,19 @@ make_lua_key(value);\ make_lua_key(vbox);\ make_lua_key(vcenter);\ make_lua_key(version);\ +make_lua_key(vert_italic);\ make_lua_key(vert_variants);\ make_lua_key(vmode_par);\ make_lua_key(vtop);\ make_lua_key(width);\ make_lua_key(writable);\ make_lua_key(x_height);\ +make_lua_key(xformresources);\ +make_lua_key(xformattributes);\ make_lua_key(xoffset);\ make_lua_key(xyz_zoom);\ make_lua_key(yoffset) - #define set_init_keys \ init_lua_key(cmdname);init_lua_key(expandable);init_lua_key(protected);\ init_lua_key(LTL);\ @@ -776,6 +794,8 @@ init_lua_key(encodingbytes);\ init_lua_key(encodingname);\ init_lua_key(end);\ init_lua_key(etex);\ +init_lua_key(equation);\ +init_lua_key(equation_number);\ init_lua_key(exactly);\ init_lua_key(expansion_factor);\ init_lua_key(ext);\ @@ -785,14 +805,17 @@ init_lua_key(extensible);\ init_lua_key(extra_space);\ init_lua_key(fam);\ init_lua_key(fast);\ +init_lua_key(fence);\ init_lua_key(file);\ init_lua_key(filename);\ +init_lua_key(fill);\ init_lua_key(fin_row);\ init_lua_key(font);\ init_lua_key(fonts);\ init_lua_key(format);\ init_lua_key(fullname);\ init_lua_key(global);\ +init_lua_key(glue);\ init_lua_key(glue_order);\ init_lua_key(glue_set);\ init_lua_key(glue_sign);\ @@ -830,8 +853,12 @@ init_lua_key(list);\ init_lua_key(local_box);\ init_lua_key(log);\ init_lua_key(lua);\ +init_lua_key(lua_functions);\ init_lua_key(luatex);\ -init_lua_key(luatex_newtoken);\ +init_lua_key(luatex_node);\ +init_lua_key(luatex_oldtoken);\ +init_lua_key(luatex_token);\ +init_lua_key(marginkern);\ init_lua_key(mark);\ init_lua_key(math);\ init_lua_key(math_choice);\ @@ -860,8 +887,11 @@ init_lua_key(num);\ init_lua_key(number);\ init_lua_key(objcompression);\ init_lua_key(objnum);\ +init_lua_key(oldmath);\ +init_lua_key(origin);\ init_lua_key(ordering);\ init_lua_key(output);\ +init_lua_key(overlay_accent);\ init_lua_key(page);\ init_lua_key(page_head);\ init_lua_key(page_ins_head);\ @@ -870,11 +900,14 @@ init_lua_key(pageresources);\ init_lua_key(pagesattributes);\ init_lua_key(parameters);\ init_lua_key(pdftex);\ +init_lua_key(pdf_destination);\ +init_lua_key(pdf_literal);\ init_lua_key(pen_broken);\ init_lua_key(pen_inter);\ init_lua_key(penalty);\ init_lua_key(pop);\ init_lua_key(post);\ +init_lua_key(post_linebreak);\ init_lua_key(pre);\ init_lua_key(pre_adjust);\ init_lua_key(pre_adjust_head);\ @@ -888,6 +921,7 @@ init_lua_key(psname);\ init_lua_key(ptr);\ init_lua_key(push);\ init_lua_key(quad);\ +init_lua_key(radical);\ init_lua_key(raw);\ init_lua_key(ref_count);\ init_lua_key(reg);\ @@ -895,6 +929,7 @@ init_lua_key(registry);\ init_lua_key(renew);\ init_lua_key(rep);\ init_lua_key(replace);\ +init_lua_key(resources);\ init_lua_key(right);\ init_lua_key(right_boundary);\ init_lua_key(right_protruding);\ @@ -963,12 +998,15 @@ init_lua_key(value);\ init_lua_key(vbox);\ init_lua_key(vcenter);\ init_lua_key(version);\ +init_lua_key(vert_italic);\ init_lua_key(vert_variants);\ init_lua_key(vmode_par);\ init_lua_key(vtop);\ init_lua_key(width);\ init_lua_key(writable);\ init_lua_key(x_height);\ +init_lua_key(xformresources);\ +init_lua_key(xformattributes);\ init_lua_key(xoffset);\ init_lua_key(xyz_zoom);\ init_lua_key(yoffset);\ @@ -988,12 +1026,11 @@ init_lua_key_alias(pTRT,"+TRT");\ init_lua_key_alias(pdf_data,"pdf.data");\ init_lua_key_alias(term_and_log,"term and log") - #define assign_math_style(L,n,target) do { \ - if (lua_isnumber(L,n)) { \ + if (lua_type(L,n) == LUA_TNUMBER) { \ /* new, often same as subtype anyway */ \ target = lua_tonumber(L,n); \ - } else if (lua_isstring(L,n)) { \ + } else if (lua_type(L,n) == LUA_TSTRING) { \ const char *s = lua_tostring(L, n); \ if (lua_key_eq(s,display)) { \ target = 0; \ @@ -1019,40 +1056,17 @@ init_lua_key_alias(term_and_log,"term and log") } \ } while(0) - - - #ifdef __MINGW32__ extern FILE *_cairo_win32_tmpfile( void ); #define tmpfile() _cairo_win32_tmpfile() #endif /* __MINGW32__ */ - - -/* -* experimental code (no primitive): - - 0 = all - 1 = retain math nodes - -*/ - -#define max_experimental_code 1 -#define MAX_EXPERIMENTAL_CODE_SIZE max_experimental_code+1 -/* to be indexed by i with 1<= i <=max_experimental_code */ -extern int experimental_code[MAX_EXPERIMENTAL_CODE_SIZE] ; - - #endif /* LUATEX_API_H */ - - - /* */ /* These keys have to available to different files */ /* */ - use_lua_key(cmdname);use_lua_key(expandable);use_lua_key(protected); use_lua_key(LTL); @@ -1142,6 +1156,8 @@ use_lua_key(encodingbytes); use_lua_key(encodingname); use_lua_key(end); use_lua_key(etex); +use_lua_key(equation);\ +use_lua_key(equation_number);\ use_lua_key(exactly); use_lua_key(expansion_factor); use_lua_key(ext); @@ -1151,14 +1167,17 @@ use_lua_key(extensible); use_lua_key(extra_space); use_lua_key(fam); use_lua_key(fast); +use_lua_key(fence); use_lua_key(file); use_lua_key(filename); +use_lua_key(fill); use_lua_key(fin_row); use_lua_key(font); use_lua_key(fonts); use_lua_key(format); use_lua_key(fullname); use_lua_key(global); +use_lua_key(glue); use_lua_key(glue_order); use_lua_key(glue_set); use_lua_key(glue_sign); @@ -1198,12 +1217,14 @@ use_lua_key(log); use_lua_key(lua); use_lua_key(lua_functions); use_lua_key(luatex); -use_lua_key(luatex_newtoken); use_lua_key(luatex_node); +use_lua_key(luatex_oldtoken); +use_lua_key(luatex_token); use_lua_key(mLTL); use_lua_key(mRTT); use_lua_key(mTLT); use_lua_key(mTRT); +use_lua_key(marginkern); use_lua_key(mark); use_lua_key(math); use_lua_key(math_choice); @@ -1234,8 +1255,11 @@ use_lua_key(num); use_lua_key(number); use_lua_key(objcompression); use_lua_key(objnum); +use_lua_key(oldmath); +use_lua_key(origin); use_lua_key(ordering); use_lua_key(output); +use_lua_key(overlay_accent); use_lua_key(pLTL); use_lua_key(pRTT); use_lua_key(pTLT); @@ -1249,11 +1273,14 @@ use_lua_key(pagesattributes); use_lua_key(parameters); use_lua_key(pdf_data); use_lua_key(pdftex); +use_lua_key(pdf_destination);\ +use_lua_key(pdf_literal);\ use_lua_key(pen_broken); use_lua_key(pen_inter); use_lua_key(penalty); use_lua_key(pop); use_lua_key(post); +use_lua_key(post_linebreak); use_lua_key(pre); use_lua_key(pre_adjust); use_lua_key(pre_adjust_head); @@ -1267,6 +1294,7 @@ use_lua_key(psname); use_lua_key(ptr); use_lua_key(push); use_lua_key(quad); +use_lua_key(radical); use_lua_key(raw); use_lua_key(ref_count); use_lua_key(reg); @@ -1274,6 +1302,7 @@ use_lua_key(registry); use_lua_key(renew); use_lua_key(rep); use_lua_key(replace); +use_lua_key(resources); use_lua_key(right); use_lua_key(right_boundary); use_lua_key(right_protruding); @@ -1343,12 +1372,15 @@ use_lua_key(value); use_lua_key(vbox); use_lua_key(vcenter); use_lua_key(version); +use_lua_key(vert_italic); use_lua_key(vert_variants); use_lua_key(vmode_par); use_lua_key(vtop); use_lua_key(width); use_lua_key(writable); use_lua_key(x_height); +use_lua_key(xformresources); +use_lua_key(xformattributes); use_lua_key(xoffset); use_lua_key(xyz_zoom); use_lua_key(yoffset); diff --git a/Build/source/texk/web2c/luatexdir/lua/luatoken.w b/Build/source/texk/web2c/luatexdir/lua/luatoken.w index cf91a6f7bf8..f0ff08eec54 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatoken.w +++ b/Build/source/texk/web2c/luatexdir/lua/luatoken.w @@ -19,7 +19,6 @@ @ @c - #include "ptexlib.h" #include "lua/luatex-api.h" @@ -60,6 +59,8 @@ command_item command_names[] = { {"halign", halign_cmd, NULL}, {"valign", valign_cmd, NULL}, {"no_align", no_align_cmd, NULL}, + {"novrule", no_vrule_cmd, NULL}, + {"nohrule", no_hrule_cmd, NULL}, {"vrule", vrule_cmd, NULL}, {"hrule", hrule_cmd, NULL}, {"insert", insert_cmd, NULL}, @@ -84,12 +85,15 @@ command_item command_names[] = { {"vcenter", vcenter_cmd, NULL}, {"case_shift", case_shift_cmd, NULL}, {"message", message_cmd, NULL}, + {"normal", normal_cmd, NULL}, {"extension", extension_cmd, NULL}, + {"option", option_cmd, NULL}, {"in_stream", in_stream_cmd, NULL}, {"begin_group", begin_group_cmd, NULL}, {"end_group", end_group_cmd, NULL}, {"omit", omit_cmd, NULL}, {"ex_space", ex_space_cmd, NULL}, + {"boundary", boundary_cmd, NULL}, {"no_boundary", no_boundary_cmd, NULL}, {"radical", radical_cmd, NULL}, {"super_sub_script", super_sub_script_cmd, NULL}, @@ -140,7 +144,9 @@ command_item command_names[] = { {"hyph_data", hyph_data_cmd, NULL}, {"set_interaction", set_interaction_cmd, NULL}, {"letterspace_font", letterspace_font_cmd, NULL}, - {"pdf_copy_font", pdf_copy_font_cmd, NULL}, + {"expand_font",expand_font_cmd, NULL}, + {"copy_font", copy_font_cmd, NULL}, + {"set_font_id", set_font_id_cmd, NULL}, {"undefined_cs", undefined_cs_cmd, NULL}, {"expand_after", expand_after_cmd, NULL}, {"no_expand", no_expand_cmd, NULL}, @@ -243,7 +249,7 @@ static int get_cur_cs(lua_State * L) ret = 0; cur_cs = 0; lua_getfield(L, -1, "name"); - if (lua_isstring(L, -1)) { + if (lua_type(L, -1) == LUA_TSTRING) { s = lua_tolstring(L, -1, &l); if (l > 0) { if ((last + (int) l) > buf_size) @@ -301,7 +307,7 @@ void tokenlist_to_luastring(lua_State * L, int p) char *s; s = tokenlist_to_cstring(p, 1, &l); lua_pushlstring(L, s, (size_t) l); - free(s); + free(s); } @@ -309,14 +315,15 @@ void tokenlist_to_luastring(lua_State * L, int p) int tokenlist_from_lua(lua_State * L) { const char *s; - int tok; + int tok, t; size_t i, j; halfword p, q, r; r = get_avail(); token_info(r) = 0; /* ref count */ token_link(r) = null; p = r; - if (lua_istable(L, -1)) { + t = lua_type(L, -1); + if (t == LUA_TTABLE) { j = lua_rawlen(L, -1); if (j > 0) { for (i = 1; i <= j; i++) { @@ -329,7 +336,7 @@ int tokenlist_from_lua(lua_State * L) }; } return r; - } else if (lua_isstring(L, -1)) { + } else if (t == LUA_TSTRING) { s = lua_tolstring(L, -1, &j); for (i = 0; i < j; i++) { if (s[i] == 32) { |