summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/ltexlib.c')
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/ltexlib.c223
1 files changed, 189 insertions, 34 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
index b5a110657f4..65e55705e44 100644
--- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
@@ -789,7 +789,7 @@ static int get_item_index(lua_State * L, int i, int base)
static int gettex(lua_State * L);
-#define get_item_index_plus(L, where, base, what, value, is_assign, get_register, glue) { \
+#define get_item_index_plus(L, where, base, what, value, is_assign, get_register, texget) { \
size_t len; \
const char *str; \
int key, cs; \
@@ -804,7 +804,7 @@ static int gettex(lua_State * L);
if (key >= 0 && key <= 65535) { \
value = get_register(key); \
} else if (is_assign(eq_type(cs))) { \
- gettex(L); /* lazy */ \
+ texget = gettex(L); /* lazy */ \
} else { \
luaL_error(L, "incorrect %s name", what); \
} \
@@ -849,7 +849,11 @@ static int setdimen(lua_State * L)
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);
+ int texget = 0;
+ get_item_index_plus(L, lua_gettop(L), scaled_base, "dimen", value, is_dim_assign, get_tex_dimen_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
lua_pushinteger(L, value);
return 1;
}
@@ -877,7 +881,11 @@ static int setskip(lua_State * L)
static int getskip(lua_State * L)
{
int value = 0;
- get_item_index_plus(L, lua_gettop(L), skip_base, "skip", value, is_glue_assign, get_tex_skip_register, true);
+ int texget = 0;
+ get_item_index_plus(L, lua_gettop(L), skip_base, "skip", value, is_glue_assign, get_tex_skip_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
if (value == null) {
lua_nodelib_push_fast(L, copy_node(zero_glue));
} else {
@@ -910,22 +918,47 @@ static int setglue(lua_State * L)
static int getglue(lua_State * L)
{
int value = 0;
+ int texget = 0;
int top = lua_gettop(L);
- get_item_index_plus(L, top, skip_base, "skip", value, is_glue_assign, get_tex_skip_register, true);
- if (value == null) {
- lua_pushinteger(L,0);
- lua_pushinteger(L,0);
- lua_pushinteger(L,0);
- lua_pushinteger(L,0);
- lua_pushinteger(L,0);
+ int dim = -1;
+ if (top > 1 && lua_type(L,top) == LUA_TBOOLEAN) {
+ dim = lua_toboolean(L,top);
+ top = top - 1;
} else {
- lua_pushinteger(L,width(value));
- lua_pushinteger(L,stretch(value));
- lua_pushinteger(L,shrink(value));
- lua_pushinteger(L,stretch_order(value));
- lua_pushinteger(L,shrink_order(value));
+ lua_pushboolean(L,1);
+ dim = 1 ;
+ /* no top adaption. somewhat messy, but the gettex fallback checks itself */
+ }
+ /* checks itself for the boolean */
+ get_item_index_plus(L, top, skip_base, "glue", value, is_glue_assign, get_tex_skip_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
+ if (dim == 0) {
+ /* false */
+ if (value == null) {
+ lua_pushinteger(L,0);
+ } else {
+ lua_pushinteger(L,width(value));
+ }
+ return 1;
+ } else {
+ /* true and nil */
+ if (value == null) {
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ } else {
+ lua_pushinteger(L,width(value));
+ lua_pushinteger(L,stretch(value));
+ lua_pushinteger(L,shrink(value));
+ lua_pushinteger(L,stretch_order(value));
+ lua_pushinteger(L,shrink_order(value));
+ }
+ return 5;
}
- return 5;
}
static int ismuskip(lua_State * L)
@@ -947,7 +980,11 @@ static int setmuskip(lua_State * L)
static int getmuskip(lua_State * L)
{
int value = 0;
- get_item_index_plus(L, lua_gettop(L), mu_skip_base, "muskip", value, is_mu_glue_assign, get_tex_mu_skip_register, true);
+ int texget = 0;
+ get_item_index_plus(L, lua_gettop(L), mu_skip_base, "muskip", value, is_mu_glue_assign, get_tex_mu_skip_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
lua_nodelib_push_fast(L, copy_node(value));
return 1;
}
@@ -976,16 +1013,45 @@ static int setmuglue(lua_State * L)
static int getmuglue(lua_State * L)
{
int value = 0;
- get_item_index_plus(L, lua_gettop(L), mu_skip_base, "muskip", value, is_mu_glue_assign, get_tex_mu_skip_register, true);
- if (value == null) {
- lua_pushnil(L);
- return 1;
+ int texget = 0;
+ int top = lua_gettop(L);
+ int dim = -1;
+ if (top > 1 && lua_type(L,top) == LUA_TBOOLEAN) {
+ dim = lua_toboolean(L,top);
+ top = top - 1;
} else {
- lua_pushinteger(L,width(value));
- lua_pushinteger(L,stretch(value));
- lua_pushinteger(L,shrink(value));
- lua_pushinteger(L,stretch_order(value));
- lua_pushinteger(L,shrink_order(value));
+ lua_pushboolean(L,1);
+ dim = 1 ;
+ /* no top adaption. somewhat messy, but the gettex fallback checks itself */
+ }
+ /* checks itself for the boolean */
+ get_item_index_plus(L, top, mu_skip_base, "muskip", value, is_mu_glue_assign, get_tex_mu_skip_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
+ if (dim == 0) {
+ /* false */
+ if (value == null) {
+ lua_pushinteger(L,0);
+ } else {
+ lua_pushinteger(L,width(value));
+ }
+ return 1;
+ } else {
+ /* true and nil */
+ if (value == null) {
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ lua_pushinteger(L,0);
+ } else {
+ lua_pushinteger(L,width(value));
+ lua_pushinteger(L,stretch(value));
+ lua_pushinteger(L,shrink(value));
+ lua_pushinteger(L,stretch_order(value));
+ lua_pushinteger(L,shrink_order(value));
+ }
return 5;
}
}
@@ -1015,7 +1081,11 @@ static int setcount(lua_State * L)
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);
+ int texget = 0;
+ get_item_index_plus(L, lua_gettop(L), count_base, "count", value, is_int_assign, get_tex_count_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
lua_pushinteger(L, value);
return 1;
}
@@ -1047,7 +1117,11 @@ static int setattribute(lua_State * L)
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);
+ int texget = 0;
+ get_item_index_plus(L, lua_gettop(L), attribute_base, "attribute", value, is_attr_assign, get_tex_attribute_register, texget);
+ if (texget > 0) {
+ return texget;
+ }
lua_pushinteger(L, value);
return 1;
}
@@ -2278,7 +2352,7 @@ static const struct luaL_Reg nest_m[] = {
static void init_nest_lib(lua_State * L)
{
luaL_newmetatable(L, NEST_METATABLE);
- luaL_register(L, NULL, nest_m);
+ luaL_openlib(L, NULL, nest_m, 0);
lua_pop(L, 1);
}
@@ -2656,7 +2730,7 @@ static int tex_enableprimitives(lua_State * L)
#define get_dimen_par(A,B) do { \
lua_key_rawgeti(A); \
if (lua_type(L, -1) == LUA_TNUMBER) { \
- A = (int) lua_tointeger(L, -1); \
+ A = (int) lua_roundnumber(L, -1); \
} else { \
A = (B); \
} \
@@ -2937,11 +3011,12 @@ static int tex_run_boot(lua_State * L)
/* Initialize synctex primitive */
synctexinitcommand();
/* tex is ready to go, now */
+ /*
unhide_lua_table(Luas, "tex", tex_table_id);
unhide_lua_table(Luas, "pdf", pdf_table_id);
unhide_lua_table(Luas, "token", token_table_id);
unhide_lua_table(Luas, "node", node_table_id);
-
+ */
lua_pushboolean(L, 1); /* true */
return 1;
}
@@ -3040,6 +3115,7 @@ static int tex_save_box_resource(lua_State * L)
int attributes = null;
int resources = null;
int type = 0;
+ int margin = pdf_xform_margin;
boolean immediate = false;
/* box attributes resources */
halfword boxnumber = lua_tointeger(L,1);
@@ -3057,6 +3133,9 @@ static int tex_save_box_resource(lua_State * L)
if (lua_type(L,5) == LUA_TNUMBER) {
type = lua_tointeger(L, 5);
}
+ if (lua_type(L,6) == LUA_TNUMBER) {
+ margin = lua_tointeger(L, 6);
+ }
/* more or less same as scanner variant */
boxdata = box(boxnumber);
if (boxdata == null)
@@ -3073,6 +3152,7 @@ static int tex_save_box_resource(lua_State * L)
set_obj_xform_height(static_pdf, index, height(boxdata));
set_obj_xform_depth(static_pdf, index, depth(boxdata));
set_obj_xform_type(static_pdf, index, type);
+ set_obj_xform_margin(static_pdf, index, margin);
box(boxnumber) = null;
last_saved_box_index = index;
lua_pushinteger(L, index);
@@ -3137,14 +3217,16 @@ static int tex_get_box_resource_dimensions(lua_State * L)
lua_pushnil(L);
lua_pushnil(L);
lua_pushnil(L);
+ lua_pushnil(L);
} else {
index = lua_tointeger(L,1);
check_obj_type(static_pdf, obj_type_xform, 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));
+ lua_pushinteger(L, (int) obj_xform_margin(static_pdf, index));
}
- return 3;
+ return 4;
}
static int tex_build_page(lua_State * L)
@@ -3153,6 +3235,69 @@ static int tex_build_page(lua_State * L)
return 0;
}
+/* synctex */
+
+static int lua_set_synctex_mode(lua_State * L)
+{
+ halfword mode = lua_tointeger(L, 1);
+ synctex_set_mode(mode);
+ return 0;
+}
+static int lua_get_synctex_mode(lua_State * L)
+{
+ lua_pushinteger(L,synctex_get_mode());
+ return 1;
+}
+
+static int lua_set_synctex_tag(lua_State * L)
+{
+ halfword tag = lua_tointeger(L, 1);
+ synctex_set_tag(tag);
+ return 0;
+}
+
+static int lua_get_synctex_tag(lua_State * L)
+{
+ lua_pushinteger(L,synctex_get_tag());
+ return 1;
+}
+
+static int lua_force_synctex_tag(lua_State * L)
+{
+ halfword tag = lua_tointeger(L, 1);
+ synctex_force_tag(tag);
+ return 0;
+}
+
+static int lua_force_synctex_line(lua_State * L)
+{
+ halfword line = lua_tointeger(L, 1);
+ synctex_force_line(line);
+ return 0;
+}
+
+static int lua_set_synctex_line(lua_State * L)
+{
+ halfword line = lua_tointeger(L, 1);
+ synctex_set_line(line);
+ return 0;
+}
+
+static int lua_get_synctex_line(lua_State * L)
+{
+ lua_pushinteger(L,synctex_get_line());
+ return 1;
+}
+
+static int lua_set_synctex_no_files(lua_State * L)
+{
+ halfword flag = lua_tointeger(L, 1);
+ synctex_set_no_files(flag);
+ return 0;
+}
+
+/* till here */
+
void init_tex_table(lua_State * L)
{
lua_createtable(L, 0, 3);
@@ -3252,13 +3397,23 @@ static const struct luaL_Reg texlib[] = {
{ "getboxresourcedimensions", tex_get_box_resource_dimensions },
/* just for testing: it will probably stay but maybe with options */
{ "triggerbuildpage", tex_build_page },
+ /* not the best place but better than in node */
+ { "set_synctex_mode", lua_set_synctex_mode },
+ { "get_synctex_mode", lua_get_synctex_mode },
+ { "set_synctex_tag", lua_set_synctex_tag },
+ { "get_synctex_tag", lua_get_synctex_tag },
+ { "set_synctex_no_files", lua_set_synctex_no_files },
+ { "force_synctex_tag", lua_force_synctex_tag },
+ { "force_synctex_line", lua_force_synctex_line },
+ { "set_synctex_line", lua_set_synctex_line },
+ { "get_synctex_line", lua_get_synctex_line },
/* sentinel */
{ NULL, NULL }
};
int luaopen_tex(lua_State * L)
{
- luaL_register(L, "tex", texlib);
+ luaL_openlib(L, "tex", texlib, 0);
/* *INDENT-OFF* */
make_table(L, "attribute", "tex.attribute", "getattribute", "setattribute");
make_table(L, "skip", "tex.skip", "getskip", "setskip");