diff options
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r-- | source/luametatex/source/lua/lmtenginelib.c | 2 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtfontlib.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtinterface.h | 20 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtmplib.c | 1 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtstatuslib.c | 1 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexlib.c | 157 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttokenlib.c | 54 |
7 files changed, 220 insertions, 19 deletions
diff --git a/source/luametatex/source/lua/lmtenginelib.c b/source/luametatex/source/lua/lmtenginelib.c index 8e99aa29a..b9a647775 100644 --- a/source/luametatex/source/lua/lmtenginelib.c +++ b/source/luametatex/source/lua/lmtenginelib.c @@ -313,6 +313,7 @@ static void enginelib_show_credits(void) " decnumber : Mike Cowlishaw from IBM (one of the number models in MP)\n" " avl : Richard (adapted a bit to fit in)\n" " hjn : Raph Levien (derived from TeX's hyphenator, but adapted again)\n" + " softposit : S. H. Leong (Cerlane)\n" "\n" "The code base contains more names and references. Some libraries are partially adapted or\n" "have been replaced. The MetaPost library has additional functionality, some of which is\n" @@ -899,6 +900,7 @@ static const luaL_Reg lmt_libs_extra_function_list[] = { { "xmath", luaopen_xmath }, { "xcomplex", luaopen_xcomplex }, { "xdecimal", luaopen_xdecimal }, + { "posit", luaopen_posit }, { NULL, NULL }, }; diff --git a/source/luametatex/source/lua/lmtfontlib.c b/source/luametatex/source/lua/lmtfontlib.c index 9850d59e7..f743f960e 100644 --- a/source/luametatex/source/lua/lmtfontlib.c +++ b/source/luametatex/source/lua/lmtfontlib.c @@ -332,6 +332,10 @@ static void fontlib_aux_font_char_from_lua(lua_State *L, halfword f, int i, int if (target) { set_charinfo_tag(co, extend_last_tag); } + set_boolean_field_by_index(target, keepbase, 0); + if (target) { + set_charinfo_tag(co, keep_base_tag); + } lua_push_key(parts); if (lua_rawget(L, -2) == LUA_TTABLE) { set_charinfo_tag(co, extensible_tag); diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h index 2636ea2d7..47460acac 100644 --- a/source/luametatex/source/lua/lmtinterface.h +++ b/source/luametatex/source/lua/lmtinterface.h @@ -94,6 +94,8 @@ extern int luaextend_io (lua_State *L); extern int luaextend_string (lua_State *L); extern int luaextend_xcomplex (lua_State *L); +extern int luaopen_posit (lua_State *L); + /*tex We finetune the string hasher. When playing with \LUAJIT\ we found that its hashes was pretty @@ -784,6 +786,8 @@ make_lua_key(L, internal_int);\ make_lua_key(L, internal_int_reference);\ make_lua_key(L, internal_mu_glue);\ make_lua_key(L, internal_mu_glue_reference);\ +make_lua_key(L, internal_posit);\ +make_lua_key(L, internal_posit_reference);\ make_lua_key(L, internal_toks);\ make_lua_key(L, internal_toks_reference);\ make_lua_key(L, internaldimension);\ @@ -795,6 +799,7 @@ make_lua_key(L, italic);\ make_lua_key(L, italic_correction);\ make_lua_key(L, italiccorrection);\ make_lua_key(L, iterator_value);\ +make_lua_key(L, keepbase);\ make_lua_key(L, kern);\ make_lua_key(L, kerns);\ make_lua_key(L, language);\ @@ -1008,6 +1013,7 @@ make_lua_key(L, permitall);\ make_lua_key(L, permitglue);\ make_lua_key(L, permitmathreplace);\ make_lua_key(L, phantom);\ +make_lua_key(L, posit);\ make_lua_key(L, post);\ make_lua_key(L, post_linebreak);\ make_lua_key(L, postadjust);\ @@ -1093,6 +1099,8 @@ make_lua_key(L, register_int);\ make_lua_key(L, register_int_reference);\ make_lua_key(L, register_mu_glue);\ make_lua_key(L, register_mu_glue_reference);\ +make_lua_key(L, register_posit);\ +make_lua_key(L, register_posit_reference);\ make_lua_key(L, register_toks);\ make_lua_key(L, register_toks_reference);\ make_lua_key(L, registerdimension);\ @@ -1577,15 +1585,21 @@ inline static int lmt_roundnumber(lua_State *L, int i) return n == 0.0 ? 0 : lround(n); } +inline static unsigned int lmt_uroundnumber(lua_State *L, int i) +{ + double n = lua_tonumber(L, i); + return n == 0.0 ? 0 : (unsigned int) lround(n); +} + inline static int lmt_optroundnumber(lua_State *L, int i, int dflt) { double n = luaL_optnumber(L, i, dflt); return n == 0.0 ? 0 : lround(n); } -inline static unsigned int lmt_uroundnumber(lua_State *L, int i) +inline static int lmt_opturoundnumber(lua_State *L, int i, int dflt) { - double n = lua_tonumber(L, i); + double n = luaL_optnumber(L, i, dflt); return n == 0.0 ? 0 : (unsigned int) lround(n); } @@ -1609,7 +1623,7 @@ inline static void lua_set_string_by_key(lua_State *L, const char *a, const char lua_setfield(L, -2, a); } -inline static void lua_set_string_by_index(lua_State *L, int a, const char *b) +inline static void lua_set_string_by_index(lua_State *L, lua_Integer a, const char *b) { lua_pushstring(L, b ? b : ""); lua_rawseti(L, -2, a); diff --git a/source/luametatex/source/lua/lmtmplib.c b/source/luametatex/source/lua/lmtmplib.c index e7df5e963..660499e7f 100644 --- a/source/luametatex/source/lua/lmtmplib.c +++ b/source/luametatex/source/lua/lmtmplib.c @@ -49,6 +49,7 @@ static const char *mplib_math_options[] = { "double", "binary", /* not available in luatex */ "decimal", + "posit", NULL }; diff --git a/source/luametatex/source/lua/lmtstatuslib.c b/source/luametatex/source/lua/lmtstatuslib.c index 841ddeec0..ee785e806 100644 --- a/source/luametatex/source/lua/lmtstatuslib.c +++ b/source/luametatex/source/lua/lmtstatuslib.c @@ -329,6 +329,7 @@ static int statslib_getconstants(lua_State *L) lua_set_integer_by_key(L, "max_toks_register_index", max_toks_register_index); lua_set_integer_by_key(L, "max_box_register_index", max_box_register_index); lua_set_integer_by_key(L, "max_int_register_index", max_int_register_index); + lua_set_integer_by_key(L, "max_float_register_index", max_posit_register_index); lua_set_integer_by_key(L, "max_dimen_register_index", max_dimen_register_index); lua_set_integer_by_key(L, "max_attribute_register_index", max_attribute_register_index); lua_set_integer_by_key(L, "max_glue_register_index", max_glue_register_index); diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c index 426ca222b..39afd94fb 100644 --- a/source/luametatex/source/lua/lmttexlib.c +++ b/source/luametatex/source/lua/lmttexlib.c @@ -37,6 +37,7 @@ # define TEX_METATABLE_MUSKIP "tex.muskip" # define TEX_METATABLE_MUGLUE "tex.muglue" # define TEX_METATABLE_DIMEN "tex.dimen" +# define TEX_METATABLE_FLOAT "tex.float" # define TEX_METATABLE_COUNT "tex.count" # define TEX_METATABLE_TOKS "tex.toks" # define TEX_METATABLE_BOX "tex.box" @@ -1709,6 +1710,39 @@ static int texlib_getcount(lua_State *L) return 1; } +static int texlib_isfloat(lua_State *L) +{ + return texlib_aux_checked_register(L, register_posit_cmd, register_posit_base, max_posit_register_index, posit_cmd); +} + +static int texlib_setfloat(lua_State *L) +{ + int flags = 0; + int index = 0; + int slot = lmt_check_for_flags(L, 1, &flags, 1, 0); + int state = texlib_aux_check_for_index(L, slot++, "float", &index, internal_posit_cmd, register_posit_cmd, internal_posit_base, register_posit_base, max_posit_register_index, posit_cmd); + if (state >= 0) { + halfword value = tex_double_to_posit(luaL_optnumber(L, slot++, 0)).v; + if (state == 2) { + tex_define(flags, index, posit_cmd, value); + } else { + tex_set_tex_count_register(index, value, flags, state); + if (state == 1 && lua_toboolean(L, slot)) { + tex_update_par_par(internal_posit_cmd, index); + } + } + } + return 0; +} + +static int texlib_getfloat(lua_State *L) +{ + int index; + int state = texlib_aux_check_for_index(L, 1, "float", &index, internal_posit_cmd, register_posit_cmd, internal_posit_base, register_posit_base, max_posit_register_index, posit_cmd); + lua_pushnumber(L, tex_posit_to_double(state >= 0 ? (state == 2 ? eq_value(index) : tex_get_tex_posit_register(index, state)) : 0)); + return 1; +} + static int texlib_isattribute(lua_State *L) { return texlib_aux_checked_register(L, register_attribute_cmd, register_attribute_base, max_attribute_register_index, -1); @@ -2561,6 +2595,29 @@ static int texlib_set_item(lua_State* L, int index, int prefixes) break; } return 1; + case internal_posit_cmd: + case register_posit_cmd: /* ? */ + switch (lua_type(L, slot)) { + case LUA_TNUMBER: + { + int n = tex_double_to_posit(lua_tonumber(L, slot++)).v; + if (cmd == register_posit_cmd) { + tex_word_define(flags, eq_value(cs), n); + } else { + tex_assign_internal_posit_value(lua_toboolean(L, slot) ? add_frozen_flag(flags) : flags, eq_value(cs), n); + } + break; + } + // case userdata: + // { + // /* todo */ + // break; + // } + default: + luaL_error(L, "number expected"); + break; + } + return 1; case internal_dimen_cmd: case register_dimen_cmd: { @@ -2781,6 +2838,9 @@ static int texlib_aux_scan_internal(lua_State *L, int cmd, int code, int values) case attr_val_level: lua_pushinteger(L, cur_val); break; + case posit_val_level: + lua_pushnumber(L, tex_posit_to_double(cur_val)); + break; case glue_val_level: case mu_val_level: switch (values) { @@ -2874,6 +2934,7 @@ static int texlib_aux_someitem(lua_State *L, int code) case font_char_dp_code: case font_char_ic_code: case font_char_ta_code: + case font_char_ba_code: /* these read a char, todo */ break; case font_size_code: @@ -3126,6 +3187,8 @@ static int texlib_get_internal(lua_State *L, int index, int all) case register_int_cmd: case internal_attribute_cmd: case register_attribute_cmd: + case internal_posit_cmd: + case register_posit_cmd: case internal_dimen_cmd: case register_dimen_cmd: case lua_value_cmd: @@ -3134,6 +3197,7 @@ static int texlib_get_internal(lua_State *L, int index, int all) case set_page_property_cmd: case char_given_cmd: case integer_cmd: + case posit_cmd: case dimension_cmd: case gluespec_cmd: case mugluespec_cmd: @@ -4695,6 +4759,46 @@ static int texlib_setintegervalue(lua_State *L) return 0; } +static int texlib_setfloatvalue(lua_State *L) +{ + size_t len; + const char *str = lua_tolstring(L, 1, &len); + if (len > 0) { + int cs = tex_string_locate(str, len, 1); + int flags = 0; + lmt_check_for_flags(L, 3, &flags, 1, 0); + if (tex_define_permitted(cs, flags)) { + unsigned value = tex_double_to_posit(luaL_optnumber(L, 2, 0)).v; + if (value >= min_posit && value <= max_posit) { + tex_define(flags, cs, (quarterword) posit_cmd, value); + } else { + tex_formatted_error("lua", "posit only accepts values in the range %i-%i", min_posit, max_posit); + } + } + } + return 0; +} + +static int texlib_setcardinalvalue(lua_State *L) +{ + size_t len; + const char *str = lua_tolstring(L, 1, &len); + if (len > 0) { + int cs = tex_string_locate(str, len, 1); + int flags = 0; + lmt_check_for_flags(L, 3, &flags, 1, 0); + if (tex_define_permitted(cs, flags)) { + unsigned value = lmt_opturoundnumber(L, 2, 0); + if (value >= min_cardinal && value <= max_cardinal) { + tex_define(flags, cs, (quarterword) integer_cmd, value); + } else { + tex_formatted_error("lua", "cardinal only accepts values in the range %d-%d", min_cardinal, max_cardinal); + } + } + } + return 0; +} + static int texlib_setdimensionvalue(lua_State *L) { size_t len; @@ -4727,7 +4831,11 @@ static int texlib_aux_getvalue(lua_State *L, halfword level, halfword cs) halfword value = 0; tex_begin_inserted_list(tex_get_available_token(cs_token_flag + cs)); if (tex_scan_tex_value(level, &value)) { - lua_pushinteger(L, value); + if (level == posit_val_level) { + lua_pushnumber(L, tex_posit_to_double(value)); + } else { + lua_pushinteger(L, value); + } return 1; } } @@ -4760,6 +4868,31 @@ static int texlib_getintegervalue(lua_State *L) /* todo, now has duplicate in to return 1; } +static int texlib_getfloatvalue(lua_State *L) /* todo, now has duplicate in tokenlib */ +{ + if (lua_type(L, 1) == LUA_TSTRING) { + size_t len; + const char *str = lua_tolstring(L, 1, &len); + if (len > 0) { + int cs = tex_string_locate(str, len, 0); + switch (eq_type(cs)) { + case posit_cmd: + lua_pushnumber(L, tex_posit_to_double(eq_value(cs))); + return 1; + case call_cmd: + case protected_call_cmd: + case semi_protected_call_cmd: + return texlib_aux_getvalue(L, posit_val_level, cs); + default: + /* twice a lookup but fast enough for now */ + return texlib_getfloat(L); + } + } + } + lua_pushnil(L); + return 1; +} + static int texlib_getdimensionvalue(lua_State *L) /* todo, now has duplicate in tokenlib */ { if (lua_type(L, 1) == LUA_TSTRING) { @@ -4771,6 +4904,9 @@ static int texlib_getdimensionvalue(lua_State *L) /* todo, now has duplicate in case dimension_cmd: lua_pushinteger(L, eq_value(cs)); return 1; + case posit_cmd: + lua_pushinteger(L, tex_posit_to_dimension(eq_value(cs))); + return 1; case call_cmd: case protected_call_cmd: case semi_protected_call_cmd: @@ -4831,6 +4967,12 @@ static int texlib_setrunstate(lua_State *L) return 0; } +/*tex + todo: Some of these keywords can be removed from the interface keys, saves bytes and never accessed + as key. +*/ + + static int texlib_gethyphenationvalues(lua_State *L) { lua_createtable(L, 2, 17); @@ -4915,6 +5057,9 @@ static int texlib_getnoadoptionvalues(lua_State *L) lua_push_key_at_index(L, stretch, noad_option_stretch); lua_push_key_at_index(L, center, noad_option_center); lua_push_key_at_index(L, scale, noad_option_scale); + lua_push_key_at_index(L, keepbase, noad_option_keep_base); + + // lua_set_string_by_index(L, noad_option_keep_base, "keepbase"); return 1; } @@ -5483,6 +5628,9 @@ static const struct luaL_Reg texlib_function_list[] = { { "isdimen", texlib_isdimen }, { "setdimen", texlib_setdimen }, { "getdimen", texlib_getdimen }, + { "isfloat", texlib_isfloat }, + { "setfloat", texlib_setfloat }, + { "getfloat", texlib_getfloat }, { "isskip", texlib_isskip }, { "setskip", texlib_setskip }, { "getskip", texlib_getskip }, @@ -5597,6 +5745,11 @@ static const struct luaL_Reg texlib_function_list[] = { { "integerdef", texlib_setintegervalue }, { "setintegervalue", texlib_setintegervalue }, { "getintegervalue", texlib_getintegervalue }, + { "positdef", texlib_setfloatvalue }, + { "setpositvalue", texlib_setfloatvalue }, + { "getpositvalue", texlib_getfloatvalue }, + { "setcardinalvalue", texlib_setcardinalvalue }, + { "getcardinalvalue", texlib_getintegervalue }, { "dimensiondef", texlib_setdimensionvalue }, { "setdimensionvalue", texlib_setdimensionvalue }, { "getdimensionvalue", texlib_getdimensionvalue }, @@ -5680,6 +5833,7 @@ defineindexers(muskip) defineindexers(muglue) defineindexers(dimen) defineindexers(count) +defineindexers(float) defineindexers(toks) defineindexers(box) defineindexers(sfcode) @@ -5712,6 +5866,7 @@ int luaopen_tex(lua_State *L) lmt_make_table(L, "muglue", TEX_METATABLE_MUGLUE, texlib_index_muglue, texlib_newindex_muglue); lmt_make_table(L, "dimen", TEX_METATABLE_DIMEN, texlib_index_dimen, texlib_newindex_dimen); lmt_make_table(L, "count", TEX_METATABLE_COUNT, texlib_index_count, texlib_newindex_count); + lmt_make_table(L, "posit", TEX_METATABLE_FLOAT, texlib_index_float, texlib_newindex_float); lmt_make_table(L, "toks", TEX_METATABLE_TOKS, texlib_index_toks, texlib_newindex_toks); lmt_make_table(L, "box", TEX_METATABLE_BOX, texlib_index_box, texlib_newindex_box); lmt_make_table(L, "sfcode", TEX_METATABLE_SFCODE, texlib_index_sfcode, texlib_newindex_sfcode); diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c index 5259a1478..1b50f18d2 100644 --- a/source/luametatex/source/lua/lmttokenlib.c +++ b/source/luametatex/source/lua/lmttokenlib.c @@ -163,6 +163,8 @@ void lmt_tokenlib_initialize(void) lmt_interface.command_names[register_int_cmd] = (command_item) { .id = register_int_cmd, .lua = lua_key_index(register_int), .name = lua_key(register_int), .kind = register_command_item, .min = 0, .max = max_int_register_index, .base = register_int_base, .fixedvalue = 0 }; lmt_interface.command_names[internal_attribute_cmd] = (command_item) { .id = internal_attribute_cmd, .lua = lua_key_index(internal_attribute), .name = lua_key(internal_attribute), .kind = unused_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[register_attribute_cmd] = (command_item) { .id = register_attribute_cmd, .lua = lua_key_index(register_attribute), .name = lua_key(register_attribute), .kind = register_command_item, .min = 0, .max = max_attribute_register_index, .base = register_attribute_base, .fixedvalue = 0 }; + lmt_interface.command_names[internal_posit_cmd] = (command_item) { .id = internal_posit_cmd, .lua = lua_key_index(internal_posit), .name = lua_key(internal_posit), .kind = unused_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; + lmt_interface.command_names[register_posit_cmd] = (command_item) { .id = register_posit_cmd, .lua = lua_key_index(register_posit), .name = lua_key(register_posit), .kind = register_command_item, .min = 0, .max = max_posit_register_index, .base = register_posit_base, .fixedvalue = 0 }; lmt_interface.command_names[internal_dimen_cmd] = (command_item) { .id = internal_dimen_cmd, .lua = lua_key_index(internal_dimen), .name = lua_key(internal_dimen), .kind = internal_command_item, .min = first_dimen_code, .max = last_dimen_code, .base = internal_dimen_base, .fixedvalue = 0 }; lmt_interface.command_names[register_dimen_cmd] = (command_item) { .id = register_dimen_cmd, .lua = lua_key_index(register_dimen), .name = lua_key(register_dimen), .kind = register_command_item, .min = 0, .max = max_dimen_register_index, .base = register_dimen_base, .fixedvalue = 0 }; lmt_interface.command_names[internal_glue_cmd] = (command_item) { .id = internal_glue_cmd, .lua = lua_key_index(internal_glue), .name = lua_key(internal_glue), .kind = internal_command_item, .min = first_glue_code, .max = last_glue_code, .base = internal_glue_base, .fixedvalue = 0 }; @@ -183,6 +185,7 @@ void lmt_tokenlib_initialize(void) lmt_interface.command_names[set_font_cmd] = (command_item) { .id = set_font_cmd, .lua = lua_key_index(set_font), .name = lua_key(set_font), .kind = data_command_item, .min = 0, .max = max_font_size, .base = 0, .fixedvalue = 0 }; lmt_interface.command_names[define_font_cmd] = (command_item) { .id = define_font_cmd, .lua = lua_key_index(define_font), .name = lua_key(define_font), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[integer_cmd] = (command_item) { .id = integer_cmd, .lua = lua_key_index(integer), .name = lua_key(integer), .kind = data_command_item, .min = min_integer, .max = max_integer, .base = direct_entry, .fixedvalue = 0 }; + lmt_interface.command_names[posit_cmd] = (command_item) { .id = posit_cmd, .lua = lua_key_index(posit), .name = lua_key(posit), .kind = data_command_item, .min = min_posit, .max = max_posit, .base = direct_entry, .fixedvalue = 0 }; lmt_interface.command_names[dimension_cmd] = (command_item) { .id = dimension_cmd, .lua = lua_key_index(dimension), .name = lua_key(dimension), .kind = data_command_item, .min = min_dimen, .max = max_dimen, .base = direct_entry, .fixedvalue = 0 }; lmt_interface.command_names[gluespec_cmd] = (command_item) { .id = gluespec_cmd, .lua = lua_key_index(gluespec), .name = lua_key(gluespec), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[mugluespec_cmd] = (command_item) { .id = mugluespec_cmd, .lua = lua_key_index(mugluespec), .name = lua_key(mugluespec), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; @@ -232,6 +235,8 @@ void lmt_tokenlib_initialize(void) lmt_interface.command_names[register_int_reference_cmd] = (command_item) { .id = register_int_reference_cmd, .lua = lua_key_index(register_int_reference), .name = lua_key(register_int_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[internal_attribute_reference_cmd] = (command_item) { .id = internal_attribute_reference_cmd, .lua = lua_key_index(internal_attribute_reference), .name = lua_key(internal_attribute_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[register_attribute_reference_cmd] = (command_item) { .id = register_attribute_reference_cmd, .lua = lua_key_index(register_attribute_reference), .name = lua_key(register_attribute_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; + lmt_interface.command_names[internal_posit_reference_cmd] = (command_item) { .id = internal_posit_reference_cmd, .lua = lua_key_index(internal_posit_reference), .name = lua_key(internal_posit_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; + lmt_interface.command_names[register_posit_reference_cmd] = (command_item) { .id = register_posit_reference_cmd, .lua = lua_key_index(register_posit_reference), .name = lua_key(register_posit_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[internal_dimen_reference_cmd] = (command_item) { .id = internal_dimen_reference_cmd, .lua = lua_key_index(internal_dimen_reference), .name = lua_key(internal_dimen_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[register_dimen_reference_cmd] = (command_item) { .id = register_dimen_reference_cmd, .lua = lua_key_index(register_dimen_reference), .name = lua_key(register_dimen_reference), .kind = regular_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; lmt_interface.command_names[register_dimen_reference_cmd + 1] = (command_item) { .id = unknown_value, .lua = 0, .name = NULL, .kind = unused_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 }; @@ -900,8 +905,9 @@ static int tokenlib_scan_integer(lua_State *L) static int tokenlib_scan_cardinal(lua_State *L) { saved_tex_scanner texstate = tokenlib_aux_save_tex_scanner(); + int eq = lua_toboolean(L, 1); unsigned int v = 0; - tex_scan_cardinal(&v, 0); + tex_scan_cardinal(eq, &v, 0); lua_pushinteger(L, (unsigned int) v); tokenlib_aux_unsave_tex_scanner(texstate); return 1; @@ -1145,20 +1151,36 @@ static int tokenlib_scan_integer_indeed(lua_State *L, int cardinal) tokenlib_aux_goto_first_candidate_x(); } /*tex we collapse as in |scan_dimen| */ - if (! cardinal) { - while(1) { - if (cur_tok == minus_token) { - negative = ! negative; - } else if (cur_tok != plus_token) { - break; - } - tokenlib_aux_goto_first_candidate_x(); +// if (! cardinal) { +// while(1) { +// if (cur_tok == minus_token) { +// negative = ! negative; +// } else if (cur_tok != plus_token) { +// break; +// } +// tokenlib_aux_goto_first_candidate_x(); +// } +// if (negative) { +// luaL_addchar(&b, '-'); +// } +// } else if (cur_tok == minus_token) { +// tex_normal_warning("scanner", "positive number expected, ignoring minus sign"); +// tokenlib_aux_goto_first_candidate_x(); +// } + while(1) { + if (cur_tok == minus_token) { + negative = ! negative; + } else if (cur_tok != plus_token) { + break; } - if (negative) { + tokenlib_aux_goto_first_candidate_x(); + } + if (negative) { + if (cardinal) { + tex_normal_warning("scanner", "positive number expected, ignoring minus sign"); + } else { luaL_addchar(&b, '-'); } - } else if (cur_tok == minus_token) { - tex_normal_warning("scanner", "positive number expected, ignoring minus sign"); tokenlib_aux_goto_first_candidate_x(); } if (cur_tok == zero_token) { @@ -3009,9 +3031,9 @@ static int tokenlib_get_meaning(lua_State *L) int chr = eq_value(cs); if (lua_toboolean(L, 2)) { if (lua_toboolean(L, 3)) { - lmt_token_list_to_lua(L, token_link(chr)); + lmt_token_list_to_lua(L, token_link(chr)); /* makes table sub tables */ } else { - lmt_token_register_to_lua(L, chr); + lmt_token_register_to_lua(L, chr); /* makes table */ } } else { char *str = tex_tokenlist_to_tstring(chr, 1, NULL, 0, 0, 0, 0); @@ -3069,6 +3091,8 @@ static void tokenlib_aux_expand_macros_in_tokenlist(halfword p) tex_end_token_list(); } +/* token.getmacro(t[,true][,true] : [also preamble] [only preamble] */ + static int tokenlib_get_macro(lua_State *L) { if (lua_type(L, 1) == LUA_TSTRING) { @@ -3083,7 +3107,7 @@ static int tokenlib_get_macro(lua_State *L) 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, 1); } else { - str = tex_tokenlist_to_tstring(chr, 1, NULL, 1, 0, 0, 0); + str = tex_tokenlist_to_tstring(chr, 1, NULL, lua_toboolean(L, 3) ? 2 : 1, 0, 0, 0); } lua_pushstring(L, str ? str : ""); return 1; |