diff options
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r-- | source/luametatex/source/lua/lmtinterface.h | 36 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtmplib.c | 9 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtnodelib.c | 62 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexiolib.c | 3 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexlib.c | 4 |
5 files changed, 100 insertions, 14 deletions
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h index 707d3aefb..756a25331 100644 --- a/source/luametatex/source/lua/lmtinterface.h +++ b/source/luametatex/source/lua/lmtinterface.h @@ -234,8 +234,8 @@ extern int luaextend_xcomplex (lua_State *L); /*tex Used in |lmttokenlib|. */ -# define TOKEN_METATABLE_INSTANCE "token.instance" -# define TOKEN_METATABLE_PACKAGE "token.package" +# define TOKEN_METATABLE_INSTANCE "token.instance" +# define TOKEN_METATABLE_PACKAGE "token.package" /*tex Used in |lmtepdflib|. */ @@ -255,6 +255,28 @@ extern int luaextend_xcomplex (lua_State *L); # define SPARSE_METATABLE_INSTANCE "sparse.instance" +/*tex + There are some more but for now we have no reason to alias them for performance reasons, so + that got postponed. We then also need to move the defines here: +*/ + +/* +# define DIR_METATABLE "file.directory" + +# define LUA_BYTECODES_INDIRECT + +# define TEX_METATABLE_TEX "tex.tex" +# define TEX_NEST_INSTANCE "tex.nest.instance" +# define TEX_* "tex.*" + +# define LUA_FUNCTIONS "lua.functions" +# define LUA_BYTECODES "lua.bytecodes" +# define LUA_BYTECODES_INDIRECT "lua.bytecodes.indirect" + +# define LANGUAGE_METATABLE "luatex.language" +# define LANGUAGE_FUNCTIONS "luatex.language.wordhandlers" +*/ + /*tex Currently we sometimes use numbers and sometimes strings in node properties. We can make that @@ -1458,10 +1480,12 @@ make_lua_key_alias(L, token_package, TOKEN_METATABLE_PACKAGE);\ make_lua_key_alias(L, sparse_instance, SPARSE_METATABLE_INSTANCE);\ /* */ \ make_lua_key_alias(L, pdfe_instance, PDFE_METATABLE_INSTANCE);\ -make_lua_key_alias(L, pdfe_dictionary, PDFE_METATABLE_DICTIONARY);\ -make_lua_key_alias(L, pdfe_array, PDFE_METATABLE_ARRAY);\ -make_lua_key_alias(L, pdfe_stream, PDFE_METATABLE_STREAM);\ -make_lua_key_alias(L, pdfe_reference, PDFE_METATABLE_REFERENCE);\ +make_lua_key_alias(L, pdfe_dictionary_instance, PDFE_METATABLE_DICTIONARY);\ +make_lua_key_alias(L, pdfe_array_instance, PDFE_METATABLE_ARRAY);\ +make_lua_key_alias(L, pdfe_stream_instance, PDFE_METATABLE_STREAM);\ +make_lua_key_alias(L, pdfe_reference_instance, PDFE_METATABLE_REFERENCE);\ +/* */ \ +make_lua_key_alias(L, file_handle_instance, LUA_FILEHANDLE);\ /* done */ # define declare_metapost_lua_keys(L) \ diff --git a/source/luametatex/source/lua/lmtmplib.c b/source/luametatex/source/lua/lmtmplib.c index ecbfd46b6..83fe3efd4 100644 --- a/source/luametatex/source/lua/lmtmplib.c +++ b/source/luametatex/source/lua/lmtmplib.c @@ -1703,7 +1703,8 @@ static int mplib_new(lua_State *L) *mpud = mp; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_INSTANCE); + // luaL_getmetatable(L, MP_METATABLE_INSTANCE); + lua_get_metatablelua(mplib_instance); lua_setmetatable(L, -2); return 1; } @@ -1763,7 +1764,8 @@ static int mplib_aux_wrapresults(lua_State *L, mp_run_data *res, int status, lua *v = p; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_FIGURE); + // luaL_getmetatable(L, MP_METATABLE_FIGURE); + lua_get_metatablelua(mplib_figure); lua_setmetatable(L, -2); lua_rawseti(L, -2, i); i++; @@ -2341,7 +2343,8 @@ static int mplib_figure_objects(lua_State *L) *v = p; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_OBJECT); + // luaL_getmetatable(L, MP_METATABLE_OBJECT); + lua_get_metatablelua(mplib_object); lua_setmetatable(L, -2); lua_rawseti(L, -2, i); i++; diff --git a/source/luametatex/source/lua/lmtnodelib.c b/source/luametatex/source/lua/lmtnodelib.c index 2a02fbd11..58a98f7e3 100644 --- a/source/luametatex/source/lua/lmtnodelib.c +++ b/source/luametatex/source/lua/lmtnodelib.c @@ -2489,10 +2489,18 @@ static int nodelib_direct_getgeometry(lua_State* L) lua_pushboolean(L, tex_has_box_geometry(n, offset_geometry)); lua_pushboolean(L, tex_has_box_geometry(n, orientation_geometry)); lua_pushboolean(L, tex_has_box_geometry(n, anchor_geometry)); - return 4; + lua_pushinteger(L, checked_direction_value(box_dir(n))); + return 5; } else { return 1; } + } else if (lua_toboolean(L, 2)) { + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushinteger(L, checked_direction_value(box_dir(n))); + return 5; } break; } @@ -2870,6 +2878,25 @@ static int nodelib_direct_getkerndimension(lua_State *L) } } +static int nodelib_direct_getlistdimensions(lua_State *L) +{ + halfword n = nodelib_valid_direct_from_index(L, 1); + if (n) { + switch (node_type(n)) { + /* when we need it more node types will be handled */ + case hlist_node: + case vlist_node: + lua_pushinteger(L, box_width(n)); + lua_pushinteger(L, box_height(n)); + lua_pushinteger(L, box_depth(n)); + lua_pushinteger(L, box_shift_amount(n)); + nodelib_push_direct_or_nil_node_prev(L, box_list(n)); + return 5; + } + } + return 0; +} + /* node.direct.getlist */ static int nodelib_direct_getlist(lua_State *L) @@ -3874,7 +3901,7 @@ static int nodelib_direct_remove(lua_State *L) return 3; } } else { - lua_pushinteger(L, head); + nodelib_push_direct_or_nil(L, head); lua_pushnil(L); } } else { @@ -3884,6 +3911,34 @@ static int nodelib_direct_remove(lua_State *L) return 2; } +static int nodelib_direct_remove_from_list(lua_State *L) +{ + halfword head = nodelib_valid_direct_from_index(L, 1); + int count = 0; + if (head) { + halfword id = lmt_tohalfword(L, 2); + halfword subtype = lmt_opthalfword(L, 3, -1); + halfword current = head; + while (current) { + halfword next = node_next(current); + if (node_type(current) == id && (subtype < 0 || node_subtype(current) == subtype)) { + if (current == head) { + head = next; + node_prev(next) = null; + } else { + tex_try_couple_nodes(node_prev(current), next); + } + tex_flush_node(current); + ++count; + } + current = next; + } + } + nodelib_push_direct_or_nil(L, head); + lua_push_integer(L, count); + return 2; +} + /* node.insertbefore (insert a node in a list) */ static int nodelib_userdata_insertbefore(lua_State *L) @@ -8436,7 +8491,6 @@ static int nodelib_direct_isprevglyph(lua_State *L) } } - /* direct.usesfont */ inline static int nodelib_aux_uses_font_disc(lua_State *L, halfword n, halfword font) @@ -9700,8 +9754,10 @@ static const struct luaL_Reg nodelib_direct_function_list[] = { { "rangedimensions", nodelib_direct_rangedimensions }, /* maybe get... */ { "getglyphdimensions", nodelib_direct_getglyphdimensions }, { "getkerndimension", nodelib_direct_getkerndimension }, + { "getlistdimensions", nodelib_direct_getlistdimensions }, { "patchattributes", nodelib_direct_patchattributes }, { "remove", nodelib_direct_remove }, + { "removefromlist", nodelib_direct_remove_from_list }, { "repack", nodelib_direct_repack }, { "freeze", nodelib_direct_freeze }, { "setattribute", nodelib_direct_setattribute }, diff --git a/source/luametatex/source/lua/lmttexiolib.c b/source/luametatex/source/lua/lmttexiolib.c index f7f7751d8..416293164 100644 --- a/source/luametatex/source/lua/lmttexiolib.c +++ b/source/luametatex/source/lua/lmttexiolib.c @@ -19,7 +19,8 @@ FILE *lmt_valid_file(lua_State *L) { luaL_Stream *p = (luaL_Stream *) lua_touserdata(L, 1); if (p && lua_getmetatable(L, 1)) { - luaL_getmetatable(L, LUA_FILEHANDLE); + // luaL_getmetatable(L, LUA_FILEHANDLE); + lua_get_metatablelua(file_handle_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c index 7d1f3c32f..d3f4c0ab9 100644 --- a/source/luametatex/source/lua/lmttexlib.c +++ b/source/luametatex/source/lua/lmttexlib.c @@ -27,7 +27,8 @@ /*tex Due to the nature of the accessors, this is the module with most metatables. However, we - provide getters and setters too. Users can choose what they like most. + provide getters and setters too. Users can choose what they like most. If needed we can use + fast metatable resolvers but there is no real need. */ # define TEX_METATABLE_ATTRIBUTE "tex.attribute" @@ -2604,6 +2605,7 @@ static int texlib_aux_convert(lua_State *L, int cur_code) case string_code: /* arg token */ case cs_string_code: /* arg token */ case cs_active_code: /* arg token */ + /* case cs_lastname_code: */ /* arg token */ case detokenized_code: /* arg token */ case meaning_code: /* arg token */ case to_mathstyle_code: |