summaryrefslogtreecommitdiff
path: root/source/luametatex/source/lua
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r--source/luametatex/source/lua/lmtfontlib.c6
-rw-r--r--source/luametatex/source/lua/lmtinterface.h6
-rw-r--r--source/luametatex/source/lua/lmttexlib.c25
-rw-r--r--source/luametatex/source/lua/lmttokenlib.c91
4 files changed, 75 insertions, 53 deletions
diff --git a/source/luametatex/source/lua/lmtfontlib.c b/source/luametatex/source/lua/lmtfontlib.c
index 042772b32..f8ca2a37a 100644
--- a/source/luametatex/source/lua/lmtfontlib.c
+++ b/source/luametatex/source/lua/lmtfontlib.c
@@ -825,7 +825,7 @@ static int fontlib_id(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t l;
const char *s = lua_tolstring(L, 1, &l);
- int cs = tex_string_locate(s, l, 0);
+ int cs = tex_string_locate_only(s, l);
int f = -1;
if (cs == undefined_control_sequence || cs == undefined_cs_cmd || eq_type(cs) != set_font_cmd) {
lua_pushliteral(L, "not a valid font csname");
@@ -903,7 +903,7 @@ static int fontlib_getmathspec(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- halfword cs = tex_string_locate(name, lname, 0);
+ halfword cs = tex_string_locate_only(name, lname);
if (eq_type(cs) == mathspec_cmd) {
halfword ms = eq_value(cs);
if (ms) {
@@ -923,7 +923,7 @@ static int fontlib_getfontspec(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- halfword cs = tex_string_locate(name, lname, 0);
+ halfword cs = tex_string_locate_only(name, lname);
if (eq_type(cs) == fontspec_cmd) {
halfword fs = eq_value(cs);
if (fs) {
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h
index ea6ead4ab..1dc47cf15 100644
--- a/source/luametatex/source/lua/lmtinterface.h
+++ b/source/luametatex/source/lua/lmtinterface.h
@@ -553,6 +553,7 @@ make_lua_key(L, conditional);\
make_lua_key(L, conditionalmathskip);\
make_lua_key(L, connectoroverlapmin);\
make_lua_key(L, constant);\
+make_lua_key(L, constant_call);\
make_lua_key(L, container);\
make_lua_key(L, contributehead);\
make_lua_key(L, convert);\
@@ -568,8 +569,9 @@ make_lua_key(L, cs_name);\
make_lua_key(L, csname);\
make_lua_key(L, current);\
make_lua_key(L, data);\
-make_lua_key(L, deep_frozen_cs_dont_expand);\
-make_lua_key(L, deep_frozen_cs_end_template);\
+make_lua_key(L, deep_frozen_dont_expand);\
+make_lua_key(L, deep_frozen_end_template);\
+make_lua_key(L, deep_frozen_keep_constant);\
make_lua_key(L, def);\
make_lua_key(L, deferred);\
make_lua_key(L, define_char_code);\
diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c
index 603454bfe..08809e198 100644
--- a/source/luametatex/source/lua/lmttexlib.c
+++ b/source/luametatex/source/lua/lmttexlib.c
@@ -557,7 +557,7 @@ static int texlib_mprint(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- int cs = tex_string_locate(name, lname, 0);
+ int cs = tex_string_locate_only(name, lname);
int cmd = eq_type(cs);
if (is_call_cmd(cmd)) {
texlib_aux_store_token(cs_token_flag + cs, partial_line_mode, default_catcode_table_preset);
@@ -1185,7 +1185,7 @@ inline static int texlib_aux_valid_register_index(lua_State *L, int slot, int cm
{
size_t len;
const char *str = lua_tolstring(L, 1, &len);
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
if (eq_type(cs) == cmd) {
index = eq_value(cs) - base;
} else if (eq_type(cs) == constant_cmd) {
@@ -1213,7 +1213,7 @@ static int texlib_get_register_index(lua_State *L)
{
size_t len;
const char *str = lua_tolstring(L, 1, &len);
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
int index = -1;
switch (eq_type(cs)) {
case register_toks_cmd : index = eq_value(cs) - register_toks_base; break;
@@ -1348,7 +1348,7 @@ static int texlib_aux_check_for_index(
{
size_t len;
const char *str = lua_tolstring(L, slot, &len);
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
if (eq_type(cs) == internal_cmd) {
*index = eq_value(cs) - internal_base;
return 1;
@@ -1903,7 +1903,7 @@ int lmt_get_box_id(lua_State *L, int i, int report)
{
size_t len = 0;
const char *str = lua_tolstring(L, i, &len);
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
int cmd = eq_type(cs);
switch (cmd) {
case char_given_cmd:
@@ -2573,7 +2573,7 @@ static int texlib_set_item(lua_State* L, int index, int prefixes)
size_t sl;
const char *st = lua_tolstring(L, slot++, &sl);
if (sl > 0) {
- int cs = tex_string_locate(st, sl, 0);
+ int cs = tex_string_locate_only(st, sl);
if (cs != undefined_control_sequence && has_eq_flag_bits(cs, primitive_flag_bit)) {
int cmd = eq_type(cs);
switch (cmd) {
@@ -3173,7 +3173,7 @@ static int texlib_get_internal(lua_State *L, int index, int all)
int cmd = get_prim_eq_type(cs);
int code = get_prim_equiv(cs);
*/
- int cs = tex_string_locate(s, l, 0);
+ int cs = tex_string_locate_only(s, l);
if (cs != undefined_control_sequence && has_eq_flag_bits(cs, primitive_flag_bit)) {
int cmd = eq_type(cs);
int code = eq_value(cs);
@@ -4280,7 +4280,7 @@ static int texlib_runlocal(lua_State *L)
{
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- int cs = tex_string_locate(name, lname, 0);
+ int cs = tex_string_locate_only(name, lname);
int cmd = eq_type(cs);
if (cmd < call_cmd) { // is_call_cmd
// todo: use the better register helpers and range checkers
@@ -4850,7 +4850,7 @@ static int texlib_getintegervalue(lua_State *L) /* todo, now has duplicate in to
size_t len;
const char *str = lua_tolstring(L, 1, &len);
if (len > 0) {
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
switch (eq_type(cs)) {
case integer_cmd:
lua_pushinteger(L, eq_value(cs));
@@ -4858,6 +4858,7 @@ static int texlib_getintegervalue(lua_State *L) /* todo, now has duplicate in to
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
return texlib_aux_getvalue(L, int_val_level, cs);
default:
/* twice a lookup but fast enough for now */
@@ -4875,7 +4876,7 @@ static int texlib_getfloatvalue(lua_State *L) /* todo, now has duplicate in toke
size_t len;
const char *str = lua_tolstring(L, 1, &len);
if (len > 0) {
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
switch (eq_type(cs)) {
case posit_cmd:
lua_pushnumber(L, tex_posit_to_double(eq_value(cs)));
@@ -4883,6 +4884,7 @@ static int texlib_getfloatvalue(lua_State *L) /* todo, now has duplicate in toke
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
return texlib_aux_getvalue(L, posit_val_level, cs);
default:
/* twice a lookup but fast enough for now */
@@ -4900,7 +4902,7 @@ static int texlib_getdimensionvalue(lua_State *L) /* todo, now has duplicate in
size_t len;
const char *str = lua_tolstring(L, 1, &len);
if (len > 0) {
- int cs = tex_string_locate(str, len, 0);
+ int cs = tex_string_locate_only(str, len);
switch (eq_type(cs)) {
case dimension_cmd:
lua_pushinteger(L, eq_value(cs));
@@ -4911,6 +4913,7 @@ static int texlib_getdimensionvalue(lua_State *L) /* todo, now has duplicate in
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
return texlib_aux_getvalue(L, dimen_val_level, cs);
default:
/* twice a lookup but fast enough for now */
diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c
index fe82e7e40..e4ec867f0 100644
--- a/source/luametatex/source/lua/lmttokenlib.c
+++ b/source/luametatex/source/lua/lmttokenlib.c
@@ -215,12 +215,14 @@ void lmt_tokenlib_initialize(void)
lmt_interface.command_names[get_mark_cmd] = (command_item) { .id = get_mark_cmd, .lua = lua_key_index(get_mark), .name = lua_key(get_mark), .kind = regular_command_item, .min = 0, .max = last_get_mark_code, .base = 0, .fixedvalue = 0 };
lmt_interface.command_names[call_cmd] = (command_item) { .id = call_cmd, .lua = lua_key_index(call), .name = lua_key(call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[protected_call_cmd] = (command_item) { .id = protected_call_cmd, .lua = lua_key_index(protected_call), .name = lua_key(protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
- lmt_interface.command_names[semi_protected_call_cmd] = (command_item) { .id = semi_protected_call_cmd, .lua = lua_key_index(semi_protected_call), .name = lua_key(protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[semi_protected_call_cmd] = (command_item) { .id = semi_protected_call_cmd, .lua = lua_key_index(semi_protected_call), .name = lua_key(semi_protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[constant_call_cmd] = (command_item) { .id = constant_call_cmd, .lua = lua_key_index(constant_call), .name = lua_key(constant_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[tolerant_call_cmd] = (command_item) { .id = tolerant_call_cmd, .lua = lua_key_index(tolerant_call), .name = lua_key(tolerant_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[tolerant_protected_call_cmd] = (command_item) { .id = tolerant_protected_call_cmd, .lua = lua_key_index(tolerant_protected_call), .name = lua_key(tolerant_protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
- lmt_interface.command_names[tolerant_semi_protected_call_cmd] = (command_item) { .id = tolerant_semi_protected_call_cmd, .lua = lua_key_index(tolerant_semi_protected_call), .name = lua_key(tolerant_protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
- lmt_interface.command_names[deep_frozen_end_template_cmd] = (command_item) { .id = deep_frozen_end_template_cmd, .lua = lua_key_index(deep_frozen_cs_end_template), .name = lua_key(deep_frozen_cs_end_template), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
- lmt_interface.command_names[deep_frozen_dont_expand_cmd] = (command_item) { .id = deep_frozen_dont_expand_cmd, .lua = lua_key_index(deep_frozen_cs_dont_expand), .name = lua_key(deep_frozen_cs_dont_expand), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[tolerant_semi_protected_call_cmd] = (command_item) { .id = tolerant_semi_protected_call_cmd, .lua = lua_key_index(tolerant_semi_protected_call), .name = lua_key(tolerant_semi_protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[deep_frozen_end_template_cmd] = (command_item) { .id = deep_frozen_end_template_cmd, .lua = lua_key_index(deep_frozen_end_template), .name = lua_key(deep_frozen_end_template), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[deep_frozen_dont_expand_cmd] = (command_item) { .id = deep_frozen_dont_expand_cmd, .lua = lua_key_index(deep_frozen_dont_expand), .name = lua_key(deep_frozen_dont_expand), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
+ lmt_interface.command_names[deep_frozen_keep_constant_cmd] = (command_item) { .id = deep_frozen_keep_constant_cmd, .lua = lua_key_index(deep_frozen_keep_constant), .name = lua_key(deep_frozen_keep_constant), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[internal_glue_reference_cmd] = (command_item) { .id = internal_glue_reference_cmd, .lua = lua_key_index(internal_glue_reference), .name = lua_key(internal_glue_reference), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[register_glue_reference_cmd] = (command_item) { .id = register_glue_reference_cmd, .lua = lua_key_index(register_glue_reference), .name = lua_key(register_glue_reference), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[internal_mu_glue_reference_cmd] = (command_item) { .id = internal_mu_glue_reference_cmd, .lua = lua_key_index(internal_mu_glue_reference), .name = lua_key(internal_mu_glue_reference), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
@@ -1445,6 +1447,7 @@ static int tokenlib_scan_detokened(lua_State *L)
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
case tolerant_call_cmd:
case tolerant_protected_call_cmd:
case tolerant_semi_protected_call_cmd:
@@ -1497,10 +1500,12 @@ static int tokenlib_scan_string(lua_State *L)
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
case tolerant_call_cmd:
case tolerant_protected_call_cmd:
case tolerant_semi_protected_call_cmd:
{
+ /*tex It is pretty unlikely to end up here, because we expand. */
halfword t = token_link(cur_chr);
lmt_token_list_to_luastring(L, t, 0, 0, 1);
break;
@@ -1550,24 +1555,41 @@ static int tokenlib_scan_argument(lua_State *L)
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ // case constant_call_cmd:
case tolerant_call_cmd:
case tolerant_protected_call_cmd:
case tolerant_semi_protected_call_cmd:
- {
- halfword result;
- halfword defref = lmt_input_state.def_ref;
- tex_back_input(right_brace_token + '}');
- if (lua_type(L, 1) == LUA_TBOOLEAN && ! lua_toboolean(L, 1)) {
- tex_expand_current_token();
- result = tex_scan_toks_normal(1, NULL);
- } else {
- tex_back_input(cur_tok);
- result = tex_scan_toks_expand(1, NULL, 0);
- }
- lmt_token_list_to_luastring(L, result, 0, 0, 1);
- lmt_input_state.def_ref = defref;
- break;
- }
+ {
+ halfword result;
+ halfword defref = lmt_input_state.def_ref;
+ tex_back_input(right_brace_token + '}');
+ if (lua_type(L, 1) == LUA_TBOOLEAN && ! lua_toboolean(L, 1)) {
+ tex_expand_current_token();
+ result = tex_scan_toks_normal(1, NULL);
+ } else {
+ tex_back_input(cur_tok);
+ result = tex_scan_toks_expand(1, NULL, 0);
+ }
+ lmt_token_list_to_luastring(L, result, 0, 0, 1);
+ lmt_input_state.def_ref = defref;
+ break;
+ }
+ case constant_call_cmd:
+ {
+ halfword h = token_link(cur_chr);
+ if (h) {
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while (h) {
+ tokenlib_aux_add_utf_char_to_buffer(&b, token_chr(token_info(h)));
+ h = token_link(h);
+ }
+ luaL_pushresult(&b);
+ } else {
+ lua_pushliteral(L, "");
+ }
+ break;
+ }
case letter_cmd:
case other_char_cmd:
{
@@ -1694,6 +1716,7 @@ static int tokenlib_scan_delimited(lua_State *L)
switch (cur_cmd) {
case call_cmd:
case tolerant_call_cmd:
+ case constant_call_cmd:
tex_expand_current_token();
goto PICKUP;
case protected_call_cmd:
@@ -2112,6 +2135,7 @@ static int tokenlib_scan_value(lua_State *L)
break;
/*
case call_cmd:
+ case constant_call_cmd:
{
halfword t = cur_cs ? cs_token_flag + cur_cs : token_val(cur_cmd, cur_chr);
if (t >= cs_token_flag) {
@@ -2154,6 +2178,7 @@ static int tokenlib_scan_value(lua_State *L)
case call_cmd:
case protected_call_cmd:
case semi_protected_call_cmd:
+ case constant_call_cmd:
case tolerant_call_cmd:
case tolerant_protected_call_cmd:
case tolerant_semi_protected_call_cmd:
@@ -2307,7 +2332,7 @@ static int tokenlib_is_defined(lua_State *L)
size_t l;
const char *s = lua_tolstring(L, 1, &l);
if (l > 0) {
- int cs = tex_string_locate(s, l, 0);
+ int cs = tex_string_locate_only(s, l);
b = (cs != undefined_control_sequence) && (eq_type(cs) != undefined_cs_cmd);
}
}
@@ -2402,7 +2427,7 @@ static int tokenlib_get_cmdchrcs(lua_State* L)
size_t l;
const char *s = lua_tolstring(L, 1, &l);
if (l > 0) {
- int cs = tex_string_locate(s, l, 0);
+ int cs = tex_string_locate_only(s, l);
int cmd = eq_type(cs);
int chr = eq_value(cs);
if (! lua_toboolean(L, 2)) {
@@ -2457,7 +2482,7 @@ static int tokenlib_get_cstoken(lua_State* L)
size_t l;
const char *s = lua_tolstring(L, 1, &l);
if (l > 0) {
- lua_pushinteger(L, (lua_Integer) tex_string_locate(s, l, 0) + cs_token_flag);
+ lua_pushinteger(L, (lua_Integer) tex_string_locate_only(s, l) + cs_token_flag);
return 1;
}
return 0;
@@ -2774,12 +2799,7 @@ inline static int tokenlib_get_constant(lua_State *L)
{
lua_token *n = tokenlib_aux_check_istoken(L, 1);
halfword tok = token_info(n->token);
- int result = 0;
- if (tok >= cs_token_flag && is_call_cmd(eq_type(tok - cs_token_flag))) {
- halfword v = eq_value(tok - cs_token_flag);
- result = v && get_token_reference(v) == max_token_reference;
- }
- lua_pushboolean(L, result);
+ lua_pushboolean(L, tok >= cs_token_flag && (eq_type(tok - cs_token_flag) == constant_call_cmd));
return 1;
}
@@ -2848,7 +2868,7 @@ static int tokenlib_get_fields(lua_State *L)
if (l > 0) {
halfword cs;
lua_createtable(L, 0, onlyflags ? 0 : 5);
- cs = tex_string_locate(str, l, 0);
+ cs = tex_string_locate_only(str, l);
cmd = eq_type(cs);
chr = eq_value(cs);
flags = eq_flag(cs);
@@ -3087,7 +3107,7 @@ static int tokenlib_get_meaning(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- halfword cs = tex_string_locate(name, lname, 0);
+ halfword cs = tex_string_locate_only(name, lname);
halfword cmd = eq_type(cs);
if (is_call_cmd(cmd)) {
int chr = eq_value(cs);
@@ -3160,7 +3180,7 @@ static int tokenlib_get_macro(lua_State *L)
if (lua_type(L, 1) == LUA_TSTRING) {
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
- halfword cs = tex_string_locate(name, lname, 0);
+ halfword cs = tex_string_locate_only(name, lname);
halfword cmd = eq_type(cs);
if (is_call_cmd(cmd)) {
halfword chr = eq_value(cs);
@@ -3198,7 +3218,7 @@ static int tokenlib_push_macro(lua_State *L) // todo: just store cmd and flag to
size_t lname = 0;
const char *name = lua_tolstring(L, 1, &lname);
if (lname > 0) {
- halfword cs = tex_string_locate(name, lname, 0);
+ halfword cs = tex_string_locate_only(name, lname);
singleword cmd = eq_type(cs);
halfword chr = eq_value(cs);
quarterword global = lua_toboolean(L, 2) ? add_global_flag(0) : 0; /* how */
@@ -3355,9 +3375,6 @@ static int tokenlib_set_macro(lua_State *L) /* todo: protected */
h = get_reference_token();
/*tex Options: 1=create (will trigger an error), 2=ignore. */
tex_parse_str_to_tok(h, null, ct, str, lstr, lua_toboolean(L, slot++) ? 2 : 1);
- if (is_constant(flags)) {
- set_token_reference(h, max_token_reference);
- }
} else {
h = lmt_token_state.empty;
// tex_add_token_reference(h);
@@ -3379,7 +3396,7 @@ halfword lmt_macro_to_tok(lua_State *L, int slot, halfword *tail)
{
size_t lname = 0;
const char *name = lua_tolstring(L, slot, &lname);
- int cs = tex_string_locate(name, lname, 0);
+ int cs = tex_string_locate_only(name, lname);
int cmd = eq_type(cs);
if (is_call_cmd(cmd)) {
tok = cs_token_flag + cs;
@@ -3542,7 +3559,7 @@ static int tokenlib_get_constant_value(lua_State *L, halfword cmd)
size_t l;
const char *s = lua_tolstring(L, 1, &l);
if (l > 0) {
- int cs = tex_string_locate(s, l, 0);
+ int cs = tex_string_locate_only(s, l);
if (eq_type(cs) == cmd) {
lua_pushinteger(L, eq_value(cs));
return 1;