void tokenlist_to_lua(lua_State * L, int p) { int cmd, chr, cs; int v; int i = 1; v = p; while (v != null && v < (int) fix_mem_end) { i++; v = token_link(v); } i = 1; lua_createtable(L, i, 0); while (p != null && p < (int) fix_mem_end) { if (token_info(p) >= cs_token_flag) { cs = token_info(p) - cs_token_flag; cmd = eq_type(cs); chr = equiv(cs); make_token_table(L, cmd, chr, cs); } else { cmd = token_cmd(token_info(p)); chr = token_chr(token_info(p)); make_token_table(L, cmd, chr, 0); } lua_rawseti(L, -2, i++); p = token_link(p); } }
void tex::set_math_char(int c) { ptr p; if (c >= 0100000) { cur_cs = active_base[cur_chr]; cur_cmd = eq_type(cur_cs); cur_chr = equiv(cur_cs); x_token(); back_input(); } else { p = new_noad(); math_type(nucleus(p)) = MATH_CHAR; character(nucleus(p)) = c % 256; fam(nucleus(p)) = c / 256 % 16; if (c >= VAR_CODE) { if (fam_in_range()) fam(nucleus(p)) = cur_fam; type(p) = ORD_NOAD; } else { type(p) = ORD_NOAD + c / 010000; } tail_append(p); } }
void tex::scan_math(ptr p) { int c; restart: get_nbrx_token(); reswitch: switch (cur_cmd) { case LETTER: case OTHER_CHAR: case CHAR_GIVEN: c = math_code(cur_chr); if (c == 0100000) { cur_cs = active_base[cur_chr]; cur_cmd = eq_type(cur_cs); cur_chr = equiv(cur_cs); x_token(); back_input(); goto restart; } break; case CHAR_NUM: scan_char_num(); cur_chr = cur_val; cur_cmd = CHAR_GIVEN; goto reswitch; case MATH_CHAR_NUM: scan_fifteen_bit_int(); c = cur_val; break; case MATH_GIVEN: c = cur_chr; break; case DELIM_NUM: scan_twenty_seven_bit_int(); c = cur_val / 010000; break; default: back_input(); scan_left_brace(); saved(0) = p; incr(save_ptr); push_math(MATH_GROUP); return; } math_type(p) = MATH_CHAR; character(p) = c % 256; if (c >= VAR_CODE && fam_in_range()) { fam(p) = cur_fam; } else { fam(p) = c / 256 % 16; } }
inline static int lua_tokenlib_get_cmdname(lua_State * L) { lua_token *n = check_istoken(L, 1); halfword t = token_info(n->token); int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); lua_push_string_by_index(L, command_names[cmd].lua); return 1; }
void primitive_def(const char*s,size_t l,quarterword c,halfword o) { int nncs= no_new_control_sequence; no_new_control_sequence= false; cur_val= string_lookup(s,l); no_new_control_sequence= nncs; eq_level(cur_val)= level_one; eq_type(cur_val)= c; equiv(cur_val)= o; }
inline static int lua_tokenlib_get_command(lua_State * L) { lua_token *n = check_istoken(L, 1); halfword t = token_info(n->token); if (t >= cs_token_flag) { lua_pushinteger(L,(int) eq_type((t - cs_token_flag))); } else { lua_pushinteger(L, token_cmd(t)); } return 1; }
boolean is_primitive(str_number csname) { int n,m; char*ss; m= prim_lookup(csname); ss= makecstring(csname); n= string_lookup(ss,str_length(csname)); free(ss); return((n!=undefined_cs_cmd)&& (m!=undefined_primitive)&& (eq_type(n)==prim_eq_type(m))&&(equiv(n)==prim_equiv(m))); }
inline static int lua_tokenlib_get_expandable(lua_State * L) { lua_token *n = check_istoken(L, 1); halfword t = token_info(n->token); int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); if (cmd > max_command_cmd) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } return 1; }
inline static int lua_tokenlib_get_protected(lua_State * L) { lua_token *n = check_istoken(L, 1); halfword t = token_info(n->token); int cmd = (t >= cs_token_flag ? eq_type(t - cs_token_flag) : token_cmd(t)); if (cmd > max_command_cmd && (cmd >= call_cmd) && (cmd < end_template_cmd)) { int chr = (t >= cs_token_flag ? equiv(t - cs_token_flag) : token_chr(t)); if (token_info(token_link(chr)) == protected_token) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } } else { lua_pushboolean(L, 0); } return 1; }
static int run_lookup(lua_State * L) { const char *s; size_t l; int cs, cmd, chr; if (lua_type(L, -1) == LUA_TSTRING) { s = lua_tolstring(L, -1, &l); if (l > 0) { cs = string_lookup(s, l); cmd = eq_type(cs); chr = equiv(cs); make_new_token(L, cmd, chr, cs); return 1; } } lua_pushnil(L); return 1; }
static int run_build(lua_State * L) { if (lua_type(L, 1) == LUA_TNUMBER) { int cs = 0; int chr = (int) lua_tointeger(L, 1); int cmd = (int) luaL_optinteger(L, 2, get_cat_code(cat_code_table_par,chr)); if (cmd == 0 || cmd == 9 || cmd == 14 || cmd == 15) { formatted_warning("token lib","not a good token, catcode %i can not be returned, so 12 will be used",(int) cmd); cmd = 12; } else if (cmd == 13) { cs = active_to_cs(chr, false); cmd = eq_type(cs); chr = equiv(cs); } make_new_token(L, cmd, chr, cs); return 1; } else { return run_lookup(L); } }
inline static int lua_tokenlib_get_index(lua_State * L) { int cmd, chr; lua_token *n = check_istoken(L, 1); halfword t = token_info(n->token); if (t >= cs_token_flag) { cmd = eq_type(t - cs_token_flag); chr = equiv(t - cs_token_flag); } else { cmd = token_cmd(t); chr = token_chr(t); } switch (cmd) { case assign_int_cmd: chr -= count_base; break; case assign_attr_cmd: chr -= attribute_base; break; case assign_dimen_cmd: chr -= scaled_base; break; case assign_glue_cmd: chr -= skip_base; break; case assign_mu_glue_cmd: chr -= mu_skip_base; break; case assign_toks_cmd: chr -= toks_base; break; default: break; } if (chr >= 0 && chr <= 65535) { lua_pushinteger(L, chr); } else { lua_pushnil(L); } return 1; }