diff options
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r-- | source/luametatex/source/lua/lmtcallbacklib.h | 26 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtnodelib.c | 58 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexlib.c | 10 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttokenlib.c | 21 |
4 files changed, 87 insertions, 28 deletions
diff --git a/source/luametatex/source/lua/lmtcallbacklib.h b/source/luametatex/source/lua/lmtcallbacklib.h index 6faa4ddac..7801e1a70 100644 --- a/source/luametatex/source/lua/lmtcallbacklib.h +++ b/source/luametatex/source/lua/lmtcallbacklib.h @@ -83,23 +83,23 @@ typedef enum callback_keys { callback_result_key = 'R', /*tex a string (return value) but nil is also okay */ } callback_keys; -inline static int lmt_callback_defined (int a) { return lmt_callback_state.values[a]; } -inline static int lmt_callback_call (lua_State *L, int i, int o, int top) { return lua_pcallk(L, i, o, top + 2, 0, NULL); } +inline static int lmt_callback_defined (int a) { return lmt_callback_state.values[a]; } +inline static int lmt_callback_call (lua_State *L, int i, int o, int top) { return lua_pcallk(L, i, o, top + 2, 0, NULL); } -extern int lmt_callback_okay (lua_State *L, int i, int *top); -extern void lmt_callback_error (lua_State *L, int top, int i); -inline void lmt_callback_wrapup (lua_State *L, int top) { lua_settop(L, top); } +extern int lmt_callback_okay (lua_State *L, int i, int *top); +extern void lmt_callback_error (lua_State *L, int top, int i); +inline static void lmt_callback_wrapup (lua_State *L, int top) { lua_settop(L, top); } + +extern int lmt_run_callback (lua_State *L, int i, const char *values, ...); +extern int lmt_run_and_save_callback (lua_State *L, int i, const char *values, ...); +extern int lmt_run_saved_callback_line (lua_State *L, int i, int firstpos); +extern int lmt_run_saved_callback_close (lua_State *L, int i); -extern int lmt_run_callback (lua_State *L, int i, const char *values, ...); -extern int lmt_run_and_save_callback (lua_State *L, int i, const char *values, ...); -extern int lmt_run_saved_callback_line (lua_State *L, int i, int firstpos); -extern int lmt_run_saved_callback_close (lua_State *L, int i); +extern void lmt_destroy_saved_callback (lua_State *L, int i); -extern void lmt_destroy_saved_callback (lua_State *L, int i); +extern void lmt_run_memory_callback (const char *what, int success); -extern void lmt_run_memory_callback (const char *what, int success); - -extern void lmt_push_callback_usage (lua_State *L); +extern void lmt_push_callback_usage (lua_State *L); # endif diff --git a/source/luametatex/source/lua/lmtnodelib.c b/source/luametatex/source/lua/lmtnodelib.c index 4f0c7d73a..2a02fbd11 100644 --- a/source/luametatex/source/lua/lmtnodelib.c +++ b/source/luametatex/source/lua/lmtnodelib.c @@ -1363,12 +1363,12 @@ static int nodelib_direct_getanchors(lua_State *L) lua_pushnil(L); } /* bonus detail: source, target */ - if (box_source_anchor(n)) { + if (box_anchor(n)) { lua_pushinteger(L, box_anchor(n) & 0x0FFF); } else { lua_pushnil(L); } - if (box_target_anchor(n)) { + if (box_anchor(n)) { lua_pushinteger(L, (box_anchor(n) >> 16) & 0x0FFF); } else { lua_pushnil(L); @@ -7861,6 +7861,57 @@ static int nodelib_direct_unprotectglyphs(lua_State *L) return 0; } +/*tex This is an experiment. */ + +inline static void nodelib_aux_protect_all_none(halfword h) +{ + while (h) { + if (node_type(h) == glyph_node) { + halfword f = glyph_font(h); + if (f >= 0 && f <= lmt_font_state.font_data.ptr && lmt_font_state.fonts[f] && has_font_text_control(f, text_control_none_protected)) { + glyph_protected(h) = glyph_protected_text_code; + } + } + h = node_next(h); + } +} + +inline static void nodelib_aux_protect_node_none(halfword n) +{ + switch (node_type(n)) { + case glyph_node: + { + halfword f = glyph_font(n); + if (f >= 0 && f <= lmt_font_state.font_data.ptr && lmt_font_state.fonts[f] && has_font_text_control(f, text_control_none_protected)) { + glyph_protected(n) = glyph_protected_text_code; + } + } + break; + case disc_node: + nodelib_aux_protect_all_none(disc_no_break_head(n)); + nodelib_aux_protect_all_none(disc_pre_break_head(n)); + nodelib_aux_protect_all_none(disc_post_break_head(n)); + break; + } +} + +static int nodelib_direct_protectglyphs_none(lua_State *L) +{ + halfword head = nodelib_valid_direct_from_index(L, 1); + halfword tail = nodelib_valid_direct_from_index(L, 2); + if (head) { + while (head) { + nodelib_aux_protect_node_none(head); + if (head == tail) { + break; + } else { + head = node_next(head); + } + } + } + return 0; +} + /* node.direct.first_glyph */ static int nodelib_direct_firstglyph(lua_State *L) @@ -7946,7 +7997,7 @@ static int nodelib_direct_hasglyph(lua_State *L) /* node.getword */ -static inline int nodelib_aux_in_word(halfword n) +inline static int nodelib_aux_in_word(halfword n) { switch (node_type(n)) { case glyph_node: @@ -9644,6 +9695,7 @@ static const struct luaL_Reg nodelib_direct_function_list[] = { { "newmathglyph", nodelib_direct_newmathglyph }, { "protectglyph", nodelib_direct_protectglyph }, { "protectglyphs", nodelib_direct_protectglyphs }, + { "protectglyphsnone", nodelib_direct_protectglyphs_none }, { "protrusionskippable", nodelib_direct_protrusionskipable }, { "rangedimensions", nodelib_direct_rangedimensions }, /* maybe get... */ { "getglyphdimensions", nodelib_direct_getglyphdimensions }, diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c index c88d13490..7d1f3c32f 100644 --- a/source/luametatex/source/lua/lmttexlib.c +++ b/source/luametatex/source/lua/lmttexlib.c @@ -2173,7 +2173,7 @@ return 0; static int texlib_getmathcode(lua_State* L) { - mathcodeval mval = { 0, 0, 0 }; + mathcodeval mval = tex_no_math_code(); int ch = lmt_checkinteger(L, -1); if (character_in_range(ch)) { mval = tex_get_math_code(ch); @@ -2192,7 +2192,7 @@ static int texlib_getmathcode(lua_State* L) static int texlib_getmathcodes(lua_State* L) { - mathcodeval mval = { 0, 0, 0 }; + mathcodeval mval = tex_no_math_code(); int ch = lmt_checkinteger(L, -1); if (character_in_range(ch)) { mval = tex_get_math_code(ch); @@ -2603,6 +2603,7 @@ static int texlib_aux_convert(lua_State *L, int cur_code) /* case lua_token_string_code: */ /* arg token list */ case string_code: /* arg token */ case cs_string_code: /* arg token */ + case cs_active_code: /* arg token */ case detokenized_code: /* arg token */ case meaning_code: /* arg token */ case to_mathstyle_code: @@ -5191,8 +5192,11 @@ static int texlib_getmathcontrolvalues(lua_State *L) static int texlib_gettextcontrolvalues(lua_State *L) { - lua_createtable(L, 1, 0); + lua_createtable(L, 2, 2); lua_set_string_by_index(L, text_control_collapse_hyphens, "collapsehyphens"); + lua_set_string_by_index(L, text_control_base_ligaturing, "baseligaturing"); + lua_set_string_by_index(L, text_control_base_kerning, "basekerning"); + lua_set_string_by_index(L, text_control_none_protected, "noneprotected"); return 1; } diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c index e15b2de5a..97ca1b144 100644 --- a/source/luametatex/source/lua/lmttokenlib.c +++ b/source/luametatex/source/lua/lmttokenlib.c @@ -1874,6 +1874,7 @@ static int tokenlib_scan_next_char(lua_State *L) break; case letter_cmd: case other_char_cmd: + case active_char_cmd: /* needs testing */ { char buffer[6]; char *uindex = aux_uni2string((char *) buffer, (unsigned int) cur_chr); @@ -3069,6 +3070,8 @@ static int tokenlib_push_macro(lua_State *L) // todo: just store cmd and flag to /*tex We need to check for a valid hit, but what is best here, for instance using |(cmd >= call_cmd)| is not okay as we miss a lot then. + + Active characters: maybe when we pass a number ... */ if (lua_type(L, 1) == LUA_TSTRING) { size_t lname = 0; @@ -3088,6 +3091,15 @@ static int tokenlib_push_macro(lua_State *L) // todo: just store cmd and flag to return 0; } +static int tokenlib_pop_macro(lua_State *L) +{ + lua_token_package *p = tokenlib_aux_check_ispackage(L, 1); + if (p) { + tex_forced_define(p->how, p->cs, p->flag, p->cmd, p->chr); + } + return 0; +} + char *lmt_get_expansion(halfword head, int *len) { char *str = NULL; @@ -3127,15 +3139,6 @@ static int tokenlib_get_expansion(lua_State* L) return 1; } -static int tokenlib_pop_macro(lua_State *L) -{ - lua_token_package *p = tokenlib_aux_check_ispackage(L, 1); - if (p) { - tex_forced_define(p->how, p->cs, p->flag, p->cmd, p->chr); - } - return 0; -} - static int tokenlib_save_lua(lua_State *L) { halfword f = lmt_tohalfword(L, 1); |