diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/ltexlib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/ltexlib.c | 709 |
1 files changed, 360 insertions, 349 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index 2c292afa40a..2f4aa10230b 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -43,6 +43,7 @@ typedef struct { void *next; boolean partial; int cattable; + /* halfword tok; */ } rope; typedef struct { @@ -63,8 +64,8 @@ static int spindle_index = 0; static void luac_store(lua_State * L, int i, int partial, int cattable) { - char *st; const char *sttemp; + char *st; size_t tsize; rope *rn = NULL; sttemp = lua_tolstring(L, i, &tsize); @@ -78,6 +79,7 @@ static void luac_store(lua_State * L, int i, int partial, int cattable) rn->partial = partial; rn->cattable = cattable; rn->next = NULL; + /* rn->tok = 0; */ if (write_spindle.head == NULL) { assert(write_spindle.tail == NULL); write_spindle.head = rn; @@ -91,13 +93,12 @@ static void luac_store(lua_State * L, int i, int partial, int cattable) static int do_luacprint(lua_State * L, int partial, int deftable) { - int i, n; int cattable = deftable; int startstrings = 1; - n = lua_gettop(L); + int n = lua_gettop(L); if (cattable != NO_CAT_TABLE) { if (lua_type(L, 1) == LUA_TNUMBER && n > 1) { - cattable=(int)lua_tonumber(L, 1); + cattable = lua_tointeger(L, 1); startstrings = 2; if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) { cattable = DEFAULT_CAT_TABLE; @@ -105,6 +106,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) } } if (lua_type(L, startstrings) == LUA_TTABLE) { + int i; for (i = 1;; i++) { lua_rawgeti(L, startstrings, i); if (lua_isstring(L,-1)) { /* or number */ @@ -115,6 +117,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable) } } } else { + int i; for (i = startstrings; i <= n; i++) { if (!lua_isstring(L,1)) { /* or number */ luaL_error(L, "no string to print"); @@ -136,6 +139,54 @@ static int do_luacprint(lua_State * L, int partial, int deftable) return 0; } +/* + +// some first experiments .. somewhat tricky at the other end + +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; + 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; + rn->next = r; + rn = r; + write_spindle.tail = rn; + i++; + } else { + break; + } + } + } + return 0; +} + +*/ + static int luacwrite(lua_State * L) { return do_luacprint(L, FULL_LINE, NO_CAT_TABLE); @@ -153,9 +204,9 @@ static int luacsprint(lua_State * L) static int luactprint(lua_State * L) { - int i, j, n; + int i, j; int cattable, startstrings; - n = lua_gettop(L); + int n = lua_gettop(L); for (i = 1; i <= n; i++) { cattable = DEFAULT_CAT_TABLE; startstrings = 1; @@ -163,19 +214,18 @@ static int luactprint(lua_State * L) luaL_error(L, "no string to print"); } lua_pushvalue(L, i); /* push the table */ - lua_pushnumber(L, 1); + lua_pushinteger(L, 1); lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TNUMBER) { - cattable=(int)lua_tonumber(L, -1); + cattable = lua_tointeger(L, -1); startstrings = 2; if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) { cattable = DEFAULT_CAT_TABLE; } } lua_pop(L, 1); - for (j = startstrings;; j++) { - lua_pushnumber(L, j); + lua_pushinteger(L, j); lua_gettable(L, -2); if (lua_isstring(L, -1)) { /* or number */ luac_store(L, -1, PARTIAL_LINE, cattable); @@ -190,7 +240,6 @@ static int luactprint(lua_State * L) return 0; } - int luacstring_cattable(void) { return (int) read_spindle.tail->cattable; @@ -208,9 +257,8 @@ int luacstring_final_line(void) int luacstring_input(void) { - char *st; - int ret; rope *t = read_spindle.head; + int ret = 1 ; if (!read_spindle.complete) { read_spindle.complete = 1; read_spindle.tail = NULL; @@ -222,12 +270,11 @@ int luacstring_input(void) return 0; } if (t->text != NULL) { - st = t->text; /* put that thing in the buffer */ + char *st = t->text; + int ret = first; last = first; - ret = last; check_buffer_overflow(last + (int) t->tsize); - while (t->tsize-- > 0) buffer[last++] = (packed_ASCII_code) * st++; if (!t->partial) { @@ -236,13 +283,17 @@ int luacstring_input(void) } free(t->text); t->text = NULL; + /* + } else if (t->tok > 0) { + ret = - t->tok; + */ } if (read_spindle.tail != NULL) { /* not a one-liner */ free(read_spindle.tail); } read_spindle.tail = t; read_spindle.head = t->next; - return 1; + return ret; } /* open for reading, and make a new one for writing */ @@ -272,8 +323,8 @@ void luacstring_close(int n) t = next; next = next->next; if (t==read_spindle.tail) { - read_spindle.tail = NULL; // prevent double-free - } + read_spindle.tail = NULL; + } free(t); } read_spindle.head = NULL; @@ -293,7 +344,7 @@ void luacstring_close(int n) #define check_register(base) do { \ int k = get_item_index(L, lua_gettop(L), base); \ if ((k>=0) && (k <= 65535)) { \ - lua_pushnumber(L,k); \ + lua_pushinteger(L,k); \ } else { \ lua_pushboolean(L,false); \ } \ @@ -303,14 +354,14 @@ void luacstring_close(int n) static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, int *radix_ret) { boolean negative = false; /* should the answer be negated? */ - int m; /* |$2^{31}$ / radix|, the threshold of danger */ + int m = 214748364; /* |$2^{31}$ / radix|, the threshold of danger */ int d; /* the digit just scanned */ - boolean vacuous; /* have no digits appeared? */ - boolean OK_so_far; /* has an error message been issued? */ - int radix1 = 0; /* the radix of the integer */ + boolean vacuous = true; /* have no digits appeared? */ + boolean OK_so_far = true; /* has an error message been issued? */ + int radix1 = 10; /* the radix of the integer */ int c = 0; /* the current character */ const char *s; /* where we stopped in the string |ss| */ - integer val = 0; /* return value */ + integer val = 0; /* return value */ s = ss; do { do { @@ -321,10 +372,6 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, in c = '+'; } } while (c == '+'); - - - radix1 = 10; - m = 214748364; if (c == '\'') { radix1 = 8; m = 02000000000; @@ -334,10 +381,6 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret, in m = 01000000000; c = *s++; } - vacuous = true; - val = 0; - OK_so_far = true; - /* Accumulate the constant until |cur_tok| is not a suitable digit */ while (1) { if ((c < '0' + radix1) && (c >= '0') && (c <= '0' + 9)) { @@ -411,7 +454,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) c = '+'; } } while (c == '+'); - if (c == ',') { c = '.'; } @@ -449,7 +491,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) negative = !negative; cur_val = -cur_val; } - /* Scan for (u)units that are internal dimensions; |goto attach_sign| with |cur_val| set if found */ save_cur_val = cur_val; @@ -478,7 +519,6 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) cur_val = nx_plus_y(save_cur_val, v, xn_over_d(v, f, 0200000)); goto ATTACH_SIGN; NOT_FOUND: - /* Scan for (m)\.{mu} units and |goto attach_fraction| */ if (strncmp(s, "mu", 2) == 0) { s += 2; @@ -487,12 +527,14 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) if (strncmp(s, "true", 4) == 0) { /* Adjust (f)for the magnification ratio */ s += 4; - prepare_mag(); - if (int_par(mag_code) != 1000) { - cur_val = xn_over_d(cur_val, 1000, int_par(mag_code)); - f = (1000 * f + 0200000 * tex_remainder) / int_par(mag_code); - cur_val = cur_val + (f / 0200000); - f = f % 0200000; + if (output_mode_used == OMODE_DVI) { + prepare_mag(); + if (int_par(mag_code) != 1000) { + cur_val = xn_over_d(cur_val, 1000, int_par(mag_code)); + f = (1000 * f + 0200000 * tex_remainder) / int_par(mag_code); + cur_val = cur_val + (f / 0200000); + f = f % 0200000; + } } do { c = *s++; @@ -505,37 +547,36 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret) } /* Scan for (a)all other units and adjust |cur_val| and |f| accordingly; |goto done| in the case of scaled points */ - - if (strncmp(s, "in", 2) == 0) { + if (strncmp(s, "mm", 2) == 0) { s += 2; - set_conversion(7227, 100); - } else if (strncmp(s, "pc", 2) == 0) { - s += 2; - set_conversion(12, 1); + set_conversion(7227, 2540); } else if (strncmp(s, "cm", 2) == 0) { s += 2; set_conversion(7227, 254); - } else if (strncmp(s, "mm", 2) == 0) { + } else if (strncmp(s, "sp", 2) == 0) { s += 2; - set_conversion(7227, 2540); + goto DONE; } else if (strncmp(s, "bp", 2) == 0) { s += 2; set_conversion(7227, 7200); + } else if (strncmp(s, "in", 2) == 0) { + s += 2; + set_conversion(7227, 100); } else if (strncmp(s, "dd", 2) == 0) { s += 2; set_conversion(1238, 1157); } else if (strncmp(s, "cc", 2) == 0) { s += 2; set_conversion(14856, 1157); + } else if (strncmp(s, "pc", 2) == 0) { + s += 2; + set_conversion(12, 1); } else if (strncmp(s, "nd", 2) == 0) { s += 2; set_conversion(685, 642); } else if (strncmp(s, "nc", 2) == 0) { s += 2; set_conversion(1370, 107); - } else if (strncmp(s, "sp", 2) == 0) { - s += 2; - goto DONE; } else { /* Complain about unknown unit and |goto done2| */ luaL_error(L, "Illegal unit of measure (pt inserted)"); @@ -587,25 +628,25 @@ static int tex_scaledimen(lua_State * L) int sp; int t = lua_type(L, 1); if (t == LUA_TNUMBER) { - sp = (int) lua_tonumber(L, 1); + sp = lua_tointeger(L, 1); } else if (t == LUA_TSTRING) { sp = dimen_to_number(L, lua_tostring(L, 1)); } else { luaL_error(L, "argument must be a string or a number"); return 0; } - lua_pushnumber(L, sp); + lua_pushinteger(L, sp); return 1; } static int texerror (lua_State * L) { - int i, n, l; const char **errhlp = NULL; const char *error = luaL_checkstring(L,1); - n = lua_gettop(L); + int n = lua_gettop(L); if (n==2 && lua_type(L, n) == LUA_TTABLE) { - l = 1; /* |errhlp| is terminated by a NULL entry */ + int i; + int l = 1; /* |errhlp| is terminated by a NULL entry */ for (i = 1;; i++) { lua_rawgeti(L, n, i); if (lua_type(L,-1) == LUA_TSTRING) { @@ -654,7 +695,7 @@ static int get_item_index(lua_State * L, int i, int base) k = (equiv(cur_cs1) - base); break; case LUA_TNUMBER: - k = (int) luaL_checkinteger(L, i); + k = luaL_checkinteger(L, i); break; default: luaL_error(L, "argument must be a string or a number"); @@ -705,7 +746,7 @@ static int get_item_index(lua_State * L, int i, int base) } \ break; \ case LUA_TNUMBER: \ - key = (int) luaL_checkinteger(L, where); \ + key = luaL_checkinteger(L, where); \ if (key>=0 && key <= 65535) { \ err = set_register(key, value); \ if (err) { \ @@ -745,7 +786,7 @@ static int gettex(lua_State * L); } \ break; \ case LUA_TNUMBER: \ - key = (int) luaL_checkinteger(L, where); \ + key = luaL_checkinteger(L, where); \ if (key>=0 && key <= 65535) { \ value = get_register(key); \ } else { \ @@ -770,7 +811,7 @@ static int setdimen(lua_State * L) int t = lua_type(L, top); check_item_global(L,top,isglobal); if (t == LUA_TNUMBER) { - value = (int) lua_tonumber(L, top); + value = lua_tointeger(L, top); } else if (t == LUA_TSTRING) { value = dimen_to_number(L, lua_tostring(L, top)); } else { @@ -784,7 +825,7 @@ static int getdimen(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), scaled_base, "dimen", value, is_dim_assign, get_tex_dimen_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -853,8 +894,8 @@ static int setcount(lua_State * L) int top = lua_gettop(L); check_item_global(L,top,isglobal); t = lua_type(L,top); - if (t == LUA_TNUMBER || t == LUA_TSTRING) { - value = (int) lua_tonumber(L, top); + if (t == LUA_TNUMBER) { + value = lua_tointeger(L, top); } else { luaL_error(L, "unsupported %s value type","count"); } @@ -866,7 +907,7 @@ static int getcount(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), count_base, "count", value, is_int_assign, get_tex_count_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -885,8 +926,8 @@ static int setattribute(lua_State * L) int top = lua_gettop(L); check_item_global(L,top,isglobal); t = lua_type(L,top); - if (t == LUA_TNUMBER || t == LUA_TSTRING) { - value = (int) lua_tonumber(L, top); + if (t == LUA_TNUMBER) { + value = lua_tointeger(L, top); } else { luaL_error(L, "unsupported %s value type","attribute"); } @@ -898,7 +939,7 @@ static int getattribute(lua_State * L) { int value = 0; get_item_index_plus(L, lua_gettop(L), attribute_base, "attribute", value, is_attr_assign, get_tex_attribute_register, false); - lua_pushnumber(L, value); + lua_pushinteger(L, value); return 1; } @@ -972,7 +1013,7 @@ static int scantoks(lua_State * L) memcpy (s, ss, str.l+1); str.s = (unsigned char *)s; k = get_item_index(L, (i - 2), toks_base); - c = (int) luaL_checkinteger(L, i - 1); + c = luaL_checkinteger(L, i - 1); check_index_range(k, "settoks"); err = scan_tex_toks_register(k, c, str); xfree(str.s); @@ -985,10 +1026,9 @@ static int scantoks(lua_State * L) static int gettoks(lua_State * L) { - int k; - str_number t; char *ss; - k = get_item_index(L, lua_gettop(L), toks_base); + str_number t; + int k = get_item_index(L, lua_gettop(L), toks_base); check_index_range(k, "gettoks"); t = get_tex_toks_register(k); ss = makecstring(t); @@ -1005,31 +1045,31 @@ static int get_box_id(lua_State * L, int i, boolean report) size_t k = 0; int j = -1; switch (lua_type(L, i)) { - case LUA_TSTRING: - s = lua_tolstring(L, i, &k); - cur_cs1 = string_lookup(s, k); - cur_cmd1 = eq_type(cur_cs1); - if (cur_cmd1 == char_given_cmd || - cur_cmd1 == math_given_cmd) { - j = equiv(cur_cs1); - } - break; - case LUA_TNUMBER: - j=(int)lua_tonumber(L, (i)); - break; - default: - if (report) { - luaL_error(L, "argument must be a string or a number"); - } - j = -1; /* not a valid box id */ + case LUA_TSTRING: + s = lua_tolstring(L, i, &k); + cur_cs1 = string_lookup(s, k); + cur_cmd1 = eq_type(cur_cs1); + if (cur_cmd1 == char_given_cmd || + cur_cmd1 == math_given_cmd) { + j = equiv(cur_cs1); + } + break; + case LUA_TNUMBER: + j = lua_tointeger(L, (i)); + break; + default: + if (report) { + luaL_error(L, "argument must be a string or a number"); + } + j = -1; /* not a valid box id */ } return j; } static int getbox(lua_State * L) { - int k, t; - k = get_box_id(L, -1, true); + int t; + int k = get_box_id(L, -1, true); check_index_range(k, "getbox"); t = get_tex_box_register(k); nodelist_to_lua(L, t); @@ -1085,14 +1125,13 @@ static int setbox(lua_State * L) return vsetbox(L, isglobal); } -#define check_char_range(j,s,lim) \ - if (j<0 || j >= lim) { \ - luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); \ +#define check_char_range(j,s,lim) \ + if (j<0 || j >= lim) { \ + luaL_error(L, "incorrect character value %d for tex.%s()", (int) j, s); \ } - static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), - void (*settwo)(int,halfword,quarterword), const char *name, int lim) + void (*settwo)(int,halfword,quarterword), const char *name, int lim) { int ch; halfword val, ucval; @@ -1100,7 +1139,7 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), int n = lua_gettop(L); int f = 1; if (n>1 && lua_type(L,1) == LUA_TTABLE) - f++; + f++; if (n>2 && (lua_type(L,f) == LUA_TSTRING)) { const char *s = lua_tostring(L, f); if (lua_key_eq(s,global)) { @@ -1108,13 +1147,13 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), f++; } } - ch = (int) luaL_checkinteger(L, f); + ch = luaL_checkinteger(L, f); check_char_range(ch, name, 65536*17); val = (halfword) luaL_checkinteger(L, f+1); check_char_range(val, name, lim); (setone)(ch, val, level); if (settwo != NULL && n-f == 2) { - ucval = (halfword) luaL_checkinteger(L, f+2); + ucval = (halfword) luaL_checkinteger(L, f+2); check_char_range(ucval, name, lim); (settwo)(ch, ucval, level); } @@ -1128,9 +1167,9 @@ static int setlccode(lua_State * L) static int getlccode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getlccode", 65536*17); - lua_pushnumber(L, get_lc_code(ch)); + lua_pushinteger(L, get_lc_code(ch)); return 1; } @@ -1141,9 +1180,9 @@ static int setuccode(lua_State * L) static int getuccode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getuccode", 65536*17); - lua_pushnumber(L, get_uc_code(ch)); + lua_pushinteger(L, get_uc_code(ch)); return 1; } @@ -1154,9 +1193,9 @@ static int setsfcode(lua_State * L) static int getsfcode(lua_State * L) { - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getsfcode", 65536*17); - lua_pushnumber(L, get_sf_code(ch)); + lua_pushinteger(L, get_sf_code(ch)); return 1; } @@ -1178,9 +1217,9 @@ static int setcatcode(lua_State * L) } } if (n-f == 2) { - cattable = (int) luaL_checkinteger(L, -3); + cattable = luaL_checkinteger(L, -3); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setcatcode", 65536*17); val = (halfword) luaL_checkinteger(L, -1); check_char_range(val, "setcatcode", 16); @@ -1191,12 +1230,12 @@ static int setcatcode(lua_State * L) static int getcatcode(lua_State * L) { int cattable = int_par(cat_code_table_code); - int ch = (int) luaL_checkinteger(L, -1); + int ch = luaL_checkinteger(L, -1); if (lua_gettop(L)>=2 && lua_type(L,-2)==LUA_TNUMBER) { cattable = luaL_checkinteger(L, -2); } check_char_range(ch, "getcatcode", 65536*17); - lua_pushnumber(L, get_cat_code(cattable, ch)); + lua_pushinteger(L, get_cat_code(cattable, ch)); return 1; } @@ -1220,7 +1259,7 @@ static int setmathcode(lua_State * L) if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { luaL_error(L, "Bad arguments for tex.setmathcode()"); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setmathcode", 65536*17); lua_rawgeti(L, -1, 1); @@ -1234,35 +1273,35 @@ static int setmathcode(lua_State * L) check_char_range(cval, "setmathcode", 8); check_char_range(fval, "setmathcode", 256); check_char_range(chval, "setmathcode", 65536*17); - set_math_code(ch, umath_mathcode, cval,fval, chval, (quarterword) (level)); + set_math_code(ch, cval,fval, chval, (quarterword) (level)); return 0; } static int getmathcode(lua_State * L) { - mathcodeval mval = { 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + mathcodeval mval = { 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getmathcode", 65536*17); mval = get_math_code(ch); lua_newtable(L); - lua_pushnumber(L,mval.class_value); + lua_pushinteger(L,mval.class_value); lua_rawseti(L, -2, 1); - lua_pushnumber(L,mval.family_value); + lua_pushinteger(L,mval.family_value); lua_rawseti(L, -2, 2); - lua_pushnumber(L,mval.character_value); + lua_pushinteger(L,mval.character_value); lua_rawseti(L, -2, 3); return 1; } static int getmathcodes(lua_State * L) { - mathcodeval mval = { 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + mathcodeval mval = { 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getmathcodes", 65536*17); mval = get_math_code(ch); - lua_pushnumber(L,mval.class_value); - lua_pushnumber(L,mval.family_value); - lua_pushnumber(L,mval.character_value); + lua_pushinteger(L,mval.class_value); + lua_pushinteger(L,mval.family_value); + lua_pushinteger(L,mval.character_value); return 3; } @@ -1285,7 +1324,7 @@ static int setdelcode(lua_State * L) if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { luaL_error(L, "Bad arguments for tex.setdelcode()"); } - ch = (int) luaL_checkinteger(L, -2); + ch = luaL_checkinteger(L, -2); check_char_range(ch, "setdelcode", 65536*17); lua_rawgeti(L, -1, 1); sfval = (halfword) luaL_checkinteger(L, -1); @@ -1301,59 +1340,56 @@ static int setdelcode(lua_State * L) check_char_range(scval, "setdelcode", 65536*17); check_char_range(lfval, "setdelcode", 256); check_char_range(lcval, "setdelcode", 65536*17); - set_del_code(ch, umath_mathcode, sfval, scval, lfval, lcval, (quarterword) (level)); + set_del_code(ch, sfval, scval, lfval, lcval, (quarterword) (level)); return 0; } static int getdelcode(lua_State * L) { - delcodeval mval = { 0, 0, 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + delcodeval mval = { 0, 0, 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getdelcode", 65536*17); mval = get_del_code(ch); - /* lua_pushnumber(L, mval.class_value); */ - /* lua_pushnumber(L, mval.origin_value); */ lua_newtable(L); - lua_pushnumber(L,mval.small_family_value); + lua_pushinteger(L,mval.small_family_value); lua_rawseti(L, -2, 1); - lua_pushnumber(L,mval.small_character_value); + lua_pushinteger(L,mval.small_character_value); lua_rawseti(L, -2, 2); - lua_pushnumber(L,mval.large_family_value); + lua_pushinteger(L,mval.large_family_value); lua_rawseti(L, -2, 3); - lua_pushnumber(L,mval.large_character_value); + lua_pushinteger(L,mval.large_character_value); lua_rawseti(L, -2, 4); return 1; } static int getdelcodes(lua_State * L) { - delcodeval mval = { 0, 0, 0, 0, 0, 0 }; - int ch = (int) luaL_checkinteger(L, -1); + delcodeval mval = { 0, 0, 0, 0, 0 }; + int ch = luaL_checkinteger(L, -1); check_char_range(ch, "getdelcodes", 65536*17); mval = get_del_code(ch); - lua_pushnumber(L,mval.small_family_value); - lua_pushnumber(L,mval.small_character_value); - lua_pushnumber(L,mval.large_family_value); - lua_pushnumber(L,mval.large_character_value); + lua_pushinteger(L,mval.small_family_value); + lua_pushinteger(L,mval.small_character_value); + lua_pushinteger(L,mval.large_family_value); + lua_pushinteger(L,mval.large_character_value); return 4; } static int settex(lua_State * L) { const char *st; - int i, j, texstr; + int texstr; size_t k; int cur_cs1, cur_cmd1; int isglobal = 0; - j = 0; - i = lua_gettop(L); + int j = 0; + int i = lua_gettop(L); if (lua_type(L,i-1) == LUA_TSTRING) { st = lua_tolstring(L, (i - 1), &k); - if (lua_key_eq(st,prevdepth)) { if (lua_type(L, i) == LUA_TNUMBER) { - cur_list.prev_depth_field = lua_tonumber(L, i); + cur_list.prev_depth_field = lua_tointeger(L, i); } else if (lua_type(L, i) == LUA_TSTRING) { cur_list.prev_depth_field = dimen_to_number(L, lua_tostring(L, i)); } else { @@ -1361,22 +1397,20 @@ static int settex(lua_State * L) } return 0; } else if (lua_key_eq(st,prevgraf)) { - if (lua_type(L, i) != LUA_TNUMBER) { - cur_list.pg_field = lua_tonumber(L, i); + if (lua_type(L, i) == LUA_TNUMBER) { + cur_list.pg_field = lua_tointeger(L, i); } else { luaL_error(L, "unsupported value type"); } return 0; } else if (lua_key_eq(st,spacefactor)) { - if (lua_type(L, i) != LUA_TNUMBER) { - cur_list.space_factor_field = lua_tonumber(L, i); + if (lua_type(L, i) == LUA_TNUMBER) { + cur_list.space_factor_field = lua_tointeger(L, i); } else { luaL_error(L, "unsupported value type"); } return 0; } - - texstr = maketexlstring(st, k); if (is_primitive(texstr)) { if (i == 3 && (lua_type(L,1) == LUA_TSTRING)) { @@ -1389,16 +1423,14 @@ static int settex(lua_State * L) cur_cmd1 = eq_type(cur_cs1); if (is_int_assign(cur_cmd1)) { if (lua_type(L, i) == LUA_TNUMBER) { - int luai; - luai=(int)lua_tonumber(L, i); - assign_internal_value((isglobal ? 4 : 0), - equiv(cur_cs1), luai); + int luai = lua_tointeger(L, i); + assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), luai); } else { luaL_error(L, "unsupported value type"); } } else if (is_dim_assign(cur_cmd1)) { if (lua_type(L, i) == LUA_TNUMBER) { - j=(int)lua_tonumber(L, i); + j = lua_tointeger(L, i); } else if (lua_type(L, i) == LUA_TSTRING) { j = dimen_to_number(L, lua_tostring(L, i)); } else { @@ -1452,6 +1484,7 @@ static int do_convert(lua_State * L, int cur_code) case left_margin_kern_code: /* arg box */ case right_margin_kern_code: /* arg box */ case string_code: /* arg token */ + case cs_string_code: /* arg token */ case meaning_code: /* arg token */ break; @@ -1466,7 +1499,7 @@ static int do_convert(lua_State * L, int cur_code) if (lua_gettop(L) < 1) { /* error */ } - i=(int)lua_tonumber(L, 1); + i = lua_tointeger(L, 1); /* these fall through! */ @@ -1502,7 +1535,7 @@ static int do_scan_internal(lua_State * L, int cur_cmd1, int cur_code) case int_val_level: case dimen_val_level: case attr_val_level: - lua_pushnumber(L, cur_val); + lua_pushinteger(L, cur_val); break; case glue_val_level: case mu_val_level: @@ -1596,11 +1629,9 @@ static int tex_setmathparm(lua_State * L) { int i, j; int k; - int n; int l = cur_level; void *p; - n = lua_gettop(L); - + int n = lua_gettop(L); if ((n == 3) || (n == 4)) { if (n == 4 && (lua_type(L,1) == LUA_TSTRING)) { const char *s = lua_tostring(L, 1); @@ -1615,11 +1646,11 @@ static int tex_setmathparm(lua_State * L) p = lua_touserdata(L, n); k = *((halfword *)p); def_math_param(i, j, (scaled) k, l); - } else { - if (lua_type(L, n) == LUA_TNUMBER) - luaL_error(L, "argument must be a number"); - k=(int)lua_tonumber(L, n); + } else if (lua_type(L, n) == LUA_TNUMBER) { + k = lua_tointeger(L, n); def_math_param(i, j, (scaled) k, l); + } else { + luaL_error(L, "argument must be a number"); } } return 0; @@ -1627,12 +1658,10 @@ static int tex_setmathparm(lua_State * L) static int tex_getmathparm(lua_State * L) { - int i, j; - scaled k; if ((lua_gettop(L) == 2)) { - i = luaL_checkoption(L, 1, NULL, math_param_names); - j = luaL_checkoption(L, 2, NULL, math_style_names); - k = get_math_param(i, j); + int i = luaL_checkoption(L, 1, NULL, math_param_names); + int j = luaL_checkoption(L, 2, NULL, math_style_names); + scaled k = get_math_param(i, j); if (i<0 && i>=math_param_last) { lua_pushnil(L); } else if (i>=math_param_first_mu_glue) { @@ -1641,7 +1670,7 @@ static int tex_getmathparm(lua_State * L) } lua_nodelib_push_fast(L, k); } else { - lua_pushnumber(L, k); + lua_pushinteger(L, k); } } return 1; @@ -1674,17 +1703,16 @@ static int getromannumeral(lua_State * L) static int get_parshape(lua_State * L) { - int n; halfword par_shape_ptr = equiv(par_shape_loc); if (par_shape_ptr != 0) { int m = 1; - n = vinfo(par_shape_ptr + 1); + int n = vinfo(par_shape_ptr + 1); lua_createtable(L, n, 0); while (m <= n) { lua_createtable(L, 2, 0); - lua_pushnumber(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 2)); + lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 2)); lua_rawseti(L, -2, 1); - lua_pushnumber(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 3)); + lua_pushinteger(L, vlink((par_shape_ptr) + (2 * (m - 1)) + 3)); lua_rawseti(L, -2, 2); lua_rawseti(L, -2, m); m++; @@ -1704,54 +1732,51 @@ static int gettex(lua_State * L) int texstr; size_t k; const char *st = lua_tolstring(L, t, &k); - if (lua_key_eq(st,prevdepth)) { - lua_pushnumber(L, cur_list.prev_depth_field); + lua_pushinteger(L, cur_list.prev_depth_field); return 1; } else if (lua_key_eq(st,prevgraf)) { - lua_pushnumber(L, cur_list.pg_field); + lua_pushinteger(L, cur_list.pg_field); return 1; } else if (lua_key_eq(st,spacefactor)) { - lua_pushnumber(L, cur_list.space_factor_field); + lua_pushinteger(L, cur_list.space_factor_field); return 1; } - texstr = maketexlstring(st, k); cur_cs1 = prim_lookup(texstr); /* not found == relax == 0 */ flush_str(texstr); } if (cur_cs1 > 0) { - int cur_cmd1, cur_code; - cur_cmd1 = get_prim_eq_type(cur_cs1); - cur_code = get_prim_equiv(cur_cs1); + int cur_cmd1 = get_prim_eq_type(cur_cs1); + int cur_code = get_prim_equiv(cur_cs1); switch (cur_cmd1) { - case last_item_cmd: - retval = do_lastitem(L, cur_code); - break; - case convert_cmd: - retval = do_convert(L, cur_code); - break; - case assign_toks_cmd: - case assign_int_cmd: - case assign_attr_cmd: - case assign_dir_cmd: - case assign_dimen_cmd: - case assign_glue_cmd: - case assign_mu_glue_cmd: - case set_aux_cmd: - case set_prev_graf_cmd: - case set_page_int_cmd: - case set_page_dimen_cmd: - case char_given_cmd: - case math_given_cmd: - retval = do_scan_internal(L, cur_cmd1, cur_code); - break; - case set_tex_shape_cmd: - retval = get_parshape(L); - break; - default: - lua_pushnil(L); - break; + case last_item_cmd: + retval = do_lastitem(L, cur_code); + break; + case convert_cmd: + retval = do_convert(L, cur_code); + break; + case assign_toks_cmd: + case assign_int_cmd: + case assign_attr_cmd: + case assign_dir_cmd: + case assign_dimen_cmd: + case assign_glue_cmd: + case assign_mu_glue_cmd: + case set_aux_cmd: + case set_prev_graf_cmd: + case set_page_int_cmd: + case set_page_dimen_cmd: + case char_given_cmd: + case math_given_cmd: + retval = do_scan_internal(L, cur_cmd1, cur_code); + break; + case set_tex_shape_cmd: + retval = get_parshape(L); + break; + default: + lua_pushnil(L); + break; } } else if (t == 2) { lua_rawget(L, 1); @@ -1766,44 +1791,44 @@ static int getlist(lua_State * L) str = lua_tostring(L, 2); if (lua_key_eq(str,page_ins_head)) { if (vlink(page_ins_head) == page_ins_head) - lua_pushnumber(L, null); + lua_pushinteger(L, null); else - lua_pushnumber(L, vlink(page_ins_head)); + lua_pushinteger(L, vlink(page_ins_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,contrib_head)) { alink(vlink(contrib_head)) = null ; - lua_pushnumber(L, vlink(contrib_head)); + lua_pushinteger(L, vlink(contrib_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,page_head)) { alink(vlink(page_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(page_head)); + lua_pushinteger(L, vlink(page_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,temp_head)) { alink(vlink(temp_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(temp_head)); + lua_pushinteger(L, vlink(temp_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,hold_head)) { alink(vlink(hold_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(hold_head)); + lua_pushinteger(L, vlink(hold_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,adjust_head)) { alink(vlink(adjust_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(adjust_head)); + lua_pushinteger(L, vlink(adjust_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,best_page_break)) { - lua_pushnumber(L, best_page_break); + lua_pushinteger(L, best_page_break); lua_nodelib_push(L); } else if (lua_key_eq(str,least_page_cost)) { - lua_pushnumber(L, least_page_cost); + lua_pushinteger(L, least_page_cost); } else if (lua_key_eq(str,best_size)) { - lua_pushnumber(L, best_size); + lua_pushinteger(L, best_size); } else if (lua_key_eq(str,pre_adjust_head)) { alink(vlink(pre_adjust_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(pre_adjust_head)); + lua_pushinteger(L, vlink(pre_adjust_head)); lua_nodelib_push(L); } else if (lua_key_eq(str,align_head)) { alink(vlink(align_head)) = null ;/*hh-ls */ - lua_pushnumber(L, vlink(align_head)); + lua_pushinteger(L, vlink(align_head)); lua_nodelib_push(L); } else { lua_pushnil(L); @@ -1816,16 +1841,15 @@ static int getlist(lua_State * L) static int setlist(lua_State * L) { - halfword *n_ptr; - const char *str; - halfword n = 0; if (lua_type(L,2) == LUA_TSTRING) { - str = lua_tostring(L, 2); + const char *str = lua_tostring(L, 2); if (lua_key_eq(str,best_size)) { best_size = (int) lua_tointeger(L, 3); } else if (lua_key_eq(str,least_page_cost)) { least_page_cost = (int) lua_tointeger(L, 3); } else { + halfword *n_ptr; + halfword n = 0; if (!lua_isnil(L, 3)) { n_ptr = check_isnode(L, 3); n = *n_ptr; @@ -1875,32 +1899,32 @@ static int lua_nest_getfield(lua_State * L) const char *field = lua_tostring(L, -1); r = *rv; if (lua_key_eq(field,mode)) { - lua_pushnumber(L, r->mode_field); + lua_pushinteger(L, r->mode_field); } else if (lua_key_eq(field,head)) { lua_nodelib_push_fast(L, r->head_field); } else if (lua_key_eq(field,tail)) { lua_nodelib_push_fast(L, r->tail_field); } else if (lua_key_eq(field,delimptr)) { - lua_pushnumber(L, r->eTeX_aux_field); + lua_pushinteger(L, r->eTeX_aux_field); lua_nodelib_push(L); } else if (lua_key_eq(field,prevgraf)) { - lua_pushnumber(L, r->pg_field); + lua_pushinteger(L, r->pg_field); } else if (lua_key_eq(field,modeline)) { - lua_pushnumber(L, r->ml_field); + lua_pushinteger(L, r->ml_field); } else if (lua_key_eq(field,prevdepth)) { - lua_pushnumber(L, r->prev_depth_field); + lua_pushinteger(L, r->prev_depth_field); } else if (lua_key_eq(field,spacefactor)) { - lua_pushnumber(L, r->space_factor_field); + lua_pushinteger(L, r->space_factor_field); } else if (lua_key_eq(field,noad)) { - lua_pushnumber(L, r->incompleat_noad_field); + lua_pushinteger(L, r->incompleat_noad_field); lua_nodelib_push(L); } else if (lua_key_eq(field,dirs)) { - lua_pushnumber(L, r->dirs_field); + lua_pushinteger(L, r->dirs_field); lua_nodelib_push(L); } else if (lua_key_eq(field,mathdir)) { lua_pushboolean(L, r->math_field); } else if (lua_key_eq(field,mathstyle)) { - lua_pushnumber(L, r->math_style_field); + lua_pushinteger(L, r->math_style_field); } else { lua_pushnil(L); } @@ -1915,7 +1939,7 @@ static int lua_nest_setfield(lua_State * L) const char *field = lua_tostring(L, -2); r = *rv; if (lua_key_eq(field,mode)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->mode_field = i; } else if (lua_key_eq(field,head)) { n = check_isnode(L, -1); @@ -1927,16 +1951,16 @@ static int lua_nest_setfield(lua_State * L) n = check_isnode(L, -1); r->eTeX_aux_field = *n; } else if (lua_key_eq(field,prevgraf)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->pg_field = i; } else if (lua_key_eq(field,modeline)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->ml_field = i; } else if (lua_key_eq(field,prevdepth)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->prev_depth_field = i; } else if (lua_key_eq(field,spacefactor)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->space_factor_field = i; } else if (lua_key_eq(field,noad)) { n = check_isnode(L, -1); @@ -1947,7 +1971,7 @@ static int lua_nest_setfield(lua_State * L) } else if (lua_key_eq(field,mathdir)) { r->math_field = lua_toboolean(L, -1); } else if (lua_key_eq(field,mathstyle)) { - i=(int)lua_tonumber(L, -1); + i = lua_tointeger(L, -1); r->math_style_field = i; } return 0; @@ -1968,11 +1992,10 @@ static void init_nest_lib(lua_State * L) static int getnest(lua_State * L) { - int ptr; list_state_record **nestitem; int t = lua_type(L, 2); if (t == LUA_TNUMBER) { - ptr=(int)lua_tonumber(L, 2); + int ptr = lua_tointeger(L, 2); if (ptr >= 0 && ptr <= nest_ptr) { nestitem = lua_newuserdata(L, sizeof(list_state_record *)); *nestitem = &nest[ptr]; @@ -1984,7 +2007,7 @@ static int getnest(lua_State * L) } else if (t == LUA_TSTRING) { const char *s = lua_tostring(L, 2); if (lua_key_eq(s,ptr)) { - lua_pushnumber(L, nest_ptr); + lua_pushinteger(L, nest_ptr); } else { lua_pushnil(L); } @@ -2013,11 +2036,11 @@ static int do_integer_error(double m) static int tex_roundnumber(lua_State * L) { - double m = (double) lua_tonumber(L, 1) + 0.5; + double m = (double) lua_tonumber(L, 1) + 0.5; /* integer or float */ if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); return 1; } @@ -2031,21 +2054,21 @@ static int tex_scaletable(lua_State * L) lua_pushvalue(L, -2); lua_insert(L, -2); if (lua_type(L,-2) == LUA_TNUMBER) { - double m = (double) lua_tonumber(L, -1) * delta + 0.5; + double m = (double) lua_tonumber(L, -1) * delta + 0.5; /* integer or float */ lua_pop(L, 1); if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); } lua_rawset(L, 3); } } else if (lua_type(L,1) == LUA_TNUMBER) { - double m = (double) lua_tonumber(L, 1) * delta + 0.5; + double m = (double) lua_tonumber(L, 1) * delta + 0.5; /* integer or float */ if (abs(m) > (double) infinity) - lua_pushnumber(L, do_integer_error(m)); + lua_pushinteger(L, do_integer_error(m)); else - lua_pushnumber(L, floor(m)); + lua_pushinteger(L, floor(m)); } else { lua_pushnil(L); } @@ -2071,7 +2094,7 @@ static int tex_definefont(lua_State * L) i = 2; } csname = luaL_checklstring(L, i, &l); - f = (int) luaL_checkinteger(L, (i + 1)); + f = luaL_checkinteger(L, (i + 1)); t = maketexlstring(csname, l); no_new_control_sequence = 0; u = string_lookup(csname, l); @@ -2136,10 +2159,7 @@ static int tex_extraprimitives(lua_State * L) int cs = 0; n = lua_gettop(L); if (n == 0) { - mask = etex_command - + pdftex_command /* obsolete */ - + umath_command /* obsolete */ - + luatex_command; + mask = etex_command + luatex_command; } else { for (i = 1; i <= n; i++) { if (lua_type(L,i) == LUA_TSTRING) { @@ -2150,13 +2170,8 @@ static int tex_extraprimitives(lua_State * L) mask |= tex_command; } else if (lua_key_eq(s,core)) { mask |= core_command; - } else if (lua_key_eq(s,pdftex)) { /* obsolete */ - mask |= pdftex_command; } else if (lua_key_eq(s,luatex)) { - mask |= luatex_command - | umath_command; /* obsolete */ - } else if (lua_key_eq(s,umath)) { /* obsolete */ - mask |= umath_command; + mask |= luatex_command; } } } @@ -2238,57 +2253,55 @@ static int tex_enableprimitives(lua_State * L) return 0; } -#define get_int_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - - -#define get_intx_par(A,B,C,D,E) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - D = null; \ - } else if (lua_type(L, -1) == LUA_TTABLE){ \ - B = 0; \ - D = nodelib_topenalties(L, lua_gettop(L)); \ - } else { \ - B = (C); \ - D = (E); \ - } \ - lua_pop(L,1); \ - } while (0) - -#define get_dimen_par(A,B,C) do { \ +#define get_int_par(A,B,C) do { \ lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) == LUA_TNUMBER) { \ - B=(int)lua_tonumber(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) + + +#define get_intx_par(A,B,C,D,E) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + D = null; \ + } else if (lua_type(L, -1) == LUA_TTABLE){ \ + B = 0; \ + D = nodelib_topenalties(L, lua_gettop(L)); \ + } else { \ + B = (C); \ + D = (E); \ + } \ + lua_pop(L,1); \ +} while (0) + +#define get_dimen_par(A,B,C) do { \ + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) == LUA_TNUMBER) { \ + B = (int) lua_tointeger(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) #define get_glue_par(A,B,C) do { \ - lua_pushstring(L,(A)); \ - lua_gettable(L,-2); \ - if (lua_type(L, -1) != LUA_TNIL) { \ - B = *check_isnode(L, -1); \ - } else { \ - B = (C); \ - } \ - lua_pop(L,1); \ - } while (0) - + lua_pushstring(L,(A)); \ + lua_gettable(L,-2); \ + if (lua_type(L, -1) != LUA_TNIL) { \ + B = *check_isnode(L, -1); \ + } else { \ + B = (C); \ + } \ + lua_pop(L,1); \ +} while (0) static halfword nodelib_toparshape(lua_State * L, int i) { @@ -2314,11 +2327,11 @@ static halfword nodelib_toparshape(lua_State * L, int i) if (lua_type(L, i) == LUA_TTABLE) { lua_rawgeti(L, -1, 1); /* indent */ if (lua_type(L, -1) == LUA_TNUMBER) { - indent=(int)lua_tonumber(L, -1); + indent = lua_tointeger(L, -1); lua_pop(L, 1); lua_rawgeti(L, -1, 2); /* width */ if (lua_type(L, -1) == LUA_TNUMBER) { - width=(int)lua_tonumber(L, -1); + width = lua_tointeger(L, -1); lua_pop(L, 1); varmem[p + 2 * j].cint = indent; varmem[p + 2 * j + 1].cint = width; @@ -2351,16 +2364,15 @@ static halfword nodelib_topenalties(lua_State * L, int i) lua_pushnil(L); j = 2; while (lua_next(L, i) != 0) { - j++; - if (lua_type(L, -1) == LUA_TNUMBER) { - int pen = 0; - pen=(int)lua_tonumber(L, -1); - varmem[p+j].cint = pen; - } - lua_pop(L, 1); + j++; + if (lua_type(L, -1) == LUA_TNUMBER) { + int pen = lua_tointeger(L, -1); + varmem[p+j].cint = pen; + } + lua_pop(L, 1); } if (!odd(n)) - varmem[p+j+1].cint = 0; + varmem[p+j+1].cint = 0; return p; } @@ -2481,16 +2493,16 @@ static int tex_run_linebreak(lua_State * L) lua_nodelib_push_fast(L, vlink(cur_list.head_field)); lua_newtable(L); lua_pushstring(L, "demerits"); - lua_pushnumber(L, fewest_demerits); + lua_pushinteger(L, fewest_demerits); lua_settable(L, -3); lua_pushstring(L, "looseness"); - lua_pushnumber(L, actual_looseness); + lua_pushinteger(L, actual_looseness); lua_settable(L, -3); lua_pushstring(L, "prevdepth"); - lua_pushnumber(L, cur_list.prev_depth_field); + lua_pushinteger(L, cur_list.prev_depth_field); lua_settable(L, -3); lua_pushstring(L, "prevgraf"); - lua_pushnumber(L, cur_list.pg_field); + lua_pushinteger(L, cur_list.pg_field); lua_settable(L, -3); /* restore nest stack */ @@ -2511,10 +2523,9 @@ static int tex_shipout(lua_State * L) static int tex_badness(lua_State * L) { - scaled t,s; - t=(int)lua_tonumber(L,1); - s=(int)lua_tonumber(L,2); - lua_pushnumber(L, badness(t,s)); + scaled t = lua_tointeger(L,1); + scaled s = lua_tointeger(L,2); + lua_pushinteger(L, badness(t,s)); return 1; } @@ -2574,7 +2585,7 @@ static int tex_init_rand(lua_State * L) luaL_error(L, "argument must be a number"); return 0; } - sp=(int)lua_tonumber(L, 1); + sp = lua_tointeger(L, 1); init_randoms(sp); return 0; } @@ -2586,14 +2597,14 @@ static int tex_unif_rand(lua_State * L) luaL_error(L, "argument must be a number"); return 0; } - sp=(int)lua_tonumber(L, 1); - lua_pushnumber(L, unif_rand(sp)); + sp = lua_tointeger(L, 1); + lua_pushinteger(L, unif_rand(sp)); return 1; } static int tex_norm_rand(lua_State * L) { - lua_pushnumber(L, norm_rand()); + lua_pushinteger(L, norm_rand()); return 1; } @@ -2607,20 +2618,20 @@ static int tex_norm_rand(lua_State * L) r = r / rand_max; switch (lua_gettop(L)) { /* check number of arguments */ case 0: { /* no arguments */ - lua_pushnumber(L, r); /* Number between 0 and 1 */ + lua_pushnumber(L, r); /* float: [0, 1] */ break; } case 1: { /* only upper limit */ lua_Number u = luaL_checknumber(L, 1); luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty"); - lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* [1, u] */ + lua_pushnumber(L, floor(r*u) + (lua_Number)(1.0)); /* float: [1, u] */ break; } case 2: { /* lower and upper limits */ lua_Number l = luaL_checknumber(L, 1); lua_Number u = luaL_checknumber(L, 2); luaL_argcheck(L, l <= u, 2, "interval is empty"); - lua_pushnumber(L, floor(r*(u-l+1)) + l); /* [l, u] */ + lua_pushnumber(L, floor(r*(u-l+1)) + l); /* float: [l, u] */ break; } default: @@ -2654,10 +2665,10 @@ static int tex_show_context(lua_State * L) static int tex_save_box_resource(lua_State * L) { - halfword boxnumber, boxdata; + halfword boxdata; int index, attributes, resources; /* box attributes resources */ - boxnumber = (halfword) lua_tonumber(L,1); + halfword boxnumber = lua_tointeger(L,1); if (lua_type(L,2) == LUA_TSTRING) { lua_pushvalue(L, 2); attributes = luaL_ref(L, LUA_REGISTRYINDEX); @@ -2687,7 +2698,7 @@ static int tex_save_box_resource(lua_State * L) set_obj_xform_depth(static_pdf, index, depth(boxdata)); box(boxnumber) = null; last_saved_box_index = index; - lua_pushnumber(L, index); + lua_pushinteger(L, index); return 1; } @@ -2702,18 +2713,18 @@ static int tex_use_box_resource(lua_State * L) lua_pushnil(L); lua_pushnil(L); } else { - index = lua_tonumber(L,1); + index = lua_tointeger(L,1); alt.wd = null_flag; alt.ht = null_flag; alt.dp = null_flag; if (lua_type(L,2) == LUA_TNUMBER) { - alt.wd = (scaled) lua_tonumber(L,2); + alt.wd = (scaled) lua_tointeger(L,2); } if (lua_type(L,3) == LUA_TNUMBER) { - alt.ht = (scaled) lua_tonumber(L,3); + alt.ht = (scaled) lua_tointeger(L,3); } if (lua_type(L,4) == LUA_TNUMBER) { - alt.dp = (scaled) lua_tonumber(L,4); + alt.dp = (scaled) lua_tointeger(L,4); } /* sort of the same as backend */ check_obj_type(static_pdf, obj_type_xform, index); @@ -2731,9 +2742,9 @@ static int tex_use_box_resource(lua_State * L) height(rule) = dim.ht; depth(rule) = dim.dp; nodelist_to_lua(L, rule); - lua_pushnumber(L, (int) dim.wd); - lua_pushnumber(L, (int) dim.ht); - lua_pushnumber(L, (int) dim.dp); + lua_pushinteger(L, (int) dim.wd); + lua_pushinteger(L, (int) dim.ht); + lua_pushinteger(L, (int) dim.dp); } return 4; } @@ -2746,11 +2757,11 @@ static int tex_get_box_resource_dimensions(lua_State * L) lua_pushnil(L); lua_pushnil(L); } else { - index = lua_tonumber(L,1); + index = lua_tointeger(L,1); check_obj_type(static_pdf, obj_type_xform, index); - lua_pushnumber(L, (int) obj_xform_width(static_pdf, index)); - lua_pushnumber(L, (int) obj_xform_height(static_pdf, index)); - lua_pushnumber(L, (int) obj_xform_depth(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_width(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_height(static_pdf, index)); + lua_pushinteger(L, (int) obj_xform_depth(static_pdf, index)); } return 3; } |