diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/lnodelib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/lnodelib.c | 220 |
1 files changed, 149 insertions, 71 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c index ba623572641..4f98dc19526 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c @@ -96,7 +96,7 @@ */ static const char _svn_version[] = - "$Id: lnodelib.c 4847 2014-03-05 18:13:17Z luigi $ " + "$Id: lnodelib.c 4956 2014-03-28 12:12:17Z luigi $ " "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lnodelib.c $"; #include "ptexlib.h" @@ -1467,10 +1467,10 @@ static int lua_nodelib_hpack(lua_State * L) if (lua_gettop(L) > 2) { if (lua_type(L, 3) == LUA_TSTRING) { s = lua_tostring(L, 3); - if (lua_key_eq(s, additional)) { - m = 1; - } else if (lua_key_eq(s, exactly)) { + if (lua_key_eq(s, exactly)) { m = 0; + } else if (lua_key_eq(s, additional)) { + m = 1; } else if (lua_key_eq(s, cal_expand_ratio)) { m = 2; } else if (lua_key_eq(s, subst_ex_font)) { @@ -1732,7 +1732,8 @@ static int lua_nodelib_mlist_to_hlist(lua_State * L) int w; boolean m; n = *(check_isnode(L, 1)); - w = luaL_checkoption(L, 2, "text", math_style_names); + //w = luaL_checkoption(L, 2, "text", math_style_names); + assign_math_style(L,2,w); luaL_checkany(L, 3); m = lua_toboolean(L, 3); mlist_to_hlist_args(n, w, m); @@ -1877,22 +1878,26 @@ static int lua_nodelib_fields(lua_State * L) } lua_checkstack(L, 2); lua_newtable(L); - lua_pushstring(L, "next"); /* next, id, subtype, prev could be predefined string */ + // lua_pushstring(L, "next"); + lua_push_string_by_name(L,next); lua_rawseti(L, -2, 0); - lua_pushstring(L, "id"); + // 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_rawseti(L, -2, 2); - offset++; + // lua_pushstring(L, "subtype"); + lua_push_string_by_name(L,subtype); + lua_rawseti(L, -2, 2); + offset++; } if (fields != NULL) { if (nodetype_has_prev(t)) { - lua_pushstring(L, "prev"); - lua_rawseti(L, -2, -1); +// 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]); + lua_pushstring(L, fields[i]); /* todo */ lua_rawseti(L, -2, (i + offset)); } } @@ -2386,14 +2391,14 @@ 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); - } -} +// 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) */ @@ -2412,8 +2417,8 @@ int nodelib_getdir(lua_State * L, int n, int absolute_only) { if (lua_type(L, n) == LUA_TSTRING) { const char *s = lua_tostring(L, n); - RETURN_DIR_VALUES(TRT); RETURN_DIR_VALUES(TLT); + RETURN_DIR_VALUES(TRT); RETURN_DIR_VALUES(LTL); RETURN_DIR_VALUES(RTT); luaL_error(L, "Bad direction specifier %s", s); @@ -2458,7 +2463,8 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) if (t == dir_node) { if (lua_key_eq(s, dir)) { - nodelib_pushdir(L, dir_dir(n), true); + // 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)) { @@ -2481,6 +2487,13 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) case 'd': lua_pushnumber(L, user_node_value(n)); break; + case 'l': + if (user_node_value(n) != 0) { + lua_rawgeti(L, LUA_REGISTRYINDEX, user_node_value(n)); + } else { + lua_pushnil(L); + } + break; case 'n': nodelib_pushlist(L, user_node_value(n)); break; @@ -2503,7 +2516,8 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) } 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); +// 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)); @@ -2522,7 +2536,7 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) lua_pushnumber(L, pdf_literal_mode(n)); } else if (lua_key_eq(s, data)) { if (pdf_literal_type(n) == lua_refid_literal) { - lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(n)); + lua_rawgeti(L, LUA_REGISTRYINDEX, pdf_literal_data(n)); } else { tokenlist_to_luastring(L, pdf_literal_data(n)); } @@ -2530,14 +2544,14 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s) lua_pushnil(L); } } else if (t == late_lua_node) { - if (lua_key_eq(s, name)) { - tokenlist_to_luastring(L, late_lua_name(n)); - } else if (lua_key_eq(s, data) || lua_key_eq(s, string)) { + if (lua_key_eq(s, string) || lua_key_eq(s, data)) { if (late_lua_type(n) == lua_refid_literal) { - lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(n)); + lua_rawgeti(L, LUA_REGISTRYINDEX, late_lua_data(n)); } else { tokenlist_to_luastring(L, late_lua_data(n)); } + } else if (lua_key_eq(s, name)) { + tokenlist_to_luastring(L, late_lua_name(n)); } else { lua_pushnil(L); } @@ -2742,7 +2756,11 @@ static int lua_nodelib_fast_getfield(lua_State * L) p = vlink(p); while (p != null) { if (attribute_id(p) == i) { - lua_pushnumber(L, (int) attribute_value(p)); + if ((int) attribute_value(p) > UNUSED_ATTRIBUTE) { + lua_pushnumber(L, (int) attribute_value(p)); + } else { + lua_pushnil(L); + } return 1; } else if (attribute_id(p) > i) { lua_pushnil(L); @@ -2814,7 +2832,8 @@ 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); + // nodelib_pushdir(L, box_dir(n), false); + 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)) { @@ -2897,7 +2916,8 @@ 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); + // nodelib_pushdir(L, rule_dir(n), false); + lua_push_dir_par(L, rule_dir(n)); } else { lua_pushnil(L); } @@ -2984,7 +3004,7 @@ static int lua_nodelib_fast_getfield(lua_State * L) if (lua_key_eq(s, subtype)) { lua_pushnumber(L, subtype(n)); } else if (lua_key_eq(s, style)) { - lua_pushstring(L, math_style_names[subtype(n)]); + lua_push_math_style_name(L,subtype(n)); } else { lua_pushnil(L); } @@ -3150,7 +3170,8 @@ 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); + // nodelib_pushdir(L, box_dir(n), false); + 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)) { @@ -3208,7 +3229,8 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char if (t == dir_node) { if (lua_key_eq(s, dir)) { - nodelib_pushdir(L, dir_dir(n), true); + // 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)) { @@ -3231,6 +3253,13 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char case 'd': lua_pushnumber(L, user_node_value(n)); break; + case 'l': + if (user_node_value(n) != 0) { + lua_rawgeti(L, LUA_REGISTRYINDEX, user_node_value(n)); + } else { + lua_pushnil(L); + } + break; case 'n': nodelib_pushdirect(user_node_value(n)); break; @@ -3253,7 +3282,8 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char } 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); +// 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)) { @@ -3270,7 +3300,7 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char lua_pushnumber(L, pdf_literal_mode(n)); } else if (lua_key_eq(s, data)) { if (pdf_literal_type(n) == lua_refid_literal) { - lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(n)); + lua_rawgeti(L, LUA_REGISTRYINDEX, pdf_literal_data(n)); } else { tokenlist_to_luastring(L, pdf_literal_data(n)); } @@ -3278,14 +3308,14 @@ static void lua_nodelib_direct_getfield_whatsit(lua_State * L, int n, const char lua_pushnil(L); } } else if (t == late_lua_node) { - if (lua_key_eq(s, name)) { - tokenlist_to_luastring(L, late_lua_name(n)); - } else if (lua_key_eq(s, data) || lua_key_eq(s, string)) { + if (lua_key_eq(s, string) || lua_key_eq(s, data)) { if (late_lua_type(n) == lua_refid_literal) { - lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(n)); + lua_rawgeti(L, LUA_REGISTRYINDEX, late_lua_data(n)); } else { tokenlist_to_luastring(L, late_lua_data(n)); } + } else if (lua_key_eq(s, name)) { + tokenlist_to_luastring(L, late_lua_name(n)); } else { lua_pushnil(L); } @@ -3477,7 +3507,11 @@ static int lua_nodelib_direct_getfield(lua_State * L) p = vlink(p); while (p != null) { if (attribute_id(p) == i) { - lua_pushnumber(L, (int) attribute_value(p)); + if ((int) attribute_value(p) > UNUSED_ATTRIBUTE) { + lua_pushnumber(L, (int) attribute_value(p)); + } else { + lua_pushnil(L); + } return 1; } else if (attribute_id(p) > i) { lua_pushnil(L) ; @@ -3550,7 +3584,8 @@ 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); + // nodelib_pushdir(L, box_dir(n), false); + 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)) { @@ -3621,7 +3656,8 @@ 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); + // nodelib_pushdir(L, rule_dir(n), false); + lua_push_dir_par(L, rule_dir(n)); } else { lua_pushnil(L); } @@ -3689,7 +3725,7 @@ static int lua_nodelib_direct_getfield(lua_State * L) } } else if (t == style_node) { if (lua_key_eq(s, style)) { - lua_pushstring(L, math_style_names[subtype(n)]); + lua_push_math_style_name(L,subtype(n)); } else { lua_pushnil(L); } @@ -3829,7 +3865,8 @@ 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); + // nodelib_pushdir(L, box_dir(n), false); + 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)) { @@ -4353,6 +4390,24 @@ static int lua_nodelib_direct_tonode(lua_State * L) /* node.setfield */ +/* ls-hh: normally a value will not be reassigned */ + +#define cleanup_late_lua(n) do { \ + if (late_lua_data(n) != 0) { \ + if (late_lua_type(n) == normal) { \ + delete_token_ref(late_lua_data(n)); \ + } else if (late_lua_type(n) == lua_refid_literal) { \ + luaL_unref(L, LUA_REGISTRYINDEX,late_lua_data(n)); \ + } \ + } \ +} while (0) + +#define cleanup_late_lua_name(n) do { \ + if (late_lua_name(n) != 0) { \ + delete_token_ref(late_lua_name(n)); \ + } \ +} while (0) + static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) { int t ; @@ -4385,12 +4440,8 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) return nodelib_cantset(L, n, s); } } else if (t == late_lua_node) { - if (lua_key_eq(s, data)) { - late_lua_data(n) = nodelib_gettoks(L, 3); - late_lua_type(n) = normal; - } else if (lua_key_eq(s, name)) { - late_lua_name(n) = nodelib_gettoks(L, 3); - } else if (lua_key_eq(s, string)) { + if (lua_key_eq(s, string)) { + cleanup_late_lua(n) ; /* ls-hh */ if (ini_version) { late_lua_data(n) = nodelib_gettoks(L, 3); late_lua_type(n) = normal; @@ -4399,9 +4450,17 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) late_lua_data(n) = luaL_ref(L, LUA_REGISTRYINDEX); late_lua_type(n) = lua_refid_literal; } + } else if (lua_key_eq(s, data)) { + cleanup_late_lua(n) ; /* ls-hh */ + late_lua_data(n) = nodelib_gettoks(L, 3); + late_lua_type(n) = normal; + } else if (lua_key_eq(s, name)) { + cleanup_late_lua_name(n) ; /* ls-hh */ + late_lua_name(n) = nodelib_gettoks(L, 3); } else { return nodelib_cantset(L, n, s); } + /* done */ } else if (t == user_defined_node) { if (lua_key_eq(s, user_id)) { user_node_id(n) = (halfword) lua_tointeger(L, 3); @@ -4415,6 +4474,13 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s) case 'd': user_node_value(n) = (halfword) lua_tointeger(L, 3); break; + case 'l': + lua_pushvalue(L, 3); + if (user_node_value(n) != 0) { + luaL_unref(L, LUA_REGISTRYINDEX,user_node_value(n)); + } + user_node_value(n) = luaL_ref(L, LUA_REGISTRYINDEX); + break; case 'n': user_node_value(n) = nodelib_getlist(L, 3); break; @@ -4641,9 +4707,10 @@ static int lua_nodelib_fast_setfield(lua_State * L) s = lua_tostring(L, 2); - if (lua_key_eq(s, id)) { - lua_pushnumber(L, t); - } else if (lua_key_eq(s, next)) { + /*if (lua_key_eq(s, id)) { + type(n) = (quarteword) lua_tointeger(L, 3); + }* else */ + if (lua_key_eq(s, next)) { halfword x = nodelib_getlist(L, 3); if (x>0 && type(x) == glue_spec_node) { return luaL_error(L, "You can't assign a %s node to a next field\n", node_data[type(x)].name); @@ -4749,7 +4816,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)) { - lua_pushnumber(L, shrink_order(n)); + 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)) { @@ -4872,10 +4939,10 @@ static int lua_nodelib_fast_setfield(lua_State * L) if (lua_key_eq(s, subtype)) { /* dummy subtype */ } else if (lua_key_eq(s, style)) { - lua_pushstring(L, math_style_names[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); */ - subtype(n) = (quarterword) luaL_checkoption(L, 3, "text", math_style_names); /* not 2? */ } } else if (t == accent_noad) { if (lua_key_eq(s, subtype)) { @@ -5120,12 +5187,8 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char return nodelib_cantset(L, n, s); } } else if (t == late_lua_node) { - if (lua_key_eq(s, data)) { - late_lua_data(n) = nodelib_gettoks(L, 3); - late_lua_type(n) = normal; - } else if (lua_key_eq(s, name)) { - late_lua_name(n) = nodelib_gettoks(L, 3); - } else if (lua_key_eq(s, string)) { + if (lua_key_eq(s, string)) { + cleanup_late_lua(n) ; /* ls-hh */ if (ini_version) { late_lua_data(n) = nodelib_gettoks(L, 3); late_lua_type(n) = normal; @@ -5134,6 +5197,13 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char late_lua_data(n) = luaL_ref(L, LUA_REGISTRYINDEX); late_lua_type(n) = lua_refid_literal; } + } else if (lua_key_eq(s, data)) { + cleanup_late_lua(n) ; /* ls-hh */ + late_lua_data(n) = nodelib_gettoks(L, 3); + late_lua_type(n) = normal; + } else if (lua_key_eq(s, name)) { + cleanup_late_lua_name(n) ; /* ls-hh */ + late_lua_name(n) = nodelib_gettoks(L, 3); } else { return nodelib_cantset(L, n, s); } @@ -5150,6 +5220,13 @@ static int lua_nodelib_direct_setfield_whatsit(lua_State * L, int n, const char case 'd': user_node_value(n) = (halfword) lua_tointeger(L, 3); break; + case 'l': + lua_pushvalue(L, 3); + if (user_node_value(n) != 0) { + luaL_unref(L, LUA_REGISTRYINDEX,user_node_value(n)); + } + user_node_value(n) = luaL_ref(L, LUA_REGISTRYINDEX); + break; case 'n': user_node_value(n) = nodelib_getlist(L, 3); break; @@ -5376,9 +5453,10 @@ static int lua_nodelib_direct_setfield(lua_State * L) s = lua_tostring(L, 2); - if (lua_key_eq(s, id)) { - lua_pushnumber(L, t); - } else if (lua_key_eq(s, next)) { + /*if (lua_key_eq(s, id)) { + type(n) = (quarteword) lua_tointeger(L, 3); + } else*/ + if (lua_key_eq(s, next)) { halfword x = nodelib_popdirect(3); if (x>0 && type(x) == glue_spec_node) { return luaL_error(L, "You can't assign a %s node to a next field\n", node_data[type(x)].name); @@ -5484,7 +5562,7 @@ static int lua_nodelib_direct_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)) { - lua_pushnumber(L, shrink_order(n)); + 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)) { @@ -5606,10 +5684,10 @@ static int lua_nodelib_direct_setfield(lua_State * L) if (lua_key_eq(s, subtype)) { /* dummy subtype */ } else if (lua_key_eq(s, style)) { - lua_pushstring(L, math_style_names[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); */ - subtype(n) = (quarterword) luaL_checkoption(L, 2, "text", math_style_names); /* was 3 */ } } else if (t == accent_noad) { if (lua_key_eq(s, subtype)) { @@ -6024,7 +6102,7 @@ static int lua_nodelib_attributes_to_properties(lua_State * L) } } } - lua_rawset(Luas,-3); + lua_rawset(L,-3); n = vlink(n); } return 1 ; |