diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/ltexlib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/ltexlib.c | 183 |
1 files changed, 74 insertions, 109 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index 5187bc89c01..deb77555178 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -149,106 +149,6 @@ static int do_luacprint(lua_State * L, int partial, int deftable) return 0; } -/* the next one writes a raw token (number) */ - -/* - -int luatwrite(lua_State * L) -{ - int top = lua_gettop(L); - if (top>0) { - rope *rn = xmalloc(sizeof(rope)); // overkill - int i = 1 ; - luacstrings++; // should be luactokens - rn->text = NULL; - rn->tsize = 0; - rn->partial = 0; - rn->cattable = DEFAULT_CAT_TABLE; - rn->next = NULL; - rn->tok = 0; - rn->nod = 0; - if (write_spindle.head == NULL) { - write_spindle.head = rn; - } else { - write_spindle.tail->next = rn; - } - write_spindle.tail = rn; - write_spindle.complete = 0; - while (1) { - rn->tok = lua_tointeger(L,i); - if (i<top) { - rope *r = xmalloc(sizeof(rope)); // overkill - r->text = NULL; - r->tsize = 0; - r->partial = 0; - r->cattable = DEFAULT_CAT_TABLE; - r->next = NULL; - r->tok = 0; - r->nod = 0; - rn->next = r; - rn = r; - write_spindle.tail = rn; - i++; - } else { - break; - } - } - } - return 0; -} - -*/ - -/* the next one writes a raw node (number) */ - -/* - -int luanwrite(lua_State * L) -{ - int top = lua_gettop(L); - if (top>0) { - rope *rn = xmalloc(sizeof(rope)); // overkill - int i = 1 ; - luacstrings++; // should be luactokens - rn->text = NULL; - rn->tsize = 0; - rn->partial = 0; - rn->cattable = DEFAULT_CAT_TABLE; - rn->next = NULL; - rn->tok = 0; - rn->nod = 0; - if (write_spindle.head == NULL) { - write_spindle.head = rn; - } else { - write_spindle.tail->next = rn; - } - write_spindle.tail = rn; - write_spindle.complete = 0; - while (1) { - rn->nod = lua_tointeger(L,i); - if (i<top) { - rope *r = xmalloc(sizeof(rope)); // overkill - r->text = NULL; - r->tsize = 0; - r->partial = 0; - r->cattable = DEFAULT_CAT_TABLE; - r->next = NULL; - r->tok = 0; - r->nod = 0; - rn->next = r; - rn = r; - write_spindle.tail = rn; - i++; - } else { - break; - } - } - } - return 0; -} - -*/ - /* lua.write */ static int luacwrite(lua_State * L) @@ -1308,6 +1208,39 @@ static int gettoks(lua_State * L) return 1; } +static int getmark(lua_State *L) +{ + if (lua_gettop(L) == 0) { + lua_pushinteger(L, biggest_used_mark); + return 1; + } else if (lua_type(L, 1) == LUA_TSTRING) { + int num = luaL_optinteger(L, 2, 0); + if (num >= 0 && num <= biggest_used_mark) { + int ptr = null; + const char *s = lua_tostring(L, 1); + if (lua_key_eq(s, top)) { + ptr = top_marks_array[num]; + } else if (lua_key_eq(s, first)) { + ptr = first_marks_array[num]; + } else if (lua_key_eq(s, bottom)) { + ptr = bot_marks_array[num]; + } else if (lua_key_eq(s, splitfirst)) { + ptr = split_first_marks_array[num]; + } else if (lua_key_eq(s, splitbottom)) { + ptr = split_bot_marks_array[num]; + } + if (ptr) { + char *str = tokenlist_to_cstring(ptr, 1, NULL); + lua_pushstring(L, str); + free(str); + return 1; + } + } + } + lua_pushnil(L); + return 1; +} + static int get_box_id(lua_State * L, int i, boolean report) { const char *s; @@ -2133,16 +2066,16 @@ static int getromannumeral(lua_State * L) static int get_parshape(lua_State * L) { - halfword par_shape_ptr = par_shape_par_ptr; - if (par_shape_ptr != 0) { + halfword ptr = par_shape_par_ptr; + if (ptr != null) { int m = 1; - int n = vinfo(par_shape_ptr + 1); + int n = vinfo(ptr + 1); lua_createtable(L, n, 0); while (m <= n) { lua_createtable(L, 2, 0); - lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 2)); + lua_pushinteger(L, vlink((ptr) + (2 * (m - 1)) + 2)); lua_rawseti(L, -2, 1); - lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 3)); + lua_pushinteger(L, vlink((ptr) + (2 * (m - 1)) + 3)); lua_rawseti(L, -2, 2); lua_rawseti(L, -2, m); m++; @@ -2153,6 +2086,38 @@ static int get_parshape(lua_State * L) return 1; } +static int get_etex_parshape(lua_State * L, int code) +{ + halfword ptr = null; + switch (code) { + case inter_line_penalties_loc: + ptr = inter_line_penalties_par_ptr; + break; + case club_penalties_loc: + ptr = club_penalties_par_ptr; + break; + case widow_penalties_loc: + ptr = widow_penalties_par_ptr; + break; + case display_widow_penalties_loc: + ptr = display_widow_penalties_par_ptr; + break; + } + if (ptr != null) { + int m = 1; + int n = vinfo(ptr + 1) + 1; + lua_createtable(L, n, 0); + while (m <= n) { + lua_pushinteger(L, penalty(ptr + m)); + lua_rawseti(L, -2, m); + m++; + } + } else { + lua_pushnil(L); + } + return 1; +} + static int gettex(lua_State * L) { int cur_cs1 = -1; @@ -2222,6 +2187,9 @@ static int gettex(lua_State * L) case set_tex_shape_cmd: retval = get_parshape(L); break; + case set_etex_shape_cmd: + retval = get_etex_parshape(L, cur_code); + break; default: lua_pushnil(L); break; @@ -3608,10 +3576,6 @@ static const struct luaL_Reg texlib[] = { { "sprint", luacsprint }, { "tprint", luactprint }, { "cprint", luaccprint }, - /* - { "twrite", luatwrite }, - { "nwrite", luanwrite }, - */ { "error", texerror }, { "set", settex }, { "get", gettex }, @@ -3640,6 +3604,7 @@ static const struct luaL_Reg texlib[] = { { "settoks", settoks }, { "scantoks", scantoks }, { "gettoks", gettoks }, + { "getmark", getmark }, { "isbox", isbox }, { "setbox", setbox }, { "getbox", getbox }, |