903
954
return vsetbox(L, isglobal);
906
static int getboxdim(lua_State * L, int whichdim)
910
j = get_box_id(L, i);
911
lua_settop(L, (i - 2)); /* table at -1 */
912
if (j < 0 || j > 65535) {
913
luaL_error(L, "incorrect index");
917
lua_pushnumber(L, get_tex_box_width(j));
920
lua_pushnumber(L, get_tex_box_height(j));
923
lua_pushnumber(L, get_tex_box_depth(j));
928
static int getboxwd(lua_State * L)
930
return getboxdim(L, width_offset);
933
static int getboxht(lua_State * L)
935
return getboxdim(L, height_offset);
938
static int getboxdp(lua_State * L)
940
return getboxdim(L, depth_offset);
943
static int vsetboxdim(lua_State * L, int whichdim, int is_global)
946
int save_global_defs = int_par(global_defs_code);
948
int_par(global_defs_code) = 1;
950
if (!lua_isnumber(L, i)) {
951
j = dimen_to_number(L, lua_tostring(L, i));
953
lua_number2int(j, lua_tonumber(L, i));
955
k = get_box_id(L, (i - 1));
956
lua_settop(L, (i - 3)); /* table at -2 */
957
if (k < 0 || k > 65535) {
958
luaL_error(L, "incorrect index");
963
err = set_tex_box_width(k, j);
966
err = set_tex_box_height(k, j);
969
err = set_tex_box_depth(k, j);
971
int_par(global_defs_code) = save_global_defs;
973
luaL_error(L, "not a box");
978
static int setboxwd(lua_State * L)
981
int n = lua_gettop(L);
982
if (n == 3 && lua_isstring(L, 1)) {
983
const char *s = lua_tostring(L, 1);
984
if (strcmp(s, "global") == 0)
987
return vsetboxdim(L, width_offset, isglobal);
990
static int setboxht(lua_State * L)
993
int n = lua_gettop(L);
994
if (n == 3 && lua_isstring(L, 1)) {
995
const char *s = lua_tostring(L, 1);
996
if (strcmp(s, "global") == 0)
999
return vsetboxdim(L, height_offset, isglobal);
1002
static int setboxdp(lua_State * L)
1005
int n = lua_gettop(L);
1006
if (n == 3 && lua_isstring(L, 1)) {
1007
const char *s = lua_tostring(L, 1);
1008
if (strcmp(s, "global") == 0)
1011
return vsetboxdim(L, depth_offset, isglobal);
957
#define check_char_range(j,s,lim) \
958
if (j<0 || j >= lim) { \
959
luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); }
962
static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword),
963
void (*settwo)(int,halfword,quarterword), const char *name, int lim)
967
int level = cur_level;
968
int n = lua_gettop(L);
970
if (n>1 && lua_type(L,1) == LUA_TTABLE)
972
if (n>2 && lua_isstring(L, f)) {
973
const char *s = lua_tostring(L, f);
974
if (strcmp(s, "global") == 0) {
979
ch = (int) luaL_checkinteger(L, f);
980
check_char_range(ch, name, 65536*17);
981
val = (halfword) luaL_checkinteger(L, f+1);
982
check_char_range(val, name, lim);
983
(setone)(ch, val, level);
984
if (settwo != NULL && n-f == 2) {
985
ucval = (halfword) luaL_checkinteger(L, f+2);
986
check_char_range(ucval, name, lim);
987
(settwo)(ch, ucval, level);
992
static int setlccode(lua_State * L)
994
return setcode(L, &set_lc_code, &set_uc_code, "setlccode", 65536*17);
997
static int getlccode(lua_State * L)
999
int ch = (int) luaL_checkinteger(L, -1);
1000
check_char_range(ch, "getlccode", 65536*17);
1001
lua_pushnumber(L, get_lc_code(ch));
1005
static int setuccode(lua_State * L)
1007
return setcode(L, &set_uc_code, &set_lc_code, "setuccode", 65536*17);
1010
static int getuccode(lua_State * L)
1012
int ch = (int) luaL_checkinteger(L, -1);
1013
check_char_range(ch, "getuccode", 65536*17);
1014
lua_pushnumber(L, get_uc_code(ch));
1018
static int setsfcode(lua_State * L)
1020
return setcode(L, &set_sf_code, NULL, "setsfcode", 32768);
1023
static int getsfcode(lua_State * L)
1025
int ch = (int) luaL_checkinteger(L, -1);
1026
check_char_range(ch, "getsfcode", 65536*17);
1027
lua_pushnumber(L, get_sf_code(ch));
1031
static int setcatcode(lua_State * L)
1035
int level = cur_level;
1036
int cattable = int_par(cat_code_table_code);
1037
int n = lua_gettop(L);
1039
if (n>1 && lua_type(L,1) == LUA_TTABLE)
1041
if (n>2 && lua_isstring(L, f)) {
1042
const char *s = lua_tostring(L, f);
1043
if (strcmp(s, "global") == 0) {
1049
cattable = (int) luaL_checkinteger(L, -3);
1051
ch = (int) luaL_checkinteger(L, -2);
1052
check_char_range(ch, "setcatcode", 65536*17);
1053
val = (halfword) luaL_checkinteger(L, -1);
1054
check_char_range(val, "setcatcode", 16);
1055
set_cat_code(cattable, ch, val, level);
1059
static int getcatcode(lua_State * L)
1061
int cattable = int_par(cat_code_table_code);
1062
int ch = (int) luaL_checkinteger(L, -1);
1063
if (lua_gettop(L)>=2 && lua_type(L,-2)==LUA_TNUMBER) {
1064
cattable = luaL_checkinteger(L, -2);
1066
check_char_range(ch, "getcatcode", 65536*17);
1067
lua_pushnumber(L, get_cat_code(cattable, ch));
1072
static int setmathcode(lua_State * L)
1075
halfword cval, fval, chval;
1076
int level = cur_level;
1077
int n = lua_gettop(L);
1079
if (n>1 && lua_type(L,1) == LUA_TTABLE)
1081
if (n>2 && lua_isstring(L, f)) {
1082
const char *s = lua_tostring(L, f);
1083
if (strcmp(s, "global") == 0) {
1088
if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) {
1089
luaL_error(L, "Bad arguments for tex.setmathcode()");
1091
ch = (int) luaL_checkinteger(L, -2);
1092
check_char_range(ch, "setmathcode", 65536*17);
1094
lua_rawgeti(L, -1, 1);
1095
cval = (halfword) luaL_checkinteger(L, -1);
1096
lua_rawgeti(L, -2, 2);
1097
fval = (halfword) luaL_checkinteger(L, -1);
1098
lua_rawgeti(L, -3, 3);
1099
chval = (halfword) luaL_checkinteger(L, -1);
1102
check_char_range(cval, "setmathcode", 8);
1103
check_char_range(fval, "setmathcode", 256);
1104
check_char_range(chval, "setmathcode", 65536*17);
1105
set_math_code(ch, xetex_mathcode, cval,fval, chval, (quarterword) (level));
1109
static int getmathcode(lua_State * L)
1111
mathcodeval mval = { 0, 0, 0, 0 };
1112
int ch = (int) luaL_checkinteger(L, -1);
1113
check_char_range(ch, "getmathcode", 65536*17);
1114
mval = get_math_code(ch);
1116
lua_pushnumber(L,mval.class_value);
1117
lua_rawseti(L, -2, 1);
1118
lua_pushnumber(L,mval.family_value);
1119
lua_rawseti(L, -2, 2);
1120
lua_pushnumber(L,mval.character_value);
1121
lua_rawseti(L, -2, 3);
1127
static int setdelcode(lua_State * L)
1130
halfword sfval, scval, lfval, lcval;
1131
int level = cur_level;
1132
int n = lua_gettop(L);
1134
if (n>1 && lua_type(L,1) == LUA_TTABLE)
1136
if (n>2 && lua_isstring(L, f)) {
1137
const char *s = lua_tostring(L, f);
1138
if (strcmp(s, "global") == 0) {
1143
if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) {
1144
luaL_error(L, "Bad arguments for tex.setdelcode()");
1146
ch = (int) luaL_checkinteger(L, -2);
1147
check_char_range(ch, "setdelcode", 65536*17);
1148
lua_rawgeti(L, -1, 1);
1149
sfval = (halfword) luaL_checkinteger(L, -1);
1150
lua_rawgeti(L, -2, 2);
1151
scval = (halfword) luaL_checkinteger(L, -1);
1152
lua_rawgeti(L, -3, 3);
1153
lfval = (halfword) luaL_checkinteger(L, -1);
1154
lua_rawgeti(L, -4, 4);
1155
lcval = (halfword) luaL_checkinteger(L, -1);
1158
check_char_range(sfval, "setdelcode", 256);
1159
check_char_range(scval, "setdelcode", 65536*17);
1160
check_char_range(lfval, "setdelcode", 256);
1161
check_char_range(lcval, "setdelcode", 65536*17);
1162
set_del_code(ch, xetex_mathcode, sfval, scval, lfval, lcval, (quarterword) (level));
1167
static int getdelcode(lua_State * L)
1169
delcodeval mval = { 0, 0, 0, 0, 0, 0 };
1170
int ch = (int) luaL_checkinteger(L, -1);
1171
check_char_range(ch, "getdelcode", 65536*17);
1172
mval = get_del_code(ch);
1173
/* lua_pushnumber(L, mval.class_value); */
1174
/* lua_pushnumber(L, mval.origin_value); */
1176
lua_pushnumber(L,mval.small_family_value);
1177
lua_rawseti(L, -2, 1);
1178
lua_pushnumber(L,mval.small_character_value);
1179
lua_rawseti(L, -2, 2);
1180
lua_pushnumber(L,mval.large_family_value);
1181
lua_rawseti(L, -2, 3);
1182
lua_pushnumber(L,mval.large_character_value);
1183
lua_rawseti(L, -2, 4);
1014
1189
static int settex(lua_State * L)