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/lmtinterface.h3
-rw-r--r--source/luametatex/source/lua/lmtstatuslib.c6
-rw-r--r--source/luametatex/source/lua/lmttexlib.c13
-rw-r--r--source/luametatex/source/lua/lmttokenlib.c77
-rw-r--r--source/luametatex/source/lua/lmttokenlib.h2
5 files changed, 66 insertions, 35 deletions
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h
index 67c3f56d5..c60a78266 100644
--- a/source/luametatex/source/lua/lmtinterface.h
+++ b/source/luametatex/source/lua/lmtinterface.h
@@ -562,6 +562,7 @@ make_lua_key(L, condition);\
make_lua_key(L, conditional);\
make_lua_key(L, conditionalmathskip);\
make_lua_key(L, connectoroverlapmin);\
+make_lua_key(L, constant);\
make_lua_key(L, container);\
make_lua_key(L, contributehead);\
make_lua_key(L, convert);\
@@ -1127,6 +1128,7 @@ make_lua_key(L, properties);\
make_lua_key(L, proportional);\
make_lua_key(L, protected);\
make_lua_key(L, protected_call);\
+make_lua_key(L, semi_protected_call);\
make_lua_key(L, protrudechars);\
make_lua_key(L, protrusion);\
make_lua_key(L, ptr);\
@@ -1387,6 +1389,7 @@ make_lua_key(L, tolerance);\
make_lua_key(L, tolerant);\
make_lua_key(L, tolerant_call);\
make_lua_key(L, tolerant_protected_call);\
+make_lua_key(L, tolerant_semi_protected_call);\
make_lua_key(L, top);\
make_lua_key(L, topaccent);\
make_lua_key(L, topaccentvariant);\
diff --git a/source/luametatex/source/lua/lmtstatuslib.c b/source/luametatex/source/lua/lmtstatuslib.c
index cf665ede2..841ddeec0 100644
--- a/source/luametatex/source/lua/lmtstatuslib.c
+++ b/source/luametatex/source/lua/lmtstatuslib.c
@@ -254,8 +254,8 @@ static int statslib_getconstants(lua_State *L)
lua_set_integer_by_key(L, "no_catcode_table", no_catcode_table_preset);
lua_set_integer_by_key(L, "default_catcode_table", default_catcode_table_preset);
- lua_set_cardinal_by_key(L, "max_cardinal", max_cardinal);
- lua_set_cardinal_by_key(L, "min_cardinal", min_cardinal);
+ lua_set_cardinal_by_key(L,"max_cardinal", max_cardinal);
+ lua_set_cardinal_by_key(L,"min_cardinal", min_cardinal);
lua_set_integer_by_key(L, "max_integer", max_integer);
lua_set_integer_by_key(L, "min_integer", min_integer);
lua_set_integer_by_key(L, "max_dimen", max_dimen);
@@ -268,7 +268,7 @@ static int statslib_getconstants(lua_State *L)
lua_set_integer_by_key(L, "one_bp", one_bp);
- lua_set_integer_by_key(L, "infinity", infinity);
+ lua_set_integer_by_key(L, "infinity", max_infinity);
lua_set_integer_by_key(L, "min_infinity", min_infinity);
lua_set_integer_by_key(L, "awful_bad", awful_bad);
lua_set_integer_by_key(L, "infinite_bad", infinite_bad);
diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c
index 7d9395eb7..0d84eebdd 100644
--- a/source/luametatex/source/lua/lmttexlib.c
+++ b/source/luametatex/source/lua/lmttexlib.c
@@ -903,7 +903,7 @@ static const char *texlib_aux_scan_integer_part(lua_State *L, const char *ss, in
DONE:
if (overflow) {
luaL_error(L, "number too big");
- result = infinity;
+ result = max_integer;
} else if (vacuous) {
luaL_error(L, "missing number, treated as zero") ;
}
@@ -1246,6 +1246,9 @@ int lmt_check_for_flags(lua_State *L, int slot, int *flags, int prefixes, int nu
} else if (lua_key_eq(str, value)) {
slot += 1;
*flags = add_value_flag(*flags);
+ } else if (lua_key_eq(str, constant)) {
+ slot += 1;
+ *flags = add_constant_flag(*flags);
} else if (lua_key_eq(str, conditional) || lua_key_eq(str, condition)) {
/* condition will go, conditional stays */
slot += 1;
@@ -2690,7 +2693,7 @@ 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_to_cstring(texstr);
+ const char *str = tex_to_cstring(texstr);
if (str) {
lua_pushstring(L, str);
} else {
@@ -3582,7 +3585,7 @@ static int texlib_enableprimitives(lua_State *L)
for (int cs = 0; cs < prim_size; cs++) {
strnumber s = get_prim_text(cs);
if (s > 0) {
- char *prm = tex_to_cstring(s);
+ const char *prm = tex_to_cstring(s);
texlib_aux_enableprimitive(pre, lpre, prm);
}
}
@@ -4116,7 +4119,7 @@ static int texlib_runlocal(lua_State *L)
} else {
halfword ref = eq_value(cs);
halfword head = token_link(ref);
- if (head && get_token_parameters(ref)) {
+ if (head && get_token_preamble(ref)) {
tex_local_control_message("macro takes arguments and is ignored");
return 0;
} else {
@@ -4605,7 +4608,7 @@ static int texlib_setdimensionvalue(lua_State *L)
static int texlib_aux_getvalue(lua_State *L, halfword level, halfword cs)
{
halfword chr = eq_value(cs);
- if (chr && ! get_token_parameters(chr)) {
+ if (chr && ! get_token_preamble(chr)) { /* or get_token_parameters as we don't want trailing # */
halfword value = 0;
tex_begin_inserted_list(tex_get_available_token(cs_token_flag + cs));
if (tex_scan_tex_value(level, &value)) {
diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c
index 97ca1b144..41ee6c485 100644
--- a/source/luametatex/source/lua/lmttokenlib.c
+++ b/source/luametatex/source/lua/lmttokenlib.c
@@ -213,10 +213,10 @@ void lmt_tokenlib_initialize(void)
/* lmt_interface.command_names[string_cmd] = (command_item) { .id = string_cmd, .lua = lua_key_index(string), .name = lua_key(string), .kind = regular_command_item, .min = ignore_entry, .max = max_integer, .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(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[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_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[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 };
@@ -468,8 +468,9 @@ halfword lmt_token_list_from_lua(lua_State *L, int slot)
if (s[i] == ascii_space) {
tok = token_val(spacer_cmd, s[i]);
} else {
- int k = (int) aux_str2uni((const unsigned char *) (s + i));
- i = i + (size_t) (utf8_size(k)) - 1;
+ int kl;
+ int k = (int) aux_str2uni_len((const unsigned char *) (s + i), &kl);
+ i = i + kl - 1;
tok = token_val(other_char_cmd, k);
}
p = tex_store_new_token(p, tok);
@@ -737,15 +738,15 @@ static void tokenlib_aux_to_token(lua_State *L, int i, int m, int *head, int *ta
const unsigned char *p = (const unsigned char *) s;
size_t n = aux_utf8len(s, l);
for (size_t j = 0; j < n; j++) {
- int ch = *p;
- halfword x = tex_get_available_token(tokenlib_aux_to_token_val(aux_str2uni(p)));
+ int xl;
+ halfword x = tex_get_available_token(tokenlib_aux_to_token_val(aux_str2uni_len(p, &xl)));
if (*head) {
token_link(*tail) = x;
} else {
*head = x;
}
*tail = x;
- p += utf8_size(ch);
+ p += xl;
}
break;
}
@@ -2370,7 +2371,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_to_cstring(s);
+ const char *ss = tex_to_cstring(s);
int cmd = prim_eq_type(cs);
int chr = prim_equiv(cs);
if (! raw) {
@@ -2668,6 +2669,19 @@ inline static int tokenlib_get_parameters(lua_State *L)
return 0;
}
+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);
+ return 1;
+}
+
static int tokenlib_getfield(lua_State *L)
{
const char *s = lua_tostring(L, 2);
@@ -2711,6 +2725,8 @@ static int tokenlib_getfield(lua_State *L)
return tokenlib_get_flags(L);
} else if (lua_key_eq(s, parameters)) {
return tokenlib_get_parameters(L);
+ } else if (lua_key_eq(s, constant)) {
+ return tokenlib_get_constant(L);
} else {
lua_pushnil(L);
}
@@ -3229,11 +3245,17 @@ static int tokenlib_set_macro(lua_State *L) /* todo: protected */
slot = lmt_check_for_flags(L, slot, &flags, 1, 1);
}
if (tex_define_permitted(cs, flags)) { /* we check before we allocate */
- halfword h = get_reference_token();
- halfword t = h;
+ halfword h;
if (lstr > 0) {
+ h = get_reference_token();
/*tex Options: 1=create (will trigger an error), 2=ignore. */
- tex_parse_str_to_tok(h, &t, ct, str, lstr, lua_toboolean(L, slot++) ? 2 : 1);
+ 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);
}
tex_define(flags, cs, tex_flags_to_cmd(flags), h);
}
@@ -3388,7 +3410,7 @@ static int tokenlib_set_char(lua_State *L) /* also in texlib */
/* a weird place, these should be in tex */
-static int tokenlib_set_constant(lua_State *L, singleword cmd, halfword min, halfword max)
+static int tokenlib_set_constant_value(lua_State *L, singleword cmd, halfword min, halfword max)
{
int top = lua_gettop(L);
if (top >= 2) {
@@ -3409,7 +3431,7 @@ static int tokenlib_set_constant(lua_State *L, singleword cmd, halfword min, hal
return 0;
}
-static int tokenlib_get_constant(lua_State *L, halfword cmd)
+static int tokenlib_get_constant_value(lua_State *L, halfword cmd)
{
if (lua_type(L, 1) == LUA_TSTRING) {
size_t l;
@@ -3428,32 +3450,32 @@ static int tokenlib_get_constant(lua_State *L, halfword cmd)
static int tokenlib_set_integer(lua_State *L)
{
- return tokenlib_set_constant(L, integer_cmd, min_integer, max_integer);
+ return tokenlib_set_constant_value(L, integer_cmd, min_integer, max_integer);
}
static int tokenlib_set_dimension(lua_State *L)
{
- return tokenlib_set_constant(L, dimension_cmd, min_dimen, max_dimen);
+ return tokenlib_set_constant_value(L, dimension_cmd, min_dimen, max_dimen);
}
// static int tokenlib_set_gluespec(lua_State *L)
// {
-// return tokenlib_set_constant(L, gluespec_cmd, min_dimen, max_dimen);
+// return tokenlib_set_constant_value(L, gluespec_cmd, min_dimen, max_dimen);
// }
static int tokenlib_get_integer(lua_State *L)
{
- return tokenlib_get_constant(L, integer_cmd);
+ return tokenlib_get_constant_value(L, integer_cmd);
}
static int tokenlib_get_dimension(lua_State *L)
{
- return tokenlib_get_constant(L, dimension_cmd);
+ return tokenlib_get_constant_value(L, dimension_cmd);
}
// static int tokenlib_get_gluespec(lua_State *L)
// {
-// return tokenlib_get_constant(L, gluespec_cmd);
+// return tokenlib_get_constant_value(L, gluespec_cmd);
// }
/*
@@ -3575,6 +3597,7 @@ static const struct luaL_Reg tokenlib_function_list[] = {
{ "getinstance", tokenlib_get_instance },
{ "getflags", tokenlib_get_flags },
{ "getparameters", tokenlib_get_parameters },
+ { "getconstant", tokenlib_get_constant },
{ "getmacro", tokenlib_get_macro },
{ "getmeaning", tokenlib_get_meaning },
{ "getcmdchrcs", tokenlib_get_cmdchrcs },
@@ -3721,11 +3744,13 @@ void lmt_local_call(int slot)
lua_settop(L, stacktop);
}
-int lmt_function_call_by_class(int slot, int property, halfword *value)
+/*tex We replaced |class| by |category because of g++ issues. */
+
+int lmt_function_call_by_category(int slot, int property, halfword *value)
{
lua_State *L = lmt_lua_state.lua_instance;
int stacktop = lua_gettop(L);
- int class = lua_value_none_code;
+ int category = lua_value_none_code;
lua_pushcfunction(L, lmt_traceback);
lua_rawgeti(L, LUA_REGISTRYINDEX, lmt_lua_state.function_table_id);
if (lua_rawgeti(L, -1, slot) == LUA_TFUNCTION) {
@@ -3744,9 +3769,9 @@ int lmt_function_call_by_class(int slot, int property, halfword *value)
lmt_error(L, "function call", slot, i == LUA_ERRRUN ? 0 : 1);
} else {
if (lua_type(L, -2) == LUA_TNUMBER) {
- class = lmt_tointeger(L, -2);
+ category = lmt_tointeger(L, -2);
}
- switch (class) {
+ switch (category) {
case lua_value_none_code:
{
break;
@@ -3798,7 +3823,7 @@ int lmt_function_call_by_class(int slot, int property, halfword *value)
case lua_value_float_code:
case lua_value_string_code:
{
- class = lua_value_none_code;
+ category = lua_value_none_code;
break;
}
case lua_value_boolean_code:
@@ -3816,14 +3841,14 @@ int lmt_function_call_by_class(int slot, int property, halfword *value)
break;
default:
{
- class = lua_value_none_code;
+ category = lua_value_none_code;
break;
}
}
}
}
lua_settop(L, stacktop);
- return class;
+ return category;
}
/* some day maybe an alternative too
diff --git a/source/luametatex/source/lua/lmttokenlib.h b/source/luametatex/source/lua/lmttokenlib.h
index 450c6173a..bfc3ed6f2 100644
--- a/source/luametatex/source/lua/lmttokenlib.h
+++ b/source/luametatex/source/lua/lmttokenlib.h
@@ -33,7 +33,7 @@ extern halfword lmt_token_list_from_lua (lua_State *L, int slot);
extern halfword lmt_token_code_from_lua (lua_State *L, int slot);
extern void lmt_function_call (int slot, int prefix);
-extern int lmt_function_call_by_class (int slot, int property, halfword *value);
+extern int lmt_function_call_by_category (int slot, int property, halfword *value);
extern void lmt_token_call (int p);
extern void lmt_local_call (int slot);