diff options
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r-- | source/luametatex/source/lua/lmtinterface.h | 2 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtnodelib.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexlib.c | 69 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttokenlib.c | 110 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttokenlib.h | 2 |
5 files changed, 85 insertions, 102 deletions
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h index 3fd87db2f..e761252a8 100644 --- a/source/luametatex/source/lua/lmtinterface.h +++ b/source/luametatex/source/lua/lmtinterface.h @@ -865,9 +865,7 @@ make_lua_key(L, match);\ make_lua_key(L, math);\ make_lua_key(L, mathspec);\ make_lua_key(L, math_accent);\ -make_lua_key(L, math_char_given);\ make_lua_key(L, math_char_number);\ -make_lua_key(L, math_char_xgiven);\ make_lua_key(L, math_choice);\ make_lua_key(L, math_component);\ make_lua_key(L, math_fence);\ diff --git a/source/luametatex/source/lua/lmtnodelib.c b/source/luametatex/source/lua/lmtnodelib.c index 7d9d7bcbe..eb29611e2 100644 --- a/source/luametatex/source/lua/lmtnodelib.c +++ b/source/luametatex/source/lua/lmtnodelib.c @@ -2997,7 +2997,7 @@ static int nodelib_direct_getdata(lua_State *L) } case mark_node: if (lua_toboolean(L, 2)) { - lmt_token_list_to_luastring(L, mark_ptr(n), 0, 0); + lmt_token_list_to_luastring(L, mark_ptr(n), 0, 0, 0); } else { lmt_token_list_to_lua(L, mark_ptr(n)); } @@ -6555,7 +6555,7 @@ static int nodelib_common_getfield(lua_State *L, int direct, halfword n) lua_pushinteger(L, mark_index(n)); } else if (lua_key_eq(s, data) || lua_key_eq(s, mark)) { if (lua_toboolean(L, 3)) { - lmt_token_list_to_luastring(L, mark_ptr(n), 0, 0); + lmt_token_list_to_luastring(L, mark_ptr(n), 0, 0, 0); } else { lmt_token_list_to_lua(L, mark_ptr(n)); } diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c index d44127330..afafb068b 100644 --- a/source/luametatex/source/lua/lmttexlib.c +++ b/source/luametatex/source/lua/lmttexlib.c @@ -1715,10 +1715,9 @@ static int texlib_gettoks(lua_State *L) if (lua_toboolean(L, slot)) { lmt_token_register_to_lua(L, state ? toks_parameter(index) : toks_register(index)); } else { + strnumber value = tex_get_tex_toks_register(index, state); - char *s = tex_makecstring(value); - lua_pushstring(L, s); - lmt_memory_free(s); + lua_pushstring(L, tex_to_cstring(value)); tex_flush_str(value); } } else { @@ -1754,7 +1753,7 @@ static int texlib_getmark(lua_State *L) if (num >= 0 && num <= lmt_mark_state.mark_data.ptr) { halfword ptr = tex_get_some_mark(mrk, num); if (ptr) { - char *str = tex_tokenlist_to_tstring(ptr, 1, NULL, 0, 0, 0); + char *str = tex_tokenlist_to_tstring(ptr, 1, NULL, 0, 0, 0, 0); if (str) { lua_pushstring(L, str); } else { @@ -1783,7 +1782,6 @@ int lmt_get_box_id(lua_State *L, int i, int report) int cmd = eq_type(cs); switch (cmd) { case char_given_cmd: - // case math_char_given_cmd: case integer_cmd: index = eq_value(cs); break; @@ -2597,7 +2595,6 @@ static int texlib_newindex(lua_State *L) static int texlib_aux_convert(lua_State *L, int cur_code) { int i = -1; - char *str = NULL; switch (cur_code) { /* ignored (yet) */ case insert_progress_code: /* arg <register int> */ @@ -2632,19 +2629,22 @@ static int texlib_aux_convert(lua_State *L, int cur_code) if (cur_code < 32) { int texstr = tex_the_convert_string(cur_code, i); if (texstr) { - str = tex_makecstring(texstr); + lua_pushstring(L, tex_to_cstring(texstr)); tex_flush_str(texstr); + + // int allocated = 0; + // char *str = tex_makecstring(texstr, &allocated); + // lua_pushstring(L, str); + // if (allocated) { + // lmt_memory_free(str); + // } + // tex_flush_str(texstr); + return 1; } } break; } - /* end */ - if (str) { - lua_pushstring(L, str); - lmt_memory_free(str); - } else { - lua_pushnil(L); - } + lua_pushnil(L); return 1; } @@ -2687,10 +2687,9 @@ static int texlib_aux_scan_internal(lua_State *L, int cmd, int code, int values) default: { int texstr = tex_the_scanned_result(); - char *str = tex_makecstring(texstr); + char *str = tex_to_cstring(texstr); if (str) { lua_pushstring(L, str); - lmt_memory_free(str); } else { lua_pushnil(L); } @@ -3013,7 +3012,6 @@ static int texlib_get_internal(lua_State *L, int index, int all) case set_auxiliary_cmd: case set_page_property_cmd: case char_given_cmd: - // case math_char_given_cmd: case integer_cmd: case dimension_cmd: case gluespec_cmd: @@ -3407,26 +3405,22 @@ static int texlib_hashtokens(lua_State *L) int nx = 0; int all = lua_toboolean(L, 1); lua_createtable(L, hash_size, 0); + /* todo: check active characters as these have three bogus bytes in front */ if (all) { while (cs <= hash_size) { - /* because strings never get freed we can as well directly access |s|. */ strnumber s = cs_text(cs); if (s > 0) { halfword n = cs_next(cs); - char *ss = tex_makecstring(s); if (n) { int mt = 0; lua_createtable(L, 2, 0); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); ++nt; lua_rawseti(L, -2, ++mt); while (n) { s = cs_text(n); if (s) { - ss = tex_makecstring(s); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); lua_rawseti(L, -2, ++mt); ++nt; ++nx; @@ -3434,8 +3428,7 @@ static int texlib_hashtokens(lua_State *L) n = cs_next(n); } } else { - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); ++nt; } } else { @@ -3449,16 +3442,12 @@ static int texlib_hashtokens(lua_State *L) strnumber s = cs_text(cs); if (s > 0) { halfword n = cs_next(cs); - char *ss = tex_makecstring(s); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); lua_rawseti(L, -2, ++nt); while (n) { s = cs_text(n); if (s) { - ss = tex_makecstring(s); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); lua_rawseti(L, -2, ++nt); ++nx; } @@ -3482,9 +3471,7 @@ static int texlib_primitives(lua_State *L) while (cs < prim_size) { strnumber s = get_prim_text(cs); if (s > 0 && (get_prim_origin(cs) != no_command)) { - char *ss = tex_makecstring(s); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); lua_rawseti(L, -2, ++nt); } cs++; @@ -3518,9 +3505,7 @@ static int texlib_extraprimitives(lua_State *L) while (cs < prim_size) { strnumber s = get_prim_text(cs); if (s > 0 && (get_prim_origin(cs) & mask)) { - char *ss = tex_makecstring(s); - lua_pushstring(L, ss); - lmt_memory_free(ss); + lua_pushstring(L, tex_to_cstring(s)); lua_rawseti(L, -2, ++nt); } cs++; @@ -3531,7 +3516,7 @@ static int texlib_extraprimitives(lua_State *L) static void texlib_aux_enableprimitive(const char *pre, size_t prel, const char *prm) { strnumber s = tex_maketexstring(prm); - halfword prm_val = tex_prim_lookup(s); + halfword prm_val = tex_prim_lookup(s); /* todo: no need for tex string */ tex_flush_str(s); if (prm_val != undefined_primitive && get_prim_origin(prm_val) != no_command) { char *newprm; @@ -3594,10 +3579,8 @@ static int texlib_enableprimitives(lua_State *L) for (int cs = 0; cs < prim_size; cs++) { strnumber s = get_prim_text(cs); if (s > 0) { - /* there is actually no need to copy */ - char *prm = tex_makecstring(s); + char *prm = tex_to_cstring(s); texlib_aux_enableprimitive(pre, lpre, prm); - lmt_memory_free(prm); } } } @@ -4561,8 +4544,6 @@ static int texlib_mathchardef(lua_State *L) d.index = lmt_optinteger(L, 8, 0); if (class_in_range(m.class_value) && family_in_range(m.family_value) && character_in_range(m.character_value)) { tex_define(flags, cs, mathspec_cmd, tex_new_math_dict_spec(d, m, umath_mathcode)); - // halfword code = math_packed_character(m.class_value, m.family_value, m.character_value); - // tex_define(flags, cs, (quarterword) math_char_xgiven_cmd, code); } else { tex_normal_error("lua", "mathchardef needs proper class, family and character codes"); } diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c index ac69241ba..feac7cd46 100644 --- a/source/luametatex/source/lua/lmttokenlib.c +++ b/source/luametatex/source/lua/lmttokenlib.c @@ -156,8 +156,6 @@ void lmt_tokenlib_initialize(void) lmt_interface.command_names[math_shift_cs_cmd] = (command_item) { .id = math_shift_cs_cmd, .lua = lua_key_index(math_shift_cs), .name = lua_key(math_shift_cs), .kind = regular_command_item, .min = 0, .max = last_math_shift_cs_code, .base = 0, .fixedvalue = 0 }; /* a bit too tolerant */ lmt_interface.command_names[end_cs_name_cmd] = (command_item) { .id = end_cs_name_cmd, .lua = lua_key_index(end_cs_name), .name = lua_key(end_cs_name), .kind = regular_command_item, .min = 0, .max = 0, .base = 0, .fixedvalue = 0 }; lmt_interface.command_names[char_given_cmd] = (command_item) { .id = char_given_cmd, .lua = lua_key_index(char_given), .name = lua_key(char_given), .kind = character_command_item, .min = 0, .max = max_character_code, .base = 0, .fixedvalue = 0 }; - // lmt_interface.command_names[math_char_given_cmd] = (command_item) { .id = math_char_given_cmd, .lua = lua_key_index(math_char_given), .name = lua_key(math_char_given), .kind = character_command_item, .min = 0, .max = max_character_code, .base = 0, .fixedvalue = 0 }; - // lmt_interface.command_names[math_char_xgiven_cmd] = (command_item) { .id = math_char_xgiven_cmd, .lua = lua_key_index(math_char_xgiven), .name = lua_key(math_char_xgiven), .kind = character_command_item, .min = 0, .max = max_character_code, .base = 0, .fixedvalue = 0 }; lmt_interface.command_names[some_item_cmd] = (command_item) { .id = some_item_cmd, .lua = lua_key_index(some_item), .name = lua_key(some_item), .kind = regular_command_item, .min = 0, .max = last_some_item_code, .base = 0, .fixedvalue = 0 }; lmt_interface.command_names[internal_toks_cmd] = (command_item) { .id = internal_toks_cmd, .lua = lua_key_index(internal_toks), .name = lua_key(internal_toks), .kind = internal_command_item, .min = first_toks_code, .max = last_toks_code, .base = internal_toks_base, .fixedvalue = 0 }; lmt_interface.command_names[register_toks_cmd] = (command_item) { .id = register_toks_cmd, .lua = lua_key_index(register_toks), .name = lua_key(register_toks), .kind = register_command_item, .min = 0, .max = biggest_reg, .base = register_toks_base, .fixedvalue = 0 }; @@ -433,10 +431,10 @@ void lmt_token_list_to_lua(lua_State *L, halfword p) } } -void lmt_token_list_to_luastring(lua_State *L, halfword p, int nospace, int strip) +void lmt_token_list_to_luastring(lua_State *L, halfword p, int nospace, int strip, int wipe) { int l; - char *s = tex_tokenlist_to_tstring(p, 1, &l, 0, nospace, strip); /* nasty ... preambles or not, could have been endmatchtoken */ + char *s = tex_tokenlist_to_tstring(p, 1, &l, 0, nospace, strip, wipe); /* nasty ... preambles or not, could have been endmatchtoken */ if (l) { lua_pushlstring(L, s, (size_t) l); } else { @@ -511,16 +509,19 @@ halfword lmt_token_code_from_lua(lua_State *L, int slot) # define is_active_string(s) (strlen(s) > 3 && *s == 0xEF && *(s+1) == 0xBF && *(s+2) == 0xBF) -static unsigned char *tokenlib_aux_get_cs_text(int cs) +static unsigned char *tokenlib_aux_get_cs_text(int cs, int *allocated) { if (cs == null_cs) { - return (unsigned char *) lmt_memory_strdup("\\csname\\endcsname"); + return (unsigned char *) "\\csname\\endcsname"; } else if ((cs_text(cs) < 0) || (cs_text(cs) >= lmt_string_pool_state.string_pool_data.ptr)) { - return (unsigned char *) lmt_memory_strdup(""); - } else if (tex_is_active_cs(cs_text(cs))) { - return (unsigned char *) tex_makecstring(cs_text(cs)); + return (unsigned char *) ""; + // } else { + // return (unsigned char *) tex_makecstring(cs_text(cs)); + } else if (cs_text(cs) < cs_offset_value) { + *allocated = 1; + return (unsigned char *) aux_uni2str((unsigned) cs_text(cs)); } else { - return (unsigned char *) tex_makecstring(cs_text(cs)); + return (unsigned char *) (str_length(cs_text(cs)) > 0 ? (unsigned char *) str_string(cs_text(cs)) : (unsigned char *) ""); } } @@ -871,14 +872,17 @@ static int tokenlib_scan_csname(lua_State *L) } t = cur_cs ? cs_token_flag + cur_cs : token_val (cur_cmd, cur_chr); if (t >= cs_token_flag) { - unsigned char *s = tokenlib_aux_get_cs_text(t - cs_token_flag); + int allocated = 0; + unsigned char *s = tokenlib_aux_get_cs_text(t - cs_token_flag, &allocated); if (s) { if (tex_is_active_cs(cs_text(t - cs_token_flag))) { lua_pushstring(L, (char *) (s + 3)); } else { lua_pushstring(L, (char *) s); } - lmt_memory_free(s); + if (allocated) { + lmt_memory_free(s); + } } else { lua_pushnil(L); } @@ -1408,8 +1412,7 @@ static int tokenlib_scan_string(lua_State *L) { halfword defref = lmt_input_state.def_ref; halfword result = tex_scan_toks_expand(1, NULL, 0); - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); lmt_input_state.def_ref = defref; break; } @@ -1421,8 +1424,7 @@ static int tokenlib_scan_string(lua_State *L) case tolerant_semi_protected_call_cmd: { halfword t = token_link(cur_chr); - lmt_token_list_to_luastring(L, t, 0, 0); - tex_flush_token_list(t); + lmt_token_list_to_luastring(L, t, 0, 0, 1); break; } case letter_cmd: @@ -1463,8 +1465,7 @@ static int tokenlib_scan_argument(lua_State *L) halfword defref = lmt_input_state.def_ref; int expand = lua_type(L, 1) == LUA_TBOOLEAN ? lua_toboolean(L, 1) : 1; halfword result = expand ? tex_scan_toks_expand(1, NULL, 0) : tex_scan_toks_normal(1, NULL); - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); lmt_input_state.def_ref = defref; break; } @@ -1485,8 +1486,7 @@ static int tokenlib_scan_argument(lua_State *L) tex_back_input(cur_tok); result = tex_scan_toks_expand(1, NULL, 0); } - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); lmt_input_state.def_ref = defref; break; } @@ -1685,8 +1685,7 @@ static int tokenlib_scan_delimited(lua_State *L) FINALYDONE: /* */ lmt_input_state.def_ref = defref; - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); } else { tex_back_input(cur_tok); lua_pushnil(L); @@ -1781,8 +1780,7 @@ static int tokenlib_grab_until(lua_State *L) } tokenlib_aux_unsave_tex_scanner(texstate); lmt_input_state.def_ref = defref; - lmt_token_list_to_luastring(L, result, nospace, strip); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, nospace, strip, 1); } else { lua_pushnil(L); } @@ -2013,8 +2011,7 @@ static int tokenlib_scan_value(lua_State *L) halfword defref = lmt_input_state.def_ref; result = tex_scan_toks_expand(1, NULL, 0); lmt_input_state.def_ref = defref; - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); } break; /* @@ -2052,8 +2049,7 @@ static int tokenlib_scan_value(lua_State *L) halfword defref = lmt_input_state.def_ref; result = tex_scan_toks_expand(1, NULL, 0); lmt_input_state.def_ref = defref; - lmt_token_list_to_luastring(L, result, 0, 0); - tex_flush_token_list(result); + lmt_token_list_to_luastring(L, result, 0, 0, 1); luaL_addchar(&b, '{'); luaL_addvalue(&b); luaL_addchar(&b, '}'); @@ -2069,7 +2065,8 @@ static int tokenlib_scan_value(lua_State *L) /*tex We need to add a space. */ halfword t = cur_cs ? cs_token_flag + cur_cs : token_val(cur_cmd, cur_chr); if (t >= cs_token_flag) { - unsigned char *s = tokenlib_aux_get_cs_text(t - cs_token_flag); + int allocated = 0; + unsigned char *s = tokenlib_aux_get_cs_text(t - cs_token_flag, &allocated); if (s) { if (tex_is_active_cs(cs_text(t - cs_token_flag))) { lua_pushstring(L, (char *) (s + 3)); @@ -2080,7 +2077,9 @@ static int tokenlib_scan_value(lua_State *L) luaL_addvalue(&b); luaL_addchar(&b, ' '); } - lmt_memory_free(s); + if (allocated) { + lmt_memory_free(s); + } } } } @@ -2377,7 +2376,7 @@ static int tokenlib_getprimitives(lua_State *L) while (cs < prim_size) { strnumber s = get_prim_text(cs); if (s > 0 && (get_prim_origin(cs) != no_command)) { - char *ss = tex_makecstring(s); + char *ss = tex_to_cstring(s); int cmd = prim_eq_type(cs); int chr = prim_equiv(cs); if (! raw) { @@ -2393,7 +2392,6 @@ static int tokenlib_getprimitives(lua_State *L) lua_pushinteger(L, prim_origin(cs)); lua_rawseti(L, -2, 4); lua_rawseti(L, -2, ++nt); - lmt_memory_free(ss); } cs++; } @@ -2508,14 +2506,17 @@ inline static int tokenlib_get_csname(lua_State *L) lua_token *n = tokenlib_aux_check_istoken(L, 1); halfword tok = token_info(n->token); if (tok >= cs_token_flag) { - unsigned char *s = tokenlib_aux_get_cs_text(tok - cs_token_flag); + int allocated = 0; + unsigned char *s = tokenlib_aux_get_cs_text(tok - cs_token_flag, &allocated); if (s) { if (tex_is_active_cs(cs_text(tok - cs_token_flag))) { lua_pushstring(L, (char *) (s + 3)); } else { lua_pushstring(L, (char *) s); } - lmt_memory_free(s); + if (allocated) { + lmt_memory_free(s); + } return 1; } } @@ -2544,10 +2545,13 @@ inline static int tokenlib_get_active(lua_State *L) halfword tok = token_info(n->token); int result = 0; if (tok >= cs_token_flag) { - unsigned char *s = tokenlib_aux_get_cs_text(tok - cs_token_flag); + int allocated = 0; + unsigned char *s = tokenlib_aux_get_cs_text(tok - cs_token_flag, &allocated); if (s) { result = tex_is_active_cs(cs_text(tok - cs_token_flag)); - lmt_memory_free(s); + if (allocated) { + lmt_memory_free(s); + } } } lua_pushboolean(L, result); @@ -2753,7 +2757,8 @@ static int tokenlib_get_fields(lua_State *L) lua_createtable(L, 0, onlyflags ? 0 : 5); if (tok >= cs_token_flag) { int t = tok - cs_token_flag; - unsigned char* str = tokenlib_aux_get_cs_text(t); + int allocated = 0; + unsigned char* str = tokenlib_aux_get_cs_text(t, &allocated); if (str) { if (! onlyflags) { lua_push_key(csname); @@ -2767,7 +2772,9 @@ static int tokenlib_get_fields(lua_State *L) } lua_rawset(L, -3); } - lmt_memory_free(str); + if (allocated) { + lmt_memory_free(str); + } } cmd = eq_type(t); chr = eq_value(t); @@ -2836,9 +2843,12 @@ static int tokenlib_tostring(lua_State* L) unsigned char* csp = NULL; const char* cmn = NULL; if (tok >= cs_token_flag) { + int allocated = 0; tok -= cs_token_flag; - csn = tokenlib_aux_get_cs_text(tok); - csp = csn; + csn = tokenlib_aux_get_cs_text(tok, &allocated); + if (allocated) { + csp = csn; + } if (csn && tex_is_active_cs(cs_text(tok))) { csn += 3; } @@ -2974,7 +2984,7 @@ static int tokenlib_get_meaning(lua_State *L) lmt_token_register_to_lua(L, chr); } } else { - char *str = tex_tokenlist_to_tstring(chr, 1, NULL, 0, 0, 0); + char *str = tex_tokenlist_to_tstring(chr, 1, NULL, 0, 0, 0, 0); lua_pushstring(L, str ? str : ""); } return 1; @@ -3041,10 +3051,9 @@ static int tokenlib_get_macro(lua_State *L) char *str = NULL; if (lua_toboolean(L, 2)) { tokenlib_aux_expand_macros_in_tokenlist(chr); // todo: use return value instead of def_ref - str = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, NULL, 0, 0, 0); - tex_flush_token_list(lmt_input_state.def_ref); + str = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, NULL, 0, 0, 0, 1); } else { - str = tex_tokenlist_to_tstring(chr, 1, NULL, 1, 0, 0); + str = tex_tokenlist_to_tstring(chr, 1, NULL, 1, 0, 0, 0); } lua_pushstring(L, str ? str : ""); return 1; @@ -3091,8 +3100,7 @@ char *lmt_get_expansion(halfword head, int *len) halfword ref = get_reference_token(); set_token_link(ref, head); tokenlib_aux_expand_macros_in_tokenlist(ref); // todo: use return value instead of def_ref - str = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, len, 0, 0, 0); - tex_flush_token_list(lmt_input_state.def_ref); + str = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, len, 0, 0, 0, 1); tex_flush_token_list(ref); return str; } @@ -3113,12 +3121,9 @@ static int tokenlib_get_expansion(lua_State* L) char *s; int l; tex_parse_str_to_tok(h, &t, ct, str, len, 2); /* ignore unknown */ - tokenlib_aux_expand_macros_in_tokenlist(h); // todo: use return value instead of def_ref - s = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, &l, 0, 0, 0); - tex_flush_token_list(lmt_input_state.def_ref); + s = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, &l, 0, 0, 0, 1); tex_flush_token_list(h); - if (l > 0) { lua_pushlstring(L, (const char *) s, (size_t) l); return 1; @@ -3472,9 +3477,8 @@ static int tokenlib_serialize(lua_State *L) halfword t = n->token; char *s; tokenlib_aux_expand_macros_in_tokenlist(t); // todo: use return value instead of def_ref - s = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, NULL, 0, 0, 0); + s = tex_tokenlist_to_tstring(lmt_input_state.def_ref, 1, NULL, 0, 0, 0, 1); lua_pushstring(L, s ? s : ""); - tex_flush_token_list(lmt_input_state.def_ref); } else { lua_pushnil(L); } @@ -3656,7 +3660,7 @@ void lmt_token_call(int p) /*tex The \TEX\ pointer to the token list. */ { LoadS ls; int l = 0; - ls.s = tex_tokenlist_to_tstring(p, 1, &l, 0, 0, 0); + ls.s = tex_tokenlist_to_tstring(p, 1, &l, 0, 0, 0, 0); ls.size = (size_t) l; if (ls.size > 0) { lua_State *L = lmt_lua_state.lua_instance; diff --git a/source/luametatex/source/lua/lmttokenlib.h b/source/luametatex/source/lua/lmttokenlib.h index 5339a80fe..450c6173a 100644 --- a/source/luametatex/source/lua/lmttokenlib.h +++ b/source/luametatex/source/lua/lmttokenlib.h @@ -28,7 +28,7 @@ typedef enum command_item_types { } command_item_types; extern void lmt_token_list_to_lua (lua_State *L, halfword p); -extern void lmt_token_list_to_luastring (lua_State *L, halfword p, int nospace, int strip); +extern void lmt_token_list_to_luastring (lua_State *L, halfword p, int nospace, int strip, int wipe); extern halfword lmt_token_list_from_lua (lua_State *L, int slot); extern halfword lmt_token_code_from_lua (lua_State *L, int slot); |