summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/lua
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-21 09:16:59 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-21 09:16:59 +0000
commit388463b9fa865c3b2311508c41647b0f3c532031 (patch)
tree1cdfbf5552d0783ecbcc52017e49567e5042af33 /Build/source/texk/web2c/luatexdir/lua
parentabd0b00a4e8c1ac6f5b20c7474d70ef579129991 (diff)
Import MetaPost 1.800 and LuaTeX beta-0.75.0 from LuaTeX repository r4604
git-svn-id: svn://tug.org/texlive/trunk@29453 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua')
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c14
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lepdflib.cc157
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lfontlib.c219
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/limglib.c94
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/liolib.c683
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/liolibext.c668
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lkpselib.c20
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/llanglib.c16
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/llfslibext.c2
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/llualib.c6
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lnodelib.c3711
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/loslibext.c18
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lpdflib.c111
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc952
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lstatslib.c22
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lstrlibext.c379
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/ltexiolib.c4
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/ltexlib.c250
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/ltokenlib.c12
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luagen.w18
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luainit.w178
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luanode.w21
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luastuff.w112
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luatex-api.h25
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luatoken.w37
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/texluac.w538
26 files changed, 4910 insertions, 3357 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
index 8ca0f84e3c3..1153c8d98eb 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
@@ -21,7 +21,7 @@
#include "lua/luatex-api.h"
static const char _svn_version[] =
- "$Id: lcallbacklib.c 3965 2010-11-22 12:38:45Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lcallbacklib.c $";
+ "$Id: lcallbacklib.c 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lcallbacklib.c $";
int callback_count = 0;
int saved_callback_count = 0;
@@ -44,9 +44,11 @@ static const char *const callbacknames[] = {
"find_truetype_file", "read_truetype_file",
"find_opentype_file", "read_opentype_file",
"find_sfd_file", "read_sfd_file",
+ "find_cidmap_file", "read_cidmap_file",
"find_pk_file", "read_pk_file",
"show_error_hook",
"process_input_buffer", "process_output_buffer",
+ "process_jobname",
"start_page_number", "stop_page_number",
"start_run", "stop_run",
"define_font",
@@ -120,7 +122,7 @@ void get_lua_number(const char *table, const char *name, int *target)
if (lua_istable(Luas, -1)) {
lua_getfield(Luas, -1, name);
if (lua_isnumber(Luas, -1)) {
- lua_number2int(*target, lua_tonumber(Luas, -1));
+ *target = (int)lua_tonumber(Luas, -1);
}
}
lua_settop(Luas, stacktop);
@@ -136,7 +138,7 @@ void get_saved_lua_number(int r, const char *name, int *target)
if (lua_istable(Luas, -1)) {
lua_getfield(Luas, -1, name);
if (lua_isnumber(Luas, -1)) {
- lua_number2int(*target, lua_tonumber(Luas, -1));
+ *target=(int)lua_tonumber(Luas, -1);
}
}
lua_settop(Luas, stacktop);
@@ -324,7 +326,7 @@ int do_run_callback(int special, const char *values, va_list vl)
/* Can't be more precise here, could be called before
* TeX initialization is complete
*/
- if (!log_opened) {
+ if (!log_opened_global) {
fprintf(stderr, "This went wrong: %s\n", lua_tostring(L, -1));
error();
} else {
@@ -356,7 +358,7 @@ int do_run_callback(int special, const char *values, va_list vl)
lua_typename(L, lua_type(L, nres)));
goto EXIT;
}
- lua_number2int(b, lua_tonumber(L, nres));
+ b=(int)lua_tonumber(L, nres);
*va_arg(vl, int *) = b;
break;
case CALLBACK_LINE: /* TeX line */
@@ -512,7 +514,7 @@ static int callback_listf(lua_State * L)
return 1;
}
-static const struct luaL_reg callbacklib[] = {
+static const struct luaL_Reg callbacklib[] = {
{"find", callback_find},
{"register", callback_register},
{"list", callback_listf},
diff --git a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
index b003b6b1931..5bc11a38bc0 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
+++ b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
@@ -1,7 +1,7 @@
/* lepdflib.cc
- Copyright 2009-2012 Taco Hoekwater <taco@luatex.org>
- Copyright 2009-2012 Hartmut Henkel <hartmut@luatex.org>
+ Copyright 2009-2013 Taco Hoekwater <taco@luatex.org>
+ Copyright 2009-2013 Hartmut Henkel <hartmut@luatex.org>
This file is part of LuaTeX.
@@ -19,7 +19,7 @@
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
static const char _svn_version[] =
- "$Id: lepdflib.cc 4415 2012-05-09 19:56:06Z oneiros $ "
+ "$Id: lepdflib.cc 4573 2013-02-03 16:47:07Z hhenkel $ "
"$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lepdflib.cc $";
#include "image/epdf.h"
@@ -53,6 +53,8 @@ static const char *ErrorCodeNames[] = { "None", "OpenFile", "BadCatalog",
#define M_Array "Array"
#define M_Catalog "Catalog"
#define M_Dict "Dict"
+#define M_EmbFile "EmbFile"
+#define M_FileSpec "FileSpec"
#define M_GooString "GooString"
#define M_LinkDest "LinkDest"
#define M_Link "Link"
@@ -85,6 +87,8 @@ new_poppler_userdata(Annot);
new_poppler_userdata(Array);
new_poppler_userdata(Catalog);
new_poppler_userdata(Dict);
+new_poppler_userdata(EmbFile);
+new_poppler_userdata(FileSpec);
new_poppler_userdata(LinkDest);
new_poppler_userdata(Links);
new_poppler_userdata(Object);
@@ -179,7 +183,7 @@ static int l_new_PDFRectangle(lua_State * L)
return 1;
}
-static const struct luaL_Reg epdflib[] = {
+static const struct luaL_Reg epdflib_f[] = {
{"open", l_open_PDFDoc},
{"Array", l_new_Array},
{"Dict", l_new_Dict},
@@ -350,7 +354,11 @@ static int m_Annot__gc(lua_State * L)
printf("\n===== Annot GC ===== uin=<%p>\n", uin);
#endif
if (uin->atype == ALLOC_LEPDF)
+#if 1 /* def HAVE_ANNOTDECREFCNT */
((Annot *) uin->d)->decRefCnt();
+#else
+ delete(Annot *) uin->d;
+#endif
return 0;
}
@@ -611,6 +619,25 @@ static int m_Catalog_findDest(lua_State * L)
m_poppler_get_poppler(Catalog, Object, getDests);
m_poppler_get_INT(Catalog, numEmbeddedFiles);
+static int m_Catalog_embeddedFile(lua_State * L)
+{
+ int i, len;
+ udstruct *uin, *uout;
+ uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
+ if (uin->pd != NULL && uin->pd->pc != uin->pc)
+ pdfdoc_changed_error(L);
+ i = luaL_checkint(L, 2);
+ len = ((Catalog *) uin->d)->numEmbeddedFiles();
+ if (i > 0 && i <= len) {
+ uout = new_FileSpec_userdata(L);
+ uout->d = ((Catalog *) uin->d)->embeddedFile(i - 1);
+ uout->pc = uin->pc;
+ uout->pd = uin->pd;
+ } else
+ lua_pushnil(L);
+ return 1;
+}
+
m_poppler_get_INT(Catalog, numJS);
static int m_Catalog_getJS(lua_State * L)
@@ -652,6 +679,7 @@ static const struct luaL_Reg Catalog_m[] = {
{"findDest", m_Catalog_findDest},
{"getDests", m_Catalog_getDests},
{"numEmbeddedFiles", m_Catalog_numEmbeddedFiles},
+ {"embeddedFile", m_Catalog_embeddedFile},
{"numJS", m_Catalog_numJS},
{"getJS", m_Catalog_getJS},
{"getOutline", m_Catalog_getOutline},
@@ -862,6 +890,80 @@ static const struct luaL_Reg Dict_m[] = {
};
//**********************************************************************
+// EmbFile
+
+m_poppler_get_INT(EmbFile, size);
+m_poppler_get_GOOSTRING(EmbFile, modDate);
+m_poppler_get_GOOSTRING(EmbFile, createDate);
+m_poppler_get_GOOSTRING(EmbFile, checksum);
+m_poppler_get_GOOSTRING(EmbFile, mimeType);
+
+m_poppler_get_BOOL(EmbFile, isOk);
+
+static int m_EmbFile_save(lua_State * L)
+{
+ const char *s;
+ size_t len;
+ udstruct *uin;
+ uin = (udstruct *) luaL_checkudata(L, 1, M_EmbFile);
+ if (uin->pd != NULL && uin->pd->pc != uin->pc)
+ pdfdoc_changed_error(L);
+ s = luaL_checklstring(L, 2, &len);
+ if (((EmbFile *) uin->d)->save(s))
+ lua_pushboolean(L, 1);
+ else
+ lua_pushboolean(L, 0);
+ return 1;
+}
+
+m_poppler__tostring(EmbFile);
+
+static const struct luaL_Reg EmbFile_m[] = {
+ {"size", m_EmbFile_size},
+ {"modDate", m_EmbFile_modDate},
+ {"createDate", m_EmbFile_createDate},
+ {"checksum", m_EmbFile_checksum},
+ {"mimeType", m_EmbFile_mimeType},
+ {"isOk", m_EmbFile_isOk},
+ {"save", m_EmbFile_save},
+ {"__tostring", m_EmbFile__tostring},
+ {NULL, NULL} // sentinel
+};
+
+//**********************************************************************
+// FileSpec
+
+m_poppler_get_BOOL(FileSpec, isOk);
+m_poppler_get_GOOSTRING(FileSpec, getFileName);
+m_poppler_get_GOOSTRING(FileSpec, getFileNameForPlatform);
+m_poppler_get_GOOSTRING(FileSpec, getDescription);
+
+static int m_FileSpec_getEmbeddedFile(lua_State * L)
+{
+ udstruct *uin, *uout;
+ uin = (udstruct *) luaL_checkudata(L, 1, M_FileSpec);
+ if (uin->pd != NULL && uin->pd->pc != uin->pc)
+ pdfdoc_changed_error(L);
+ uout = new_EmbFile_userdata(L);
+ uout->d = ((FileSpec *) uin->d)->getEmbeddedFile();
+ uout->pc = uin->pc;
+ uout->pd = uin->pd;
+ return 1;
+}
+
+m_poppler__tostring(FileSpec);
+
+static const struct luaL_Reg FileSpec_m[] = {
+ {"isOk", m_FileSpec_isOk},
+ {"getFileName", m_FileSpec_getFileName},
+ {"getFileNameForPlatform", m_FileSpec_getFileNameForPlatform},
+ {"getDescription", m_FileSpec_getDescription},
+ {"getEmbeddedFile", m_FileSpec_getEmbeddedFile},
+ {"__tostring", m_FileSpec__tostring},
+ {NULL, NULL} // sentinel
+};
+
+//**********************************************************************
// GooString
static int m_GooString__tostring(lua_State * L)
@@ -1406,7 +1508,6 @@ static int m_Object_getRefGen(lua_State * L)
static int m_Object_getCmd(lua_State * L)
{
- char *s;
udstruct *uin;
uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
if (uin->pd != NULL && uin->pd->pc != uin->pc)
@@ -1767,8 +1868,10 @@ static int m_Object__gc(lua_State * L)
#ifdef DEBUG
printf("\n===== Object GC ===== uin=<%p>\n", uin);
#endif
- if (uin->atype == ALLOC_LEPDF)
+ if (uin->atype == ALLOC_LEPDF) {
+ ((Object *) uin->d)->free();
delete(Object *) uin->d;
+ }
return 0;
}
@@ -2514,33 +2617,35 @@ static const struct luaL_Reg XRefEntry_m[] = {
//**********************************************************************
-#define register_meta(type) \
+#define setfuncs_meta(type) \
luaL_newmetatable(L, M_##type); \
lua_pushvalue(L, -1); \
lua_setfield(L, -2, "__index"); \
lua_pushstring(L, "no user access"); \
lua_setfield(L, -2, "__metatable"); \
- luaL_register(L, NULL, type##_m)
+ luaL_setfuncs(L, type##_m, 0)
int luaopen_epdf(lua_State * L)
{
- register_meta(Annot);
- register_meta(Annots);
- register_meta(Array);
- register_meta(Catalog);
- register_meta(Dict);
- register_meta(GooString);
- register_meta(LinkDest);
- register_meta(Links);
- register_meta(Object);
- register_meta(Page);
- register_meta(PDFDoc);
- register_meta(PDFRectangle);
- register_meta(Ref);
- register_meta(Stream);
- register_meta(XRef);
- register_meta(XRefEntry);
-
- luaL_register(L, "epdf", epdflib);
+ setfuncs_meta(Annot);
+ setfuncs_meta(Annots);
+ setfuncs_meta(Array);
+ setfuncs_meta(Catalog);
+ setfuncs_meta(Dict);
+ setfuncs_meta(EmbFile);
+ setfuncs_meta(FileSpec);
+ setfuncs_meta(GooString);
+ setfuncs_meta(LinkDest);
+ setfuncs_meta(Links);
+ setfuncs_meta(Object);
+ setfuncs_meta(Page);
+ setfuncs_meta(PDFDoc);
+ setfuncs_meta(PDFRectangle);
+ setfuncs_meta(Ref);
+ setfuncs_meta(Stream);
+ setfuncs_meta(XRef);
+ setfuncs_meta(XRefEntry);
+
+ luaL_newlib(L, epdflib_f);
return 1;
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c
index 53aad41a0e4..e66f2f0ab45 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c
@@ -1,6 +1,6 @@
/* lfontlib.c
-
- Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 2006-2011 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -17,20 +17,19 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+static const char _svn_version[] =
+ "$Id: lfontlib.c 4524 2012-12-20 15:38:02Z taco $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lfontlib.c $";
+
#include "ptexlib.h"
#include "lua/luatex-api.h"
-
-static const char _svn_version[] =
- "$Id: lfontlib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lfontlib.c $";
-
#define TIMERS 0
#if TIMERS
# include <sys/time.h>
#endif
-
static int get_fontid(void)
{
if (font_tables == NULL || font_tables[0] == NULL) {
@@ -48,7 +47,7 @@ static int font_read_tfm(lua_State * L)
if (lua_isstring(L, 1)) {
cnom = lua_tostring(L, 1);
if (lua_isnumber(L, 2)) {
- lua_number2int(s, lua_tonumber(L, 2));
+ s=(int)lua_tonumber(L, 2);
if (strlen(cnom)) {
f = get_fontid();
if (read_tfm_info(f, cnom, s)) {
@@ -80,11 +79,10 @@ static int font_read_vf(lua_State * L)
cnom = lua_tostring(L, 1);
if (strlen(cnom)) {
if (lua_isnumber(L, 2)) {
- lua_number2int(i, lua_tonumber(L, 2));
+ i=(int)lua_tonumber(L, 2);
return make_vf_table(L, cnom, (scaled) i);
} else {
- luaL_error(L,
- "expected an integer size as second argument");
+ luaL_error(L, "expected an integer size as second argument");
return 2;
}
}
@@ -121,8 +119,8 @@ static int tex_max_font(lua_State * L)
static int tex_each_font_next(lua_State * L)
{
int i, m; /* id */
- lua_number2int(m, lua_tonumber(L, 1));
- lua_number2int(i, lua_tonumber(L, 2));
+ m=(int)lua_tonumber(L, 1);
+ i=(int)lua_tonumber(L, 2);
i++;
while (i <= m && !is_valid_font(i))
i++;
@@ -178,7 +176,7 @@ static int setfont(lua_State * L)
font_from_lua(L, i);
} else {
luaL_error(L,
- "that font has been accessed already, changing it is forbidden");
+ "that font has been accessed already, changing it is forbidden");
}
} else {
luaL_error(L, "that integer id is not a valid font");
@@ -247,17 +245,17 @@ static int getfontid(lua_State * L)
{
const char *s;
size_t ff;
- int cur_cs;
+ int cs;
int f;
if (lua_type(L, 1) == LUA_TSTRING) {
s = lua_tolstring(L, 1, &ff);
- cur_cs = string_lookup(s, ff);
- if (cur_cs == undefined_control_sequence || cur_cs == undefined_cs_cmd
- || eq_type(cur_cs) != set_font_cmd) {
+ cs = string_lookup(s, ff);
+ if (cs == undefined_control_sequence || cs == undefined_cs_cmd
+ || eq_type(cs) != set_font_cmd) {
lua_pushstring(L, "not a valid font csname");
f = -1;
} else {
- f = equiv(cur_cs);
+ f = equiv(cs);
}
lua_pushnumber(L, f);
} else {
@@ -267,7 +265,7 @@ static int getfontid(lua_State * L)
}
-static const struct luaL_reg fontlib[] = {
+static const struct luaL_Reg fontlib[] = {
{"read_tfm", font_read_tfm},
{"read_vf", font_read_vf},
{"current", tex_current_font},
@@ -288,3 +286,184 @@ int luaopen_font(lua_State * L)
make_table(L, "fonts", "getfont", "setfont");
return 1;
}
+
+/**********************************************************************/
+/* "vf" library: Lua functions within virtual fonts */
+
+static int l_vf_char(lua_State * L)
+{
+ int k;
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.char() outside virtual font");
+ k = (int) luaL_checkinteger(L, 1);
+ if (!char_exists(vsp->lf, (int) k)) {
+ char_warning(vsp->lf, (int) k);
+ } else {
+ if (has_packet(vsp->lf, (int) k))
+ do_vf_packet(static_pdf, vsp->lf, (int) k);
+ else
+ backend_out[glyph_node] (static_pdf, vsp->lf, (int) k);
+ }
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ mat_p->pos.h += char_width(vsp->lf, (int) k);
+ synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos);
+ return 0;
+}
+
+static int l_vf_down(lua_State * L)
+{
+ scaled i;
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.down() outside virtual font");
+ i = (scaled) luaL_checkinteger(L, 1);
+ i = store_scaled_f(i, vsp->fs_f);
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ mat_p->pos.v += i;
+ synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos);
+ return 0;
+}
+
+static int l_vf_fontid(lua_State * L)
+{
+ vf_struct *vsp = static_pdf->vfstruct;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.fontid() outside virtual font");
+ vsp->lf = (int) luaL_checkinteger(L, 1);
+ return 0;
+}
+
+static int l_vf_image(lua_State * L)
+{
+ int k;
+ vf_struct *vsp = static_pdf->vfstruct;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.image() outside virtual font");
+ k = (int) luaL_checkinteger(L, 1);
+ vf_out_image(static_pdf, k);
+ return 0;
+}
+
+static int l_vf_node(lua_State * L)
+{
+ int k;
+ vf_struct *vsp = static_pdf->vfstruct;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.node() outside virtual font");
+ k = (int) luaL_checkinteger(L, 1);
+ hlist_out(static_pdf, (halfword) k);
+ return 0;
+}
+
+static int l_vf_nop(lua_State * L)
+{
+ vf_struct *vsp = static_pdf->vfstruct;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.nop() outside virtual font");
+ return 0;
+}
+
+static int l_vf_pop(lua_State * L)
+{
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.pop() outside virtual font");
+ if (vsp->packet_stack_level == vsp->packet_stack_minlevel)
+ pdf_error("vf", "packet_stack_level underflow");
+ vsp->packet_stack_level--;
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos);
+ return 0;
+}
+
+static int l_vf_push(lua_State * L)
+{
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.push() outside virtual font");
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ vsp->packet_stack_level++;
+ if (vsp->packet_stack_level == packet_stack_size)
+ pdf_error("vf", "packet_stack_level overflow");
+ vsp->packet_stack[vsp->packet_stack_level] = *mat_p;
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ return 0;
+}
+
+static int l_vf_right(lua_State * L)
+{
+ scaled i;
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.right() outside virtual font");
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ i = (scaled) luaL_checkinteger(L, 1);
+ i = store_scaled_f(i, vsp->fs_f);
+ mat_p->pos.h += i;
+ synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos);
+ return 0;
+}
+
+static int l_vf_rule(lua_State * L)
+{
+ scaledpos size;
+ vf_struct *vsp = static_pdf->vfstruct;
+ packet_stack_record *mat_p;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.rule() outside virtual font");
+ size.h = (scaled) luaL_checkinteger(L, 1);
+ size.v = (scaled) luaL_checkinteger(L, 2);
+ size.h = store_scaled_f(size.h, vsp->fs_f);
+ size.v = store_scaled_f(size.v, vsp->fs_f);
+ if (size.h > 0 && size.v > 0)
+ pdf_place_rule(static_pdf, 0, size); /* the 0 is unused */
+ mat_p = &(vsp->packet_stack[vsp->packet_stack_level]);
+ mat_p->pos.h += size.h;
+ synch_pos_with_cur(static_pdf->posstruct, vsp->refpos, mat_p->pos);
+ return 0;
+}
+
+static int l_vf_special(lua_State * L)
+{
+ const_lstring st;
+ int texstr;
+ vf_struct *vsp = static_pdf->vfstruct;
+ if (!vsp->vflua)
+ pdf_error("vf", "vf.special() outside virtual font");
+ st.s = lua_tolstring(L, 1, &(st.l));
+ texstr = maketexlstring(st.s, st.l);
+ pdf_literal(static_pdf, texstr, scan_special, false);
+ flush_str(texstr);
+ return 0;
+}
+
+static const struct luaL_Reg vflib[] = {
+ {"char", l_vf_char},
+ {"down", l_vf_down},
+ /* {"font", l_vf_font}, */
+ {"fontid", l_vf_fontid},
+ {"image", l_vf_image},
+ /* {"lua", l_vf_lua}, */
+ {"node", l_vf_node},
+ {"nop", l_vf_nop},
+ {"pop", l_vf_pop},
+ {"push", l_vf_push},
+ {"right", l_vf_right},
+ {"rule", l_vf_rule},
+ /* {"scale", l_vf_scale}, */
+ /* {"slot", l_vf_slot}, */
+ {"special", l_vf_special},
+ {NULL, NULL} /* sentinel */
+};
+
+int luaopen_vf(lua_State * L)
+{
+ luaL_register(L, "vf", vflib);
+ return 1;
+}
diff --git a/Build/source/texk/web2c/luatexdir/lua/limglib.c b/Build/source/texk/web2c/luatexdir/lua/limglib.c
index d9db5fa1eba..b5fa2c2fdbd 100644
--- a/Build/source/texk/web2c/luatexdir/lua/limglib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/limglib.c
@@ -1,6 +1,6 @@
/* limglib.c
- Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
+ Copyright 2006-2013 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -18,16 +18,18 @@
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
static const char _svn_version[] =
- "$Id: limglib.c 4051 2011-01-09 22:41:33Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/limglib.c $";
+ "$Id: limglib.c 4573 2013-02-03 16:47:07Z hhenkel $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/limglib.c $";
#include "ptexlib.h"
#include "lua/luatex-api.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
-#include "lua51/lua.h"
-#include "lua51/lauxlib.h"
+#include "lua52/lua.h"
+#include "lua52/lauxlib.h"
+
+#define IMG_ENV "img_env"
/**********************************************************************/
@@ -63,8 +65,8 @@ void stackDump(lua_State * L, char *s)
typedef enum { P__ZERO, P_ATTR, P_BBOX, P_COLORDEPTH, P_COLORSPACE, P_DEPTH,
P_FILENAME, P_FILEPATH, P_HEIGHT, P_IMAGETYPE, P_INDEX, P_OBJNUM,
- P_PAGE, P_PAGEBOX, P_TOTALPAGES, P_ROTATION, P_STREAM, P_TRANSFORM,
- P_WIDTH, P_XRES, P_XSIZE, P_YRES, P_YSIZE, P__SENTINEL
+ P_PAGEBOX, P_PAGE, P_TOTALPAGES, P_ROTATION, P_STREAM, P_TRANSFORM,
+ P_VISIBLEFILENAME, P_WIDTH, P_XRES, P_XSIZE, P_YRES, P_YSIZE, P__SENTINEL
} parm_idx;
static const parm_struct img_parms[] = {
@@ -80,12 +82,13 @@ static const parm_struct img_parms[] = {
{"imagetype", P_IMAGETYPE},
{"index", P_INDEX},
{"objnum", P_OBJNUM},
- {"page", P_PAGE},
{"pagebox", P_PAGEBOX},
+ {"page", P_PAGE},
{"pages", P_TOTALPAGES},
{"rotation", P_ROTATION},
{"stream", P_STREAM},
{"transform", P_TRANSFORM},
+ {"visiblefilename", P_VISIBLEFILENAME},
{"width", P_WIDTH},
{"xres", P_XRES},
{"xsize", P_XSIZE},
@@ -109,13 +112,15 @@ static void image_to_lua(lua_State * L, image * a)
int i, j;
image_dict *d = img_dict(a);
assert(d != NULL);
- lua_pushvalue(L, -1); /* k k u ... */
- lua_gettable(L, LUA_ENVIRONINDEX); /* i? k u ... */
- if (!lua_isnumber(L, -1)) /* !i k u ... */
+ lua_pushstring(L, IMG_ENV); /* s k u ... */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t k u ... */
+ lua_pushvalue(L, -2); /* k t k u ... */
+ lua_gettable(L, -2); /* i? t k u ... */
+ if (!lua_isnumber(L, -1)) /* !i t k u ... */
luaL_error(L, "image_to_lua(): %s is not a valid image key",
- lua_tostring(L, -2));
- i = (int) lua_tointeger(L, -1); /* i k u ... */
- lua_pop(L, 2); /* u ... */
+ lua_tostring(L, -3));
+ i = (int) lua_tointeger(L, -1); /* i t k u ... */
+ lua_pop(L, 3); /* u ... */
switch (i) {
case P_WIDTH:
if (is_wd_running(a))
@@ -145,6 +150,13 @@ static void image_to_lua(lua_State * L, image * a)
else
lua_pushstring(L, img_filename(d));
break;
+ case P_VISIBLEFILENAME:
+ if (img_visiblefilename(d) == NULL
+ || strlen(img_visiblefilename(d)) == 0)
+ lua_pushnil(L);
+ else
+ lua_pushstring(L, img_visiblefilename(d));
+ break;
case P_FILEPATH:
if (img_filepath(d) == NULL || strlen(img_filepath(d)) == 0)
lua_pushnil(L);
@@ -270,13 +282,15 @@ static void lua_to_image(lua_State * L, image * a)
int i;
image_dict *d = img_dict(a);
assert(d != NULL);
- lua_pushvalue(L, -2); /* k v k t ... */
- lua_gettable(L, LUA_ENVIRONINDEX); /* i? v k t ... */
- if (!lua_isnumber(L, -1)) /* !i v k t ... */
+ lua_pushstring(L, IMG_ENV); /* s v k t ... */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t v k t ... */
+ lua_pushvalue(L, -3); /* k t v k t ... */
+ lua_gettable(L, -2); /* i? t v k t ... */
+ if (!lua_isnumber(L, -1)) /* !i t v k t ... */
luaL_error(L, "lua_to_image(): %s is not a valid image key",
- lua_tostring(L, -3));
- i = (int) lua_tointeger(L, -1); /* i v k t ... */
- lua_pop(L, 1); /* v k t ... */
+ lua_tostring(L, -4));
+ i = (int) lua_tointeger(L, -1); /* i t v k t ... */
+ lua_pop(L, 2); /* v k t ... */
switch (i) {
case P_WIDTH:
if (lua_isnil(L, -1))
@@ -329,6 +343,18 @@ static void lua_to_image(lua_State * L, image * a)
} else
luaL_error(L, "image.filename needs string value");
break;
+ case P_VISIBLEFILENAME:
+ if (img_state(d) >= DICT_FILESCANNED)
+ luaL_error(L, "image.visiblefilename is now read-only");
+ if (img_type(d) == IMG_TYPE_PDFSTREAM)
+ luaL_error(L,
+ "image.visiblefilename can't be used with image.stream");
+ if (lua_isstring(L, -1)) {
+ xfree(img_visiblefilename(d));
+ img_visiblefilename(d) = xstrdup(lua_tostring(L, -1));
+ } else
+ luaL_error(L, "image.visiblefilename needs string value");
+ break;
case P_ATTR:
if (img_state(d) >= DICT_FILESCANNED)
luaL_error(L, "image.attr is now read-only");
@@ -377,7 +403,7 @@ static void lua_to_image(lua_State * L, image * a)
luaL_error(L, "image.bbox is now read-only");
if (!lua_istable(L, -1))
luaL_error(L, "image.bbox needs table value");
- if (lua_objlen(L, -1) != 4)
+ if (lua_rawlen(L, -1) != 4)
luaL_error(L, "image.bbox table must have exactly 4 elements");
for (i = 1; i <= 4; i++) { /* v k t ... */
lua_pushinteger(L, i); /* idx v k t ... */
@@ -445,8 +471,8 @@ static void copy_image(lua_State * L, lua_Number scale)
img_transform(b) = img_transform(a);
img_dict(b) = img_dict(a);
if (img_dictref(a) != LUA_NOREF) {
- lua_rawgeti(L, LUA_GLOBALSINDEX, img_dictref(a)); /* ad b */
- img_dictref(b) = luaL_ref(L, LUA_GLOBALSINDEX); /* b */
+ lua_rawgeti(L, LUA_REGISTRYINDEX, img_dictref(a)); /* ad b */
+ img_dictref(b) = luaL_ref(L, LUA_REGISTRYINDEX); /* b */
} else
assert(img_state(img_dict(a)) >= DICT_REFERED);
}
@@ -469,7 +495,7 @@ int l_new_image(lua_State * L)
luaL_getmetatable(L, TYPE_IMG_DICT); /* m ad i (t) */
lua_setmetatable(L, -2); /* ad i (t) */
img_dict(a) = *add = new_image_dict();
- img_dictref(a) = luaL_ref(L, LUA_GLOBALSINDEX); /* i (t) */
+ img_dictref(a) = luaL_ref(L, LUA_REGISTRYINDEX); /* i (t) */
if (lua_gettop(L) == 2) { /* i t, else just i */
lua_insert(L, -2); /* t i */
lua_pushnil(L); /* n t i (1st key for iterator) */
@@ -585,7 +611,6 @@ static void write_image_or_node(lua_State * L, wrtype_e writetype)
tail_append(n);
break; /* image */
case WR_IMMEDIATEWRITE:
- pdf_begin_dict(static_pdf, img_objnum(ad), 0);
write_img(static_pdf, ad);
break; /* image */
case WR_NODE: /* image */
@@ -665,7 +690,7 @@ static int l_image_boxes(lua_State * L)
return 1;
}
-static const struct luaL_Reg imglib[] = {
+static const struct luaL_Reg imglib_f[] = {
{"new", l_new_image},
{"copy", l_copy_image},
{"scan", l_scan_image},
@@ -685,7 +710,7 @@ void vf_out_image(PDF pdf, unsigned i)
image *a, **aa;
image_dict *ad;
lua_State *L = Luas; /* ... */
- lua_rawgeti(L, LUA_GLOBALSINDEX, (int) i); /* image ... */
+ lua_rawgeti(L, LUA_REGISTRYINDEX, (int) i); /* image ... */
aa = (image **) luaL_checkudata(L, -1, TYPE_IMG);
a = *aa;
ad = img_dict(a);
@@ -714,13 +739,12 @@ static int m_img_set(lua_State * L)
static int m_img_mul(lua_State * L)
{
- image **aa;
lua_Number scale;
if (lua_isnumber(L, 1)) { /* u? n */
- aa = (image **) luaL_checkudata(L, 2, TYPE_IMG); /* u n */
+ (void) luaL_checkudata(L, 2, TYPE_IMG); /* u n */
lua_insert(L, -2); /* n a */
} else if (lua_isnumber(L, 2)) { /* n u? */
- aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* n a */
+ (void) luaL_checkudata(L, 1, TYPE_IMG); /* n a */
} /* n a */
scale = lua_tonumber(L, 2); /* n a */
lua_pop(L, 1); /* a */
@@ -753,7 +777,7 @@ static int m_img_gc(lua_State * L)
#ifdef DEBUG
printf("\n===== IMG GC ===== a=%d ad=%d\n", a, img_dict(a));
#endif
- luaL_unref(L, LUA_GLOBALSINDEX, img_dictref(a));
+ luaL_unref(L, LUA_REGISTRYINDEX, img_dictref(a));
if (!img_is_refered(d))
xfree(a);
return 0;
@@ -793,12 +817,12 @@ static const struct luaL_Reg img_dict_m[] = {
int luaopen_img(lua_State * L)
{
- preset_environment(L, img_parms);
+ preset_environment(L, img_parms, IMG_ENV);
luaL_newmetatable(L, TYPE_IMG);
- luaL_register(L, NULL, img_m);
+ luaL_setfuncs(L, img_m, 0);
luaL_newmetatable(L, TYPE_IMG_DICT);
- luaL_register(L, NULL, img_dict_m);
- luaL_register(L, "img", imglib);
+ luaL_setfuncs(L, img_dict_m, 0);
+ luaL_newlib(L, imglib_f);
return 1;
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/liolib.c b/Build/source/texk/web2c/luatexdir/lua/liolib.c
deleted file mode 100644
index b742928c6bd..00000000000
--- a/Build/source/texk/web2c/luatexdir/lua/liolib.c
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
-** $Id: liolib.c 3794 2010-08-03 07:02:06Z taco $
-** Standard I/O (and system) library
-** See Copyright Notice in lua.h
-*/
-
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define liolib_c
-#define LUA_LIB
-
-#ifndef MINGW32
-# define LUA_USE_POSIX 1
-#endif
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-#include "ptexlib.h"
-
-#define IO_INPUT 1
-#define IO_OUTPUT 2
-
-static const char *const fnames[] = { "input", "output" };
-
-
-static int pushresult(lua_State * L, int i, const char *filename)
-{
- int en = errno; /* calls to Lua API may change this value */
- if (i) {
- lua_pushboolean(L, 1);
- return 1;
- } else {
- lua_pushnil(L);
- if (filename)
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
- else
- lua_pushfstring(L, "%s", strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
-}
-
-
-static void fileerror(lua_State * L, int arg, const char *filename)
-{
- lua_pushfstring(L, "%s: %s", filename, strerror(errno));
- luaL_argerror(L, arg, lua_tostring(L, -1));
-}
-
-
-#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
-
-
-static int io_type(lua_State * L)
-{
- void *ud;
- luaL_checkany(L, 1);
- ud = lua_touserdata(L, 1);
- lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
- if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))
- lua_pushnil(L); /* not a file */
- else if (*((FILE **) ud) == NULL)
- lua_pushliteral(L, "closed file");
- else
- lua_pushliteral(L, "file");
- return 1;
-}
-
-
-static FILE *tofile(lua_State * L)
-{
- FILE **f = topfile(L);
- if (*f == NULL)
- luaL_error(L, "attempt to use a closed file");
- return *f;
-}
-
-
-
-/*
-** When creating file handles, always creates a `closed' file handle
-** before opening the actual file; so, if there is a memory error, the
-** file is not left opened.
-*/
-static FILE **newfile(lua_State * L)
-{
- FILE **pf = (FILE **) lua_newuserdata(L, sizeof(FILE *));
- *pf = NULL; /* file handle is currently `closed' */
- luaL_getmetatable(L, LUA_FILEHANDLE);
- lua_setmetatable(L, -2);
- return pf;
-}
-
-
-/*
-** this function has a separated environment, which defines the
-** correct __close for 'popen' files
-*/
-static int io_pclose(lua_State * L)
-{
- FILE **p = topfile(L);
- int ok = lua_pclose(L, *p);
- *p = NULL;
- return pushresult(L, ok, NULL);
-}
-
-
-static int io_fclose(lua_State * L)
-{
- FILE **p = topfile(L);
- int ok = (fclose(*p) == 0);
- *p = NULL;
- return pushresult(L, ok, NULL);
-}
-
-
-static int aux_close(lua_State * L)
-{
- lua_getfenv(L, 1);
- lua_getfield(L, -1, "__close");
- return (lua_tocfunction(L, -1)) (L);
-}
-
-
-static int io_close(lua_State * L)
-{
- if (lua_isnone(L, 1))
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
- tofile(L); /* make sure argument is a file */
- return aux_close(L);
-}
-
-
-static int io_gc(lua_State * L)
-{
- FILE *f = *topfile(L);
- /* ignore closed files and standard files */
- if (f != NULL && f != stdin && f != stdout && f != stderr)
- aux_close(L);
- return 0;
-}
-
-
-static int io_tostring(lua_State * L)
-{
- FILE *f = *topfile(L);
- if (f == NULL)
- lua_pushstring(L, "file (closed)");
- else
- lua_pushfstring(L, "file (%p)", f);
- return 1;
-}
-
-
-static int io_open(lua_State * L)
-{
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "rb");
- FILE **pf = newfile(L);
- *pf = fopen(filename, mode);
- if (*pf == NULL)
- return pushresult(L, 0, filename);
- if (mode[0]=='r')
- recorder_record_input(filename);
- else
- recorder_record_output(filename);
- return 1;
-}
-
-static int io_open_ro(lua_State * L)
-{
- FILE **pf;
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "rb");
- if ((strcmp(mode, "r") != 0) && (strcmp(mode, "rb") != 0))
- return pushresult(L, 0, filename);
- pf = newfile(L);
- *pf = fopen(filename, mode);
- if (*pf == NULL)
- return pushresult(L, 0, filename);
- recorder_record_input(filename);
- return 1;
-}
-
-
-
-
-
-static int io_popen(lua_State * L)
-{
- int ret = 1;
- char *safecmd = NULL;
- char *cmdname = NULL;
- int allow = 0;
- const char *cmd = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "rb");
- FILE **pf = newfile(L);
-
- if (shellenabledp <= 0) {
- lua_pushnil(L);
- lua_pushliteral(L, "All command execution is disabled");
- return 2;
- }
- /* If restrictedshell == 0, any command is allowed. */
- if (restrictedshell == 0)
- allow = 1;
- else
- allow = shell_cmd_is_allowed(cmd, &safecmd, &cmdname);
-
- if (allow == 1) {
- *pf = lua_popen(L, cmd, mode);
- ret = (*pf == NULL) ? pushresult(L, 0, cmd) : 1;
- } else if (allow == 2) {
- *pf = lua_popen(L, safecmd, mode);
- ret = (*pf == NULL) ? pushresult(L, 0, safecmd) : 1;
- } else if (allow == 0) {
- lua_pushnil(L);
- lua_pushliteral(L, "Command execution disabled via shell_escape='p'");
- ret = 2;
- } else {
- lua_pushnil(L);
- lua_pushliteral(L, "Bad command line quoting");
- ret = 2;
- }
- return ret;
-}
-
-
-static int io_tmpfile(lua_State * L)
-{
- FILE **pf = newfile(L);
- *pf = tmpfile();
- return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
-}
-
-
-static FILE *getiofile(lua_State * L, int findex)
-{
- FILE *f;
- lua_rawgeti(L, LUA_ENVIRONINDEX, findex);
- f = *(FILE **) lua_touserdata(L, -1);
- if (f == NULL)
- luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
- return f;
-}
-
-
-static int g_iofile(lua_State * L, int f, const char *mode)
-{
- if (!lua_isnoneornil(L, 1)) {
- const char *filename = lua_tostring(L, 1);
- if (filename) {
- FILE **pf = newfile(L);
- *pf = fopen(filename, mode);
- if (*pf == NULL) {
- fileerror(L, 1, filename);
- } else {
- if (mode[0]=='r')
- recorder_record_input(filename);
- else
- recorder_record_output(filename);
- }
- } else {
- tofile(L); /* check that it's a valid file handle */
- lua_pushvalue(L, 1);
- }
- lua_rawseti(L, LUA_ENVIRONINDEX, f);
- }
- /* return current value */
- lua_rawgeti(L, LUA_ENVIRONINDEX, f);
- return 1;
-}
-
-
-static int io_input(lua_State * L)
-{
- return g_iofile(L, IO_INPUT, "rb");
-}
-
-
-static int io_output(lua_State * L)
-{
- return g_iofile(L, IO_OUTPUT, "wb");
-}
-
-
-static int io_readline(lua_State * L);
-
-
-static void aux_lines(lua_State * L, int idx, int toclose)
-{
- lua_pushvalue(L, idx);
- lua_pushboolean(L, toclose); /* close/not close file when finished */
- lua_pushcclosure(L, io_readline, 2);
-}
-
-
-static int f_lines(lua_State * L)
-{
- tofile(L); /* check that it's a valid file handle */
- aux_lines(L, 1, 0);
- return 1;
-}
-
-
-static int io_lines(lua_State * L)
-{
- if (lua_isnoneornil(L, 1)) { /* no arguments? */
- /* will iterate over default input */
- lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
- return f_lines(L);
- } else {
- const char *filename = luaL_checkstring(L, 1);
- FILE **pf = newfile(L);
- *pf = fopen(filename, "rb");
- if (*pf == NULL)
- fileerror(L, 1, filename);
- else
- recorder_record_input(filename);
- aux_lines(L, lua_gettop(L), 1);
- return 1;
- }
-}
-
-
-/*
-** {======================================================
-** READ
-** =======================================================
-*/
-
-
-static int read_number(lua_State * L, FILE * f)
-{
- lua_Number d;
- if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
- lua_pushnumber(L, d);
- return 1;
- } else
- return 0; /* read fails */
-}
-
-
-static int test_eof(lua_State * L, FILE * f)
-{
- int c = getc(f);
- ungetc(c, f);
- lua_pushlstring(L, NULL, 0);
- return (c != EOF);
-}
-
-#if 0
-static int read_line(lua_State * L, FILE * f)
-{
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- for (;;) {
- size_t l;
- char *p = luaL_prepbuffer(&b);
- if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
- luaL_pushresult(&b); /* close buffer */
- return (lua_strlen(L, -1) > 0); /* check whether read something */
- }
- l = strlen(p);
- if (l == 0 || p[l - 1] != '\n')
- luaL_addsize(&b, l);
- else {
- luaL_addsize(&b, l - 1); /* do not include `eol' */
- luaL_pushresult(&b); /* close buffer */
- return 1; /* read at least an `eol' */
- }
- }
-}
-#endif
-
-/* this new version does not care wether the file has
- line endings using an 'alien' convention */
-
-static int new_read_line(lua_State * L, FILE * f)
-{
- luaL_Buffer buf;
- int c, d;
- luaL_buffinit(L, &buf);
- while (1) {
- c = fgetc(f);
- if (c == EOF) {
- luaL_pushresult(&buf); /* close buffer */
- return (lua_strlen(L, -1) > 0); /* check whether read something */
- };
- if (c == '\n') {
- break;
- } else if (c == '\r') {
- d = fgetc(f);
- if (d != EOF && d != '\n')
- ungetc(d, f);
- break;
- } else {
- luaL_addchar(&buf, c);
- }
- }
- luaL_pushresult(&buf); /* close buffer */
- return 1;
-}
-
-
-static int read_chars(lua_State * L, FILE * f, size_t n)
-{
- size_t rlen; /* how much to read */
- size_t nr; /* number of chars actually read */
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
- do {
- char *p = luaL_prepbuffer(&b);
- if (rlen > n)
- rlen = n; /* cannot read more than asked */
- nr = fread(p, sizeof(char), rlen, f);
- luaL_addsize(&b, nr);
- n -= nr; /* still have to read `n' chars */
- } while (n > 0 && nr == rlen); /* until end of count or eof */
- luaL_pushresult(&b); /* close buffer */
- return (n == 0 || lua_strlen(L, -1) > 0);
-}
-
-static int read_all(lua_State * L, FILE * f)
-{
- /* attempt to speed up reading whole files */
- long rlen; /* how much to read */
- size_t nr; /* number of chars actually read */
- long old; /* old file location */
- char *p;
- old = ftell(f);
- if (old > 0 && (fseek(f, 0, SEEK_END) >= 0) && ((rlen = ftell(f)) > 0) && rlen < 1000 * 1000 * 100) { /* 100 MB */
- fseek(f, old, SEEK_SET);
- p = malloc((size_t) rlen);
- if (p != NULL) {
- nr = fread(p, sizeof(char), (size_t) rlen, f);
- lua_pushlstring(L, p, nr);
- free(p);
- return 1;
- }
- }
- if (old > 0)
- fseek(f, old, SEEK_SET);
- return read_chars(L, f, ~((size_t) 0));
-}
-
-
-static int g_read(lua_State * L, FILE * f, int first)
-{
- int nargs = lua_gettop(L) - 1;
- int success;
- int n;
- clearerr(f);
- if (nargs == 0) { /* no arguments? */
- success = new_read_line(L, f);
- n = first + 1; /* to return 1 result */
- } else { /* ensure stack space for all results and for auxlib's buffer */
- luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments");
- success = 1;
- for (n = first; nargs-- && success; n++) {
- if (lua_type(L, n) == LUA_TNUMBER) {
- size_t l = (size_t) lua_tointeger(L, n);
- success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
- } else {
- const char *p = lua_tostring(L, n);
- luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
- switch (p[1]) {
- case 'n': /* number */
- success = read_number(L, f);
- break;
- case 'l': /* line */
- success = new_read_line(L, f);
- break;
- case 'a': /* file */
- read_all(L, f);
- success = 1; /* always success */
- break;
- default:
- return luaL_argerror(L, n, "invalid format");
- }
- }
- }
- }
- if (ferror(f))
- return pushresult(L, 0, NULL);
- if (!success) {
- lua_pop(L, 1); /* remove last result */
- lua_pushnil(L); /* push nil instead */
- }
- return n - first;
-}
-
-static int io_read(lua_State * L)
-{
- return g_read(L, getiofile(L, IO_INPUT), 1);
-}
-
-static int f_read(lua_State * L)
-{
- return g_read(L, tofile(L), 2);
-}
-
-static int io_readline(lua_State * L)
-{
- FILE *f = *(FILE **) lua_touserdata(L, lua_upvalueindex(1));
- int sucess;
- if (f == NULL) /* file is already closed? */
- luaL_error(L, "file is already closed");
- sucess = new_read_line(L, f);
- if (ferror(f))
- return luaL_error(L, "%s", strerror(errno));
- if (sucess)
- return 1;
- else { /* EOF */
- if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */
- lua_settop(L, 0);
- lua_pushvalue(L, lua_upvalueindex(1));
- aux_close(L); /* close it */
- }
- return 0;
- }
-}
-
-/* }====================================================== */
-
-
-static int g_write(lua_State * L, FILE * f, int arg)
-{
- int nargs = lua_gettop(L) - 1;
- int status = 1;
- for (; nargs--; arg++) {
- if (lua_type(L, arg) == LUA_TNUMBER) {
- /* optimization: could be done exactly as for strings */
- status = status &&
- fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
- } else {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- status = status && (fwrite(s, sizeof(char), l, f) == l);
- }
- }
- return pushresult(L, status, NULL);
-}
-
-
-static int io_write(lua_State * L)
-{
- return g_write(L, getiofile(L, IO_OUTPUT), 1);
-}
-
-
-static int f_write(lua_State * L)
-{
- return g_write(L, tofile(L), 2);
-}
-
-
-static int f_seek(lua_State * L)
-{
- static const int mode[] = { SEEK_SET, SEEK_CUR, SEEK_END };
- static const char *const modenames[] = { "set", "cur", "end", NULL };
- FILE *f = tofile(L);
- int op = luaL_checkoption(L, 2, "cur", modenames);
- long offset = luaL_optlong(L, 3, 0);
- op = fseek(f, offset, mode[op]);
- if (op)
- return pushresult(L, 0, NULL); /* error */
- else {
- lua_pushinteger(L, ftell(f));
- return 1;
- }
-}
-
-
-static int f_setvbuf(lua_State * L)
-{
- int sz, op, res;
- static const int mode[] = { _IONBF, _IOFBF, _IOLBF };
- static const char *const modenames[] = { "no", "full", "line", NULL };
- FILE *f = tofile(L);
- op = luaL_checkoption(L, 2, NULL, modenames);
- lua_number2int(sz, luaL_optinteger(L, 3, LUAL_BUFFERSIZE));
- res = setvbuf(f, NULL, mode[op], (size_t) sz);
- return pushresult(L, res == 0, NULL);
-}
-
-
-
-static int io_flush(lua_State * L)
-{
- return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
-}
-
-
-static int f_flush(lua_State * L)
-{
- return pushresult(L, fflush(tofile(L)) == 0, NULL);
-}
-
-
-static const luaL_Reg iolib[] = {
- {"close", io_close},
- {"flush", io_flush},
- {"input", io_input},
- {"lines", io_lines},
- {"open", io_open},
- {"open_ro", io_open_ro},
- {"output", io_output},
- {"popen", io_popen},
- {"read", io_read},
- {"tmpfile", io_tmpfile},
- {"type", io_type},
- {"write", io_write},
- {NULL, NULL}
-};
-
-
-static const luaL_Reg flib[] = {
- {"close", io_close},
- {"flush", f_flush},
- {"lines", f_lines},
- {"read", f_read},
- {"seek", f_seek},
- {"setvbuf", f_setvbuf},
- {"write", f_write},
- {"__gc", io_gc},
- {"__tostring", io_tostring},
- {NULL, NULL}
-};
-
-
-static void createmeta(lua_State * L)
-{
- luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
- lua_pushvalue(L, -1); /* push metatable */
- lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
- luaL_register(L, NULL, flib); /* file methods */
-}
-
-
-static void createstdfile(lua_State * L, FILE * f, int k, const char *fname)
-{
- *newfile(L) = f;
- if (k > 0) {
- lua_pushvalue(L, -1);
- lua_rawseti(L, LUA_ENVIRONINDEX, k);
- }
- lua_setfield(L, -2, fname);
-}
-
-
-LUALIB_API int luaopen_io(lua_State * L)
-{
- createmeta(L);
- /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
- lua_createtable(L, 2, 1);
- lua_replace(L, LUA_ENVIRONINDEX);
- /* open library */
- luaL_register(L, LUA_IOLIBNAME, iolib);
- /* create (and set) default files */
- createstdfile(L, stdin, IO_INPUT, "stdin");
- createstdfile(L, stdout, IO_OUTPUT, "stdout");
- createstdfile(L, stderr, 0, "stderr");
- /* create environment for 'popen' */
- lua_getfield(L, -1, "popen");
- lua_createtable(L, 0, 1);
- lua_pushcfunction(L, io_pclose);
- lua_setfield(L, -2, "__close");
- lua_setfenv(L, -2);
- lua_pop(L, 1); /* pop 'popen' */
- /* set default close function */
- lua_pushcfunction(L, io_fclose);
- lua_setfield(L, LUA_ENVIRONINDEX, "__close");
- return 1;
-}
diff --git a/Build/source/texk/web2c/luatexdir/lua/liolibext.c b/Build/source/texk/web2c/luatexdir/lua/liolibext.c
new file mode 100644
index 00000000000..aa84bc257ca
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/lua/liolibext.c
@@ -0,0 +1,668 @@
+/* liolibext.c
+
+ Copyright 2012 Taco Hoekwater <taco@luatex.org>
+
+ This file is part of LuaTeX.
+
+ LuaTeX is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ LuaTeX is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+/* This extension only replaces one function: io.popen() and two
+ metatable entries: f:read() and f:lines() but unfortunately
+ it has to copy quite a bunch of lines from the original liolib.c
+ to do so.
+*/
+
+#include "ptexlib.h"
+#include "lua/luatex-api.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+static const char _svn_version[] =
+ "$Id: liolibext.c 4546 2013-01-02 14:52:28Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/liolibext.c $";
+
+
+/*
+** {======================================================
+** lua_popen spawns a new process connected to the current
+** one through the file streams.
+** =======================================================
+*/
+
+#if defined(_WIN32)
+
+#ifdef _MSC_VER
+#define lua_popen(L,c,m) ((void)L, win32_popen(c,m))
+#define lua_pclose(L,file) ((void)L, win32_pclose(file))
+#else
+#define lua_popen(L,c,m) ((void)L, _popen(c,m))
+#define lua_pclose(L,file) ((void)L, _pclose(file))
+#endif
+
+#else
+
+#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
+#define lua_pclose(L,file) ((void)L, pclose(file))
+
+#endif
+
+/* }====================================================== */
+
+
+#define l_fseek(f,o,w) fseek(f,o,w)
+#define l_ftell(f) ftell(f)
+#define l_seeknum long
+
+#define IO_PREFIX "_IO_"
+#define IO_INPUT (IO_PREFIX "input")
+#define IO_OUTPUT (IO_PREFIX "output")
+
+typedef luaL_Stream LStream;
+
+#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
+
+#define isclosed(p) ((p)->closef == NULL)
+
+static int io_type (lua_State *L) {
+ LStream *p;
+ luaL_checkany(L, 1);
+ p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
+ if (p == NULL)
+ lua_pushnil(L); /* not a file */
+ else if (isclosed(p))
+ lua_pushliteral(L, "closed file");
+ else
+ lua_pushliteral(L, "file");
+ return 1;
+}
+
+
+static int f_tostring (lua_State *L) {
+ LStream *p = tolstream(L);
+ if (isclosed(p))
+ lua_pushliteral(L, "file (closed)");
+ else
+ lua_pushfstring(L, "file (%p)", p->f);
+ return 1;
+}
+
+static FILE *tofile (lua_State *L) {
+ LStream *p = tolstream(L);
+ if (isclosed(p))
+ luaL_error(L, "attempt to use a closed file");
+ lua_assert(p->f);
+ return p->f;
+}
+
+
+/*
+** When creating file handles, always creates a `closed' file handle
+** before opening the actual file; so, if there is a memory error, the
+** file is not left opened.
+*/
+static LStream *newprefile (lua_State *L) {
+ LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
+ p->closef = NULL; /* mark file handle as 'closed' */
+ luaL_setmetatable(L, LUA_FILEHANDLE);
+ return p;
+}
+
+
+static int aux_close (lua_State *L) {
+ LStream *p = tolstream(L);
+ lua_CFunction cf = p->closef;
+ p->closef = NULL; /* mark stream as closed */
+ return (*cf)(L); /* close it */
+}
+
+
+static int io_close (lua_State *L) {
+ if (lua_isnone(L, 1)) /* no argument? */
+ lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
+ tofile(L); /* make sure argument is an open stream */
+ return aux_close(L);
+}
+
+static int f_gc (lua_State *L) {
+ LStream *p = tolstream(L);
+ if (!isclosed(p) && p->f != NULL)
+ aux_close(L); /* ignore closed and incompletely open files */
+ return 0;
+}
+
+
+/*
+** function to close regular files
+*/
+static int io_fclose (lua_State *L) {
+ LStream *p = tolstream(L);
+ int res = fclose(p->f);
+ return luaL_fileresult(L, (res == 0), NULL);
+}
+
+
+static LStream *newfile (lua_State *L) {
+ LStream *p = newprefile(L);
+ p->f = NULL;
+ p->closef = &io_fclose;
+ return p;
+}
+
+
+static void opencheck (lua_State *L, const char *fname, const char *mode) {
+ LStream *p = newfile(L);
+ p->f = fopen(fname, mode);
+ if (p->f == NULL)
+ luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
+}
+
+
+static int io_open (lua_State *L) {
+ const char *filename = luaL_checkstring(L, 1);
+ const char *mode = luaL_optstring(L, 2, "r");
+ LStream *p = newfile(L);
+ int i = 0;
+ /* check whether 'mode' matches '[rwa]%+?b?' */
+ if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
+ (mode[i] != '+' || ++i) && /* skip if char is '+' */
+ (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
+ (mode[i] == '\0')))
+ return luaL_error(L, "invalid mode " LUA_QS
+ " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
+ p->f = fopen(filename, mode);
+ return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
+}
+
+/*
+** function to close 'popen' files
+*/
+static int io_pclose (lua_State *L) {
+ LStream *p = tolstream(L);
+ return luaL_execresult(L, lua_pclose(L, p->f));
+}
+
+static int io_popen(lua_State * L)
+{
+ int ret = 1;
+ char *safecmd = NULL;
+ char *cmdname = NULL;
+ int allow = 0;
+ const char *filename = luaL_checkstring(L, 1);
+ const char *mode = luaL_optstring(L, 2, "rb");
+ LStream *p = newprefile(L);
+
+ if (shellenabledp <= 0) {
+ lua_pushnil(L);
+ lua_pushliteral(L, "All command execution is disabled");
+ return 2;
+ }
+ /* If restrictedshell == 0, any command is allowed. */
+ if (restrictedshell == 0)
+ allow = 1;
+ else
+ allow = shell_cmd_is_allowed(filename, &safecmd, &cmdname);
+
+ if (allow == 1) {
+ p->f = lua_popen(L, filename, mode);
+ p->closef = &io_pclose;
+ ret = (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
+ } else if (allow == 2) {
+ p->f = lua_popen(L, safecmd, mode);
+ p->closef = &io_pclose;
+ ret = (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
+ } else if (allow == 0) {
+ lua_pushnil(L);
+ lua_pushliteral(L, "Command execution disabled via shell_escape='p'");
+ ret = 2;
+ } else {
+ lua_pushnil(L);
+ lua_pushliteral(L, "Bad command line quoting");
+ ret = 2;
+ }
+ return ret;
+}
+
+
+static int io_tmpfile (lua_State *L) {
+ LStream *p = newfile(L);
+ p->f = tmpfile();
+ return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
+}
+
+
+static FILE *getiofile (lua_State *L, const char *findex) {
+ LStream *p;
+ lua_getfield(L, LUA_REGISTRYINDEX, findex);
+ p = (LStream *)lua_touserdata(L, -1);
+ if (isclosed(p))
+ luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
+ return p->f;
+}
+
+
+static int g_iofile (lua_State *L, const char *f, const char *mode) {
+ if (!lua_isnoneornil(L, 1)) {
+ const char *filename = lua_tostring(L, 1);
+ if (filename)
+ opencheck(L, filename, mode);
+ else {
+ tofile(L); /* check that it's a valid file handle */
+ lua_pushvalue(L, 1);
+ }
+ lua_setfield(L, LUA_REGISTRYINDEX, f);
+ }
+ /* return current value */
+ lua_getfield(L, LUA_REGISTRYINDEX, f);
+ return 1;
+}
+
+
+static int io_input (lua_State *L) {
+ return g_iofile(L, IO_INPUT, "r");
+}
+
+
+static int io_output (lua_State *L) {
+ return g_iofile(L, IO_OUTPUT, "w");
+}
+
+
+static int io_readline (lua_State *L);
+
+
+static void aux_lines (lua_State *L, int toclose) {
+ int i;
+ int n = lua_gettop(L) - 1; /* number of arguments to read */
+ /* ensure that arguments will fit here and into 'io_readline' stack */
+ luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
+ lua_pushvalue(L, 1); /* file handle */
+ lua_pushinteger(L, n); /* number of arguments to read */
+ lua_pushboolean(L, toclose); /* close/not close file when finished */
+ for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
+ lua_pushcclosure(L, io_readline, 3 + n);
+}
+
+
+static int f_lines (lua_State *L) {
+ tofile(L); /* check that it's a valid file handle */
+ aux_lines(L, 0);
+ return 1;
+}
+
+
+static int io_lines (lua_State *L) {
+ int toclose;
+ if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
+ if (lua_isnil(L, 1)) { /* no file name? */
+ lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
+ lua_replace(L, 1); /* put it at index 1 */
+ tofile(L); /* check that it's a valid file handle */
+ toclose = 0; /* do not close it after iteration */
+ }
+ else { /* open a new file */
+ const char *filename = luaL_checkstring(L, 1);
+ opencheck(L, filename, "r");
+ lua_replace(L, 1); /* put file at index 1 */
+ toclose = 1; /* close it after iteration */
+ }
+ aux_lines(L, toclose);
+ return 1;
+}
+
+/*
+** {======================================================
+** READ
+** =======================================================
+*/
+
+
+static int read_number (lua_State *L, FILE *f) {
+ lua_Number d;
+ if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
+ lua_pushnumber(L, d);
+ return 1;
+ }
+ else {
+ lua_pushnil(L); /* "result" to be removed */
+ return 0; /* read fails */
+ }
+}
+
+
+static int test_eof (lua_State *L, FILE *f) {
+ int c = getc(f);
+ ungetc(c, f);
+ lua_pushlstring(L, NULL, 0);
+ return (c != EOF);
+}
+
+/* this version does not care wether the file has
+ line endings using an 'alien' convention */
+
+static int read_line(lua_State * L, FILE * f, int chop)
+{
+ luaL_Buffer buf;
+ int c, d;
+ luaL_buffinit(L, &buf);
+ while (1) {
+ c = fgetc(f);
+ if (c == EOF) {
+ luaL_pushresult(&buf); /* close buffer */
+ return (lua_rawlen(L, -1) > 0); /* check whether read something */
+ };
+ if (c == '\n') {
+ if (!chop)
+ luaL_addchar(&buf, c);
+ break;
+ } else if (c == '\r') {
+ if (!chop)
+ luaL_addchar(&buf, c);
+ d = fgetc(f);
+ if (d != EOF && d != '\n') {
+ ungetc(d, f);
+ } else if (!chop) {
+ luaL_addchar(&buf, d);
+ }
+ break;
+ } else {
+ luaL_addchar(&buf, c);
+ }
+ }
+ luaL_pushresult(&buf); /* close buffer */
+ return 1;
+}
+
+#define MAX_SIZE_T (~(size_t)0)
+
+static void read_all (lua_State *L, FILE *f) {
+ size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
+ size_t old, nrlen = 0; /* for testing file size */
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ /* speed up loading of not too large files: */
+ old = ftell(f);
+ if ((fseek(f, 0, SEEK_END) >= 0) &&
+ ((nrlen = ftell(f)) > 0) && nrlen < 1000 * 1000 * 100) {
+ rlen = nrlen;
+ }
+ fseek(f, old, SEEK_SET);
+ for (;;) {
+ char *p = luaL_prepbuffsize(&b, rlen);
+ size_t nr = fread(p, sizeof(char), rlen, f);
+ luaL_addsize(&b, nr);
+ if (nr < rlen) break; /* eof? */
+ else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
+ rlen *= 2; /* double buffer size at each iteration */
+ }
+ luaL_pushresult(&b); /* close buffer */
+}
+
+
+static int read_chars (lua_State *L, FILE *f, size_t n) {
+ size_t nr; /* number of chars actually read */
+ char *p;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
+ nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
+ luaL_addsize(&b, nr);
+ luaL_pushresult(&b); /* close buffer */
+ return (nr > 0); /* true iff read something */
+}
+
+
+static int g_read (lua_State *L, FILE *f, int first) {
+ int nargs = lua_gettop(L) - 1;
+ int success;
+ int n;
+ clearerr(f);
+ if (nargs == 0) { /* no arguments? */
+ success = read_line(L, f, 1);
+ n = first+1; /* to return 1 result */
+ }
+ else { /* ensure stack space for all results and for auxlib's buffer */
+ luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
+ success = 1;
+ for (n = first; nargs-- && success; n++) {
+ if (lua_type(L, n) == LUA_TNUMBER) {
+ size_t l = (size_t)lua_tointeger(L, n);
+ success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
+ }
+ else {
+ const char *p = lua_tostring(L, n);
+ luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
+ switch (p[1]) {
+ case 'n': /* number */
+ success = read_number(L, f);
+ break;
+ case 'l': /* line */
+ success = read_line(L, f, 1);
+ break;
+ case 'L': /* line with end-of-line */
+ success = read_line(L, f, 0);
+ break;
+ case 'a': /* file */
+ read_all(L, f); /* read entire file */
+ success = 1; /* always success */
+ break;
+ default:
+ return luaL_argerror(L, n, "invalid format");
+ }
+ }
+ }
+ }
+ if (ferror(f))
+ return luaL_fileresult(L, 0, NULL);
+ if (!success) {
+ lua_pop(L, 1); /* remove last result */
+ lua_pushnil(L); /* push nil instead */
+ }
+ return n - first;
+}
+
+
+static int io_read (lua_State *L) {
+ return g_read(L, getiofile(L, IO_INPUT), 1);
+}
+
+static int f_read (lua_State *L) {
+ return g_read(L, tofile(L), 2);
+}
+
+
+static int io_readline (lua_State *L) {
+ LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
+ int i;
+ int n = (int)lua_tointeger(L, lua_upvalueindex(2));
+ if (isclosed(p)) /* file is already closed? */
+ return luaL_error(L, "file is already closed");
+ lua_settop(L , 1);
+ for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
+ lua_pushvalue(L, lua_upvalueindex(3 + i));
+ n = g_read(L, p->f, 2); /* 'n' is number of results */
+ lua_assert(n > 0); /* should return at least a nil */
+ if (!lua_isnil(L, -n)) /* read at least one value? */
+ return n; /* return them */
+ else { /* first result is nil: EOF or error */
+ if (n > 1) { /* is there error information? */
+ /* 2nd result is error message */
+ return luaL_error(L, "%s", lua_tostring(L, -n + 1));
+ }
+ if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
+ lua_settop(L, 0);
+ lua_pushvalue(L, lua_upvalueindex(1));
+ aux_close(L); /* close it */
+ }
+ return 0;
+ }
+}
+
+/* }====================================================== */
+
+
+static int g_write (lua_State *L, FILE *f, int arg) {
+ int nargs = lua_gettop(L) - arg;
+ int status = 1;
+ for (; nargs--; arg++) {
+ if (lua_type(L, arg) == LUA_TNUMBER) {
+ /* optimization: could be done exactly as for strings */
+ status = status &&
+ fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
+ }
+ else {
+ size_t l;
+ const char *s = luaL_checklstring(L, arg, &l);
+ status = status && (fwrite(s, sizeof(char), l, f) == l);
+ }
+ }
+ if (status) return 1; /* file handle already on stack top */
+ else return luaL_fileresult(L, status, NULL);
+}
+
+
+static int io_write (lua_State *L) {
+ return g_write(L, getiofile(L, IO_OUTPUT), 1);
+}
+
+
+static int f_write (lua_State *L) {
+ FILE *f = tofile(L);
+ lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
+ return g_write(L, f, 2);
+}
+
+
+static int f_seek (lua_State *L) {
+ static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
+ static const char *const modenames[] = {"set", "cur", "end", NULL};
+ FILE *f = tofile(L);
+ int op = luaL_checkoption(L, 2, "cur", modenames);
+ lua_Number p3 = luaL_optnumber(L, 3, 0);
+ l_seeknum offset = (l_seeknum)p3;
+ luaL_argcheck(L, (lua_Number)offset == p3, 3,
+ "not an integer in proper range");
+ op = l_fseek(f, offset, mode[op]);
+ if (op)
+ return luaL_fileresult(L, 0, NULL); /* error */
+ else {
+ lua_pushnumber(L, (lua_Number)l_ftell(f));
+ return 1;
+ }
+}
+
+
+static int f_setvbuf (lua_State *L) {
+ int res;
+ static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
+ static const char *const modenames[] = {"no", "full", "line", NULL};
+ FILE *f = tofile(L);
+ int op = luaL_checkoption(L, 2, NULL, modenames);
+ lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
+ if(sz == 0)
+ res = setvbuf(f, NULL, _IONBF, sz);
+ else
+ res = setvbuf(f, NULL, mode[op], sz);
+ return luaL_fileresult(L, res == 0, NULL);
+}
+
+
+
+static int io_flush (lua_State *L) {
+ return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
+}
+
+
+static int f_flush (lua_State *L) {
+ return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
+}
+
+
+/*
+** functions for 'io' library
+*/
+static const luaL_Reg iolib[] = {
+ {"close", io_close},
+ {"flush", io_flush},
+ {"input", io_input},
+ {"lines", io_lines},
+ {"open", io_open},
+ {"output", io_output},
+ {"popen", io_popen},
+ {"read", io_read},
+ {"tmpfile", io_tmpfile},
+ {"type", io_type},
+ {"write", io_write},
+ {NULL, NULL}
+};
+
+
+/*
+** methods for file handles
+*/
+static const luaL_Reg flib[] = {
+ {"close", io_close},
+ {"flush", f_flush},
+ {"lines", f_lines},
+ {"read", f_read},
+ {"seek", f_seek},
+ {"setvbuf", f_setvbuf},
+ {"write", f_write},
+ {"__gc", f_gc},
+ {"__tostring", f_tostring},
+ {NULL, NULL}
+};
+
+
+static void createmeta (lua_State *L) {
+ luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
+ lua_pushvalue(L, -1); /* push metatable */
+ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
+ luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
+ lua_pop(L, 1); /* pop new metatable */
+}
+
+
+/*
+** function to (not) close the standard files stdin, stdout, and stderr
+*/
+static int io_noclose (lua_State *L) {
+ LStream *p = tolstream(L);
+ p->closef = &io_noclose; /* keep file opened */
+ lua_pushnil(L);
+ lua_pushliteral(L, "cannot close standard file");
+ return 2;
+}
+
+
+static void createstdfile (lua_State *L, FILE *f, const char *k,
+ const char *fname) {
+ LStream *p = newprefile(L);
+ p->f = f;
+ p->closef = &io_noclose;
+ if (k != NULL) {
+ lua_pushvalue(L, -1);
+ lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
+ }
+ lua_setfield(L, -2, fname); /* add file to module */
+}
+
+int open_iolibext (lua_State *L) {
+ luaL_newlib(L, iolib); /* new module */
+ createmeta(L);
+ /* create (and set) default files */
+ createstdfile(L, stdin, IO_INPUT, "stdin");
+ createstdfile(L, stdout, IO_OUTPUT, "stdout");
+ createstdfile(L, stderr, NULL, "stderr");
+ return 1;
+}
diff --git a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c
index 6a64799771a..aa314105e7a 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c
@@ -29,7 +29,7 @@
#include <kpathsea/paths.h>
static const char _svn_version[] =
- "$Id: lkpselib.c 4020 2010-11-30 13:43:25Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lkpselib.c $";
+ "$Id: lkpselib.c 4595 2013-03-19 14:52:12Z taco $ $URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lkpselib.c $";
static const unsigned filetypes[] = {
kpse_gf_format,
@@ -181,7 +181,7 @@ static int find_file(lua_State * L)
if (lua_isboolean(L, i)) {
mexist = lua_toboolean(L, i);
} else if (lua_isnumber(L, i)) {
- lua_number2int(mexist, lua_tonumber(L, i));
+ mexist=(int)lua_tonumber(L, i);
} else if (lua_isstring(L, i)) {
int op = luaL_checkoption(L, i, NULL, filetypenames);
ftype = filetypes[op];
@@ -216,7 +216,7 @@ static int lua_kpathsea_find_file(lua_State * L)
if (lua_isboolean(L, i)) {
mexist = (boolean) lua_toboolean(L, i);
} else if (lua_isnumber(L, i)) {
- lua_number2int(mexist, lua_tonumber(L, i));
+ mexist=(int)lua_tonumber(L, i);
} else if (lua_isstring(L, i)) {
int op = luaL_checkoption(L, i, NULL, filetypenames);
ftype = filetypes[op];
@@ -518,14 +518,14 @@ static int do_lua_kpathsea_lookup(lua_State * L, kpathsea kpse, int idx)
lua_pushstring(L, "dpi");
lua_gettable(L, idx + 1);
if (lua_type(L, -1) == LUA_TNUMBER) {
- lua_number2int(dpi, lua_tonumber(L, -1));
+ dpi=(int)lua_tonumber(L, -1);
}
lua_pop(L, 1);
lua_pushstring(L, "debug");
lua_gettable(L, idx + 1);
if (lua_type(L, -1) == LUA_TNUMBER) {
int d = 0;
- lua_number2int(d, lua_tonumber(L, -1));
+ d=(int)lua_tonumber(L, -1);
kpse->debug |= d;
}
lua_pop(L, 1);
@@ -792,10 +792,10 @@ static int lua_kpathsea_new(lua_State * L)
{
kpathsea kpse = NULL;
kpathsea *kp = NULL;
- const char *argv = luaL_checkstring(L, 1);
- const char *liar = luaL_optstring(L, 2, argv);
+ const char *av = luaL_checkstring(L, 1);
+ const char *liar = luaL_optstring(L, 2, av);
kpse = kpathsea_new();
- kpathsea_set_program_name(kpse, argv, liar);
+ kpathsea_set_program_name(kpse, av, liar);
kp = (kpathsea *) lua_newuserdata(L, sizeof(kpathsea *));
*kp = kpse;
luaL_getmetatable(L, KPATHSEA_METATABLE);
@@ -803,7 +803,7 @@ static int lua_kpathsea_new(lua_State * L)
return 1;
}
-static const struct luaL_reg kpselib_m[] = {
+static const struct luaL_Reg kpselib_m[] = {
{"__gc", lua_kpathsea_finish},
{"init_prog", lua_kpathsea_init_prog},
{"readable_file", lua_kpathsea_readable_file},
@@ -819,7 +819,7 @@ static const struct luaL_reg kpselib_m[] = {
{NULL, NULL} /* sentinel */
};
-static const struct luaL_reg kpselib_l[] = {
+static const struct luaL_Reg kpselib_l[] = {
{"new", lua_kpathsea_new},
{"set_program_name", set_program_name},
{"init_prog", init_prog},
diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c
index 8a3a02cd766..742b5d85400 100644
--- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c
@@ -23,7 +23,7 @@
static const char _svn_version[] =
- "$Id: llanglib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/llanglib.c $";
+ "$Id: llanglib.c 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/llanglib.c $";
#define LANG_METATABLE "luatex.lang"
@@ -41,7 +41,7 @@ static int lang_new(lua_State * L)
} else {
int lualang;
lang = lua_newuserdata(L, sizeof(struct tex_language *));
- lua_number2int(lualang, lua_tonumber(L, 1));
+ lualang=(int)lua_tonumber(L, 1);
*lang = get_language(lualang);
if (!*lang) {
return luaL_error(L, "lang.new(%d): undefined language",
@@ -120,7 +120,7 @@ static int lang_pre_hyphen_char(lua_State * L)
return luaL_error(L,
"lang.prehyphenchar(): argument should be a character number");
}
- lua_number2int((*lang_ptr)->pre_hyphen_char, lua_tonumber(L, 2));
+ (*lang_ptr)->pre_hyphen_char=(int)lua_tonumber(L, 2);
return 0;
} else {
lua_pushnumber(L, (*lang_ptr)->pre_hyphen_char);
@@ -137,7 +137,7 @@ static int lang_post_hyphen_char(lua_State * L)
return luaL_error(L,
"lang.posthyphenchar(): argument should be a character number");
}
- lua_number2int((*lang_ptr)->post_hyphen_char, lua_tonumber(L, 2));
+ (*lang_ptr)->post_hyphen_char=(int)lua_tonumber(L, 2);
return 0;
} else {
lua_pushnumber(L, (*lang_ptr)->post_hyphen_char);
@@ -155,7 +155,7 @@ static int lang_pre_exhyphen_char(lua_State * L)
return luaL_error(L,
"lang.preexhyphenchar(): argument should be a character number");
}
- lua_number2int((*lang_ptr)->pre_exhyphen_char, lua_tonumber(L, 2));
+ (*lang_ptr)->pre_exhyphen_char=(int)lua_tonumber(L, 2);
return 0;
} else {
lua_pushnumber(L, (*lang_ptr)->pre_exhyphen_char);
@@ -172,7 +172,7 @@ static int lang_post_exhyphen_char(lua_State * L)
return luaL_error(L,
"lang.postexhyphenchar(): argument should be a character number");
}
- lua_number2int((*lang_ptr)->post_exhyphen_char, lua_tonumber(L, 2));
+ (*lang_ptr)->post_exhyphen_char=(int)lua_tonumber(L, 2);
return 0;
} else {
lua_pushnumber(L, (*lang_ptr)->post_exhyphen_char);
@@ -220,7 +220,7 @@ static int do_lang_hyphenate(lua_State * L)
}
-static const struct luaL_reg langlib_d[] = {
+static const struct luaL_Reg langlib_d[] = {
/* *INDENT-OFF* */
{"clear_patterns", lang_clear_patterns},
{"clear_hyphenation", lang_clear_hyphenation},
@@ -236,7 +236,7 @@ static const struct luaL_reg langlib_d[] = {
};
-static const struct luaL_reg langlib[] = {
+static const struct luaL_Reg langlib[] = {
/* *INDENT-OFF* */
{"clear_patterns", lang_clear_patterns},
{"clear_hyphenation", lang_clear_hyphenation},
diff --git a/Build/source/texk/web2c/luatexdir/lua/llfslibext.c b/Build/source/texk/web2c/luatexdir/lua/llfslibext.c
index f783967aa8f..642893458a3 100644
--- a/Build/source/texk/web2c/luatexdir/lua/llfslibext.c
+++ b/Build/source/texk/web2c/luatexdir/lua/llfslibext.c
@@ -25,7 +25,7 @@
#include <time.h>
static const char _svn_version[] =
- "$Id: llfslibext.c 4164 2011-04-16 09:00:09Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.70.x/source/texk/web2c/luatexdir/lua/llfslibext.c $";
+ "$Id: llfslibext.c 4421 2012-05-21 15:20:49Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/llfslibext.c $";
#ifdef _WIN32
# include <windows.h>
diff --git a/Build/source/texk/web2c/luatexdir/lua/llualib.c b/Build/source/texk/web2c/luatexdir/lua/llualib.c
index f99b85f2083..0b23b7e0a9e 100644
--- a/Build/source/texk/web2c/luatexdir/lua/llualib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/llualib.c
@@ -21,7 +21,7 @@
#include "lua/luatex-api.h"
static const char _svn_version[] =
- "$Id: llualib.c 3615 2010-04-13 21:59:59Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/llualib.c $";
+ "$Id: llualib.c 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/llualib.c $";
#define LOAD_BUF_SIZE 256
#define UINT_MAX32 0xFFFFFFFF
@@ -197,7 +197,7 @@ static int get_bytecode(lua_State * L)
if (k <= luabytecode_max && lua_bytecode_registers[k].buf != NULL) {
if (lua_load
(L, reader, (void *) (lua_bytecode_registers + k),
- "bytecode")) {
+ "bytecode", NULL)) {
return luaL_error(L, "bad bytecode register");
} else {
lua_pushvalue(L, -1);
@@ -304,7 +304,7 @@ static int get_luaname(lua_State * L)
-static const struct luaL_reg lualib[] = {
+static const struct luaL_Reg lualib[] = {
/* *INDENT-OFF* */
{"getluaname", get_luaname},
{"setluaname", set_luaname},
diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c
index c4c3a1dcd49..c61ddc55ab4 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c
@@ -1,6 +1,6 @@
/* lnodelib.c
-
- Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 2006-2013 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -17,9 +17,19 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+/*
+
+ The node getter and setter are adapted a bit by Hans and Luigi so blame
+ them! On the agenda: check all keys, maybe hide some fields that are not
+ supposed to be seen and set (scratch fields for the backend and par
+ builder).
+
+*/
+
+
static const char _svn_version[] =
- "$Id: lnodelib.c 4166 2011-04-16 09:12:20Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.70.x/source/texk/web2c/luatexdir/lua/lnodelib.c $";
+ "$Id: lnodelib.c 4594 2013-03-19 14:49:13Z taco $ "
+ "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lnodelib.c $";
#include "ptexlib.h"
#include "lua/luatex-api.h"
@@ -30,6 +40,12 @@ static const char _svn_version[] =
luaS_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \
} while (0)
+#define init_luaS_index_s(a,b) do { \
+ lua_pushliteral(L,b); \
+ luaS_##a##_ptr = lua_tostring(L,-1); \
+ luaS_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \
+ } while (0)
+
#define make_luaS_index(a) \
static int luaS_##a##_index = 0; \
static const char * luaS_##a##_ptr = NULL
@@ -39,12 +55,268 @@ static const char _svn_version[] =
#define luaS_ptr_eq(a,b) (a==luaS_##b##_ptr)
#define NODE_METATABLE "luatex_node"
-
+
#define DEBUG 0
#define DEBUG_OUT stdout
make_luaS_index(luatex_node);
+make_luaS_index(accent);
+make_luaS_index(action);
+make_luaS_index(action_id);
+make_luaS_index(action_type);
+make_luaS_index(area);
+make_luaS_index(attr);
+make_luaS_index(best_ins_ptr);
+make_luaS_index(bot_accent);
+make_luaS_index(box_left);
+make_luaS_index(box_left_width);
+make_luaS_index(box_right);
+make_luaS_index(box_right_width);
+make_luaS_index(broken_ins);
+make_luaS_index(broken_ptr);
+make_luaS_index(char);
+make_luaS_index(class);
+make_luaS_index(command);
+make_luaS_index(components);
+make_luaS_index(cost);
+make_luaS_index(count);
+make_luaS_index(data);
+make_luaS_index(degree);
+make_luaS_index(delim);
+make_luaS_index(denom);
+make_luaS_index(depth);
+make_luaS_index(dest_id);
+make_luaS_index(dest_type);
+make_luaS_index(dir);
+make_luaS_index(dir_h);
+make_luaS_index(display);
+make_luaS_index(dvi_ptr);
+make_luaS_index(expansion_factor);
+make_luaS_index(ext);
+make_luaS_index(fam);
+make_luaS_index(file);
+make_luaS_index(font);
+make_luaS_index(glue_order);
+make_luaS_index(glue_set);
+make_luaS_index(glue_sign);
+make_luaS_index(glyph);
+make_luaS_index(head);
+make_luaS_index(height);
+make_luaS_index(id);
+make_luaS_index(index);
+make_luaS_index(kern);
+make_luaS_index(lang);
+make_luaS_index(large_char);
+make_luaS_index(large_fam);
+make_luaS_index(last_ins_ptr);
+make_luaS_index(leader);
+make_luaS_index(left);
+make_luaS_index(level);
+make_luaS_index(link_attr);
+make_luaS_index(list);
+make_luaS_index(mark);
+make_luaS_index(mode);
+make_luaS_index(name);
+make_luaS_index(named_id);
+make_luaS_index(new_window);
+make_luaS_index(next);
+make_luaS_index(nucleus);
+make_luaS_index(num);
+make_luaS_index(number);
+make_luaS_index(objnum);
+make_luaS_index(pen_broken);
+make_luaS_index(pen_inter);
+make_luaS_index(penalty);
+make_luaS_index(post);
+make_luaS_index(pre);
+make_luaS_index(prev);
+make_luaS_index(ref_count);
+make_luaS_index(reg);
+make_luaS_index(replace);
+make_luaS_index(right);
+make_luaS_index(script);
+make_luaS_index(scriptscript);
+make_luaS_index(shift);
+make_luaS_index(shrink);
+make_luaS_index(shrink_order);
+make_luaS_index(small_char);
+make_luaS_index(small_fam);
+make_luaS_index(spec);
+make_luaS_index(stack);
+make_luaS_index(stream);
+make_luaS_index(stretch);
+make_luaS_index(stretch_order);
+make_luaS_index(string);
+make_luaS_index(style);
+make_luaS_index(sub);
+make_luaS_index(subtype);
+make_luaS_index(sup);
+make_luaS_index(surround);
+make_luaS_index(text);
+make_luaS_index(thread_attr);
+make_luaS_index(thread_id);
+make_luaS_index(transform);
+make_luaS_index(type);
+make_luaS_index(uchyph);
+make_luaS_index(user_id);
+make_luaS_index(value);
+make_luaS_index(width);
+make_luaS_index(writable);
+make_luaS_index(xoffset);
+make_luaS_index(xyz_zoom);
+make_luaS_index(yoffset);
+
+make_luaS_index(additional);
+make_luaS_index(cal_expand_ratio);
+make_luaS_index(exactly);
+make_luaS_index(subst_ex_font);
+
+make_luaS_index(TLT);
+make_luaS_index(TRT);
+make_luaS_index(LTL);
+make_luaS_index(RTT);
+
+make_luaS_index(pTLT);
+make_luaS_index(pTRT);
+make_luaS_index(pLTL);
+make_luaS_index(pRTT);
+
+make_luaS_index(mTLT);
+make_luaS_index(mTRT);
+make_luaS_index(mLTL);
+make_luaS_index(mRTT);
+
+static void initialize_luaS_indexes(lua_State * L)
+{
+ init_luaS_index(luatex_node);
+
+ init_luaS_index(accent);
+ init_luaS_index(action_id);
+ init_luaS_index(action);
+ init_luaS_index(action_type);
+ init_luaS_index(area);
+ init_luaS_index(attr);
+ init_luaS_index(best_ins_ptr);
+ init_luaS_index(bot_accent);
+ init_luaS_index(box_left);
+ init_luaS_index(box_left_width);
+ init_luaS_index(box_right);
+ init_luaS_index(box_right_width);
+ init_luaS_index(broken_ins);
+ init_luaS_index(broken_ptr);
+ init_luaS_index(char);
+ init_luaS_index(class);
+ init_luaS_index(command);
+ init_luaS_index(components);
+ init_luaS_index(cost);
+ init_luaS_index(count);
+ init_luaS_index(data);
+ init_luaS_index(degree);
+ init_luaS_index(delim);
+ init_luaS_index(denom);
+ init_luaS_index(depth);
+ init_luaS_index(dest_id);
+ init_luaS_index(dest_type);
+ init_luaS_index(dir);
+ init_luaS_index(dir_h);
+ init_luaS_index(display);
+ init_luaS_index(dvi_ptr);
+ init_luaS_index(expansion_factor);
+ init_luaS_index(ext);
+ init_luaS_index(fam);
+ init_luaS_index(file);
+ init_luaS_index(font);
+ init_luaS_index(glue_order);
+ init_luaS_index(glue_set);
+ init_luaS_index(glue_sign);
+ init_luaS_index(glyph);
+ init_luaS_index(head);
+ init_luaS_index(height);
+ init_luaS_index(id);
+ init_luaS_index(index);
+ init_luaS_index(kern);
+ init_luaS_index(lang);
+ init_luaS_index(large_char);
+ init_luaS_index(large_fam);
+ init_luaS_index(last_ins_ptr);
+ init_luaS_index(leader);
+ init_luaS_index(left);
+ init_luaS_index(level);
+ init_luaS_index(link_attr);
+ init_luaS_index(list);
+ init_luaS_index(mark);
+ init_luaS_index(mode);
+ init_luaS_index(name);
+ init_luaS_index(named_id);
+ init_luaS_index(new_window);
+ init_luaS_index(next);
+ init_luaS_index(nucleus);
+ init_luaS_index(num);
+ init_luaS_index(number);
+ init_luaS_index(objnum);
+ init_luaS_index(pen_broken);
+ init_luaS_index(pen_inter);
+ init_luaS_index(penalty);
+ init_luaS_index(post);
+ init_luaS_index(pre);
+ init_luaS_index(prev);
+ init_luaS_index(ref_count);
+ init_luaS_index(reg);
+ init_luaS_index(replace);
+ init_luaS_index(right);
+ init_luaS_index(script);
+ init_luaS_index(scriptscript);
+ init_luaS_index(shift);
+ init_luaS_index(shrink);
+ init_luaS_index(shrink_order);
+ init_luaS_index(small_char);
+ init_luaS_index(small_fam);
+ init_luaS_index(spec);
+ init_luaS_index(stack);
+ init_luaS_index(stream);
+ init_luaS_index(stretch);
+ init_luaS_index(stretch_order);
+ init_luaS_index(string);
+ init_luaS_index(style);
+ init_luaS_index(sub);
+ init_luaS_index(subtype);
+ init_luaS_index(sup);
+ init_luaS_index(surround);
+ init_luaS_index(text);
+ init_luaS_index(thread_attr);
+ init_luaS_index(thread_id);
+ init_luaS_index(transform);
+ init_luaS_index(type);
+ init_luaS_index(uchyph);
+ init_luaS_index(user_id);
+ init_luaS_index(value);
+ init_luaS_index(width);
+ init_luaS_index(writable);
+ init_luaS_index(xoffset);
+ init_luaS_index(xyz_zoom);
+ init_luaS_index(yoffset);
+
+ init_luaS_index(additional);
+ init_luaS_index(cal_expand_ratio);
+ init_luaS_index(exactly);
+ init_luaS_index(subst_ex_font);
+
+ init_luaS_index(TLT);
+ init_luaS_index(TRT);
+ init_luaS_index(LTL);
+ init_luaS_index(RTT);
+ init_luaS_index_s(pTLT,"+TLT");
+ init_luaS_index_s(pTRT,"+TRT");
+ init_luaS_index_s(pLTL,"+LTL");
+ init_luaS_index_s(pRTT,"+RTT");
+ init_luaS_index_s(mTLT,"-TLT");
+ init_luaS_index_s(mTRT,"-TRT");
+ init_luaS_index_s(mLTL,"-LTL");
+ init_luaS_index_s(mRTT,"-RTT");
+
+}
+
static halfword *maybe_isnode(lua_State * L, int ud)
{
halfword *p = lua_touserdata(L, ud);
@@ -65,7 +337,7 @@ halfword *check_isnode(lua_State * L, int ud)
{
halfword *p = maybe_isnode(L, ud);
if (p != NULL) {
- return p;
+ return p;
}
pdftex_fail("There should have been a lua <node> here, not an object with type %s!", luaL_typename(L, ud));
return NULL;
@@ -97,8 +369,7 @@ int do_get_node_type_id(lua_State * L, int n, node_info * data)
#define get_node_type_id(L,n) do_get_node_type_id(L,n,node_data)
#define get_node_subtype_id(L,n) do_get_node_type_id(L,n,whatsit_node_data)
-static
-int get_valid_node_type_id(lua_State * L, int n)
+static int get_valid_node_type_id(lua_State * L, int n)
{
int i = get_node_type_id(L, n);
if (i == -1) {
@@ -111,17 +382,14 @@ int get_valid_node_type_id(lua_State * L, int n)
return i;
}
-static
-int get_valid_node_subtype_id(lua_State * L, int n)
+static int get_valid_node_subtype_id(lua_State * L, int n)
{
int i = get_node_subtype_id(L, n);
if (i == -1) {
if (lua_type(L, n) == LUA_TSTRING) {
- luaL_error(L, "Invalid whatsit node id: %s",
- lua_tostring(L, n));
+ luaL_error(L, "Invalid whatsit node id: %s", lua_tostring(L, n));
} else {
- luaL_error(L, "Invalid whatsit node id: %d",
- lua_tonumber(L, n));
+ luaL_error(L, "Invalid whatsit node id: %d", lua_tonumber(L, n));
}
}
return i;
@@ -132,9 +400,9 @@ int get_valid_node_subtype_id(lua_State * L, int n)
static int lua_nodelib_isnode(lua_State * L)
{
if (maybe_isnode(L,1) != NULL)
- lua_pushboolean(L,1);
+ lua_pushboolean(L,1);
else
- lua_pushboolean(L,0);
+ lua_pushboolean(L,0);
return 1;
}
@@ -144,9 +412,9 @@ static int lua_nodelib_next(lua_State * L)
{
halfword *p = maybe_isnode(L,1);
if (p != NULL && *p && vlink(*p)) {
- lua_nodelib_push_fast(L,vlink(*p));
+ lua_nodelib_push_fast(L,vlink(*p));
} else {
- lua_pushnil(L);
+ lua_pushnil(L);
}
return 1;
}
@@ -155,16 +423,16 @@ static int lua_nodelib_prev(lua_State * L)
{
halfword *p = maybe_isnode(L,1);
if (p != NULL && *p && alink(*p)) {
- lua_nodelib_push_fast(L,alink(*p));
+ lua_nodelib_push_fast(L,alink(*p));
} else {
- lua_pushnil(L);
+ lua_pushnil(L);
}
return 1;
}
-/* Creates a userdata object for a number found at the stack top,
- if it is representing a node (i.e. an pointer into |varmem|).
+/* Creates a userdata object for a number found at the stack top,
+ if it is representing a node (i.e. an pointer into |varmem|).
It replaces the stack entry with the new userdata, or pushes
|nil| if the number is |null|, or if the index is definately out of
range. This test could be improved.
@@ -225,7 +493,6 @@ void lua_nodelib_push_fast(lua_State * L, halfword n)
return;
}
-
/* converts type strings to type ids */
static int lua_nodelib_id(lua_State * L)
@@ -256,20 +523,19 @@ static int lua_nodelib_subtype(lua_State * L)
static int lua_nodelib_type(lua_State * L)
{
if (lua_type(L,1) == LUA_TNUMBER) {
- int i = get_node_type_id(L, 1);
- if (i >= 0) {
- lua_pushstring(L, node_data[i].name);
- return 1;
- }
+ int i = get_node_type_id(L, 1);
+ if (i >= 0) {
+ lua_pushstring(L, node_data[i].name);
+ return 1;
+ }
} else if (maybe_isnode(L, 1) != NULL) {
- lua_pushstring(L,"node");
- return 1;
+ lua_pushstring(L,"node");
+ return 1;
}
lua_pushnil(L);
return 1;
}
-
/* allocate a new node */
static int lua_nodelib_new(lua_State * L)
@@ -284,8 +550,7 @@ static int lua_nodelib_new(lua_State * L)
j = get_valid_node_subtype_id(L, 2);
}
if (j < 0) {
- luaL_error(L,
- "Creating a whatsit requires the subtype number as a second argument");
+ luaL_error(L, "Creating a whatsit requires the subtype number as a second argument");
}
} else {
j = 0;
@@ -345,16 +610,16 @@ static int lua_nodelib_flush_list(lua_State * L)
/* remove a node from a list */
#if DEBUG
-static void show_node_links (halfword l, const char * p)
+static void show_node_links (halfword l, const char * p)
{
halfword t = l;
while (t) {
fprintf(DEBUG_OUT, "%s t = %d, prev = %d, next = %d\n", p, (int)t, (int)alink(t), (int)vlink(t));
t = vlink(t);
- }
+ }
}
#endif
-
+
static int lua_nodelib_remove(lua_State * L)
{
halfword head, current, t;
@@ -435,8 +700,7 @@ static int lua_nodelib_insert_before(lua_State * L)
if (t == null || vlink(t) != current) {
set_t_to_prev(head, current);
if (t == null) { /* error! */
- luaL_error(L,
- "Attempt to node.insert_before() a non-existing node");
+ luaL_error(L, "Attempt to node.insert_before() a non-existing node");
}
}
couple_nodes(t, n);
@@ -451,7 +715,6 @@ static int lua_nodelib_insert_before(lua_State * L)
return 2;
}
-
static int lua_nodelib_insert_after(lua_State * L)
{
halfword head, current, n;
@@ -550,8 +813,6 @@ static int lua_nodelib_last_node(lua_State * L)
return 1;
}
-
-
/* build a hbox */
static int lua_nodelib_hpack(lua_State * L)
@@ -567,26 +828,25 @@ static int lua_nodelib_hpack(lua_State * L)
if (lua_gettop(L) > 2) {
if (lua_type(L, 3) == LUA_TSTRING) {
s = lua_tostring(L, 3);
- if (strcmp(s, "additional") == 0)
+ if (luaS_ptr_eq(s, additional)) {
m = 1;
- else if (strcmp(s, "exactly") == 0)
+ } else if (luaS_ptr_eq(s, exactly)) {
m = 0;
- else if (strcmp(s, "cal_expand_ratio") == 0)
+ } else if (luaS_ptr_eq(s, cal_expand_ratio)) {
m = 2;
- else if (strcmp(s, "subst_ex_font") == 0)
+ } else if (luaS_ptr_eq(s, subst_ex_font)) {
m = 3;
- else {
- luaL_error(L,
- "3rd argument should be either additional or exactly");
+ } else {
+ luaL_error(L, "3rd argument should be either additional or exactly");
}
} else if (lua_type(L, 3) == LUA_TNUMBER) {
- lua_number2int(m, lua_tonumber(L, 3));
+ m=(int)lua_tonumber(L, 3);
} else {
lua_pushstring(L, "incorrect 3rd argument");
}
if (lua_gettop(L) > 3) {
if (lua_type(L, 4) == LUA_TSTRING) {
- d = nodelib_getdir(L, 4);
+ d = nodelib_getdir(L, 4, 1);
} else {
lua_pushstring(L, "incorrect 4th argument");
}
@@ -599,7 +859,6 @@ static int lua_nodelib_hpack(lua_State * L)
return 2;
}
-
static int lua_nodelib_dimensions(lua_State * L)
{
int top;
@@ -612,6 +871,7 @@ static int lua_nodelib_dimensions(lua_State * L)
int i = 1;
int d = -1;
halfword n = null, p = null;
+ /* maybe be more restrictive: LUA_TNUMBER i.e. it's not good to mix numbers and strings with digits */
if (lua_isnumber(L, 1)) {
if (top < 4) {
lua_pushnil(L);
@@ -619,19 +879,19 @@ static int lua_nodelib_dimensions(lua_State * L)
}
i += 3;
g_mult = (glue_ratio) lua_tonumber(L, 1);
- lua_number2int(g_sign, lua_tonumber(L, 2));
- lua_number2int(g_order, lua_tonumber(L, 3));
+ g_sign=(int)lua_tonumber(L, 2);
+ g_order=(int)lua_tonumber(L, 3);
}
n = *(check_isnode(L, i));
if (lua_gettop(L) > i && !lua_isnil(L, (i + 1))) {
if (lua_type(L, (i + 1)) == LUA_TSTRING) {
- d = nodelib_getdir(L, (i + 1));
+ d = nodelib_getdir(L, (i + 1), 1);
} else {
p = *(check_isnode(L, (i + 1)));
}
}
if (lua_gettop(L) > (i + 1) && lua_type(L, (i + 2)) == LUA_TSTRING) {
- d = nodelib_getdir(L, (i + 2));
+ d = nodelib_getdir(L, (i + 2), 1);
}
siz = natural_sizes(n, p, g_mult, g_sign, g_order, d);
lua_pushnumber(L, siz.wd);
@@ -639,14 +899,13 @@ static int lua_nodelib_dimensions(lua_State * L)
lua_pushnumber(L, siz.dp);
return 3;
} else {
- luaL_error(L,
- "missing argument to 'dimensions' (node expected)");
+ luaL_error(L, "missing argument to 'dimensions' (node expected)");
}
return 0; /* not reached */
}
-
/* build a vbox */
+
static int lua_nodelib_vpack(lua_State * L)
{
halfword n, p;
@@ -660,17 +919,17 @@ static int lua_nodelib_vpack(lua_State * L)
if (lua_gettop(L) > 2) {
if (lua_type(L, 3) == LUA_TSTRING) {
s = lua_tostring(L, 3);
- if (strcmp(s, "additional") == 0)
+ if (luaS_ptr_eq(s, additional)) {
m = 1;
- else if (strcmp(s, "exactly") == 0)
+ } else if (luaS_ptr_eq(s, exactly)) {
m = 0;
- else {
- luaL_error(L,
- "3rd argument should be either additional or exactly");
+ } else {
+ luaL_error(L, "3rd argument should be either additional or exactly");
}
+
if (lua_gettop(L) > 3) {
if (lua_type(L, 4) == LUA_TSTRING) {
- d = nodelib_getdir(L, 4);
+ d = nodelib_getdir(L, 4, 1);
} else {
lua_pushstring(L, "incorrect 4th argument");
}
@@ -678,7 +937,7 @@ static int lua_nodelib_vpack(lua_State * L)
}
else if (lua_type(L, 3) == LUA_TNUMBER) {
- lua_number2int(m, lua_tonumber(L, 3));
+ m=(int)lua_tonumber(L, 3);
} else {
lua_pushstring(L, "incorrect 3rd argument");
}
@@ -690,7 +949,6 @@ static int lua_nodelib_vpack(lua_State * L)
return 2;
}
-
/* create a hlist from a formula */
static int lua_nodelib_mlist_to_hlist(lua_State * L)
@@ -719,144 +977,61 @@ static int lua_nodelib_mfont(lua_State * L)
return 1;
}
+/*
+ This function is similar to |get_node_type_id|, for field
+ identifiers. It has to do some more work, because not all
+ identifiers are valid for all types of nodes.
+ If really needed we can optimize this one using a big if ..
+ .. else like with the getter and setter.
-/* This function is similar to |get_node_type_id|, for field
- identifiers. It has to do some more work, because not all
- identifiers are valid for all types of nodes.
-*/
-
-/* this inlining is an optimisation trick. it would be even faster to
- compare string pointers on the lua stack, but that would require a
- lot of code reworking that I don't have time for right now.
*/
-
-make_luaS_index(id);
-make_luaS_index(next);
-make_luaS_index(char);
-make_luaS_index(font);
-make_luaS_index(attr);
-make_luaS_index(prev);
-make_luaS_index(lang);
-make_luaS_index(subtype);
-make_luaS_index(left);
-make_luaS_index(right);
-make_luaS_index(uchyph);
-make_luaS_index(components);
-make_luaS_index(xoffset);
-make_luaS_index(yoffset);
-make_luaS_index(width);
-make_luaS_index(height);
-make_luaS_index(depth);
-make_luaS_index(expansion_factor);
-make_luaS_index(list);
-make_luaS_index(head);
-
-
-static void initialize_luaS_indexes(lua_State * L)
-{
- init_luaS_index(id);
- init_luaS_index(next);
- init_luaS_index(char);
- init_luaS_index(font);
- init_luaS_index(attr);
- init_luaS_index(prev);
- init_luaS_index(lang);
- init_luaS_index(subtype);
- init_luaS_index(left);
- init_luaS_index(right);
- init_luaS_index(uchyph);
- init_luaS_index(components);
- init_luaS_index(xoffset);
- init_luaS_index(yoffset);
- init_luaS_index(width);
- init_luaS_index(height);
- init_luaS_index(depth);
- init_luaS_index(expansion_factor);
- init_luaS_index(list);
- init_luaS_index(head);
-}
-
static int get_node_field_id(lua_State * L, int n, int node)
{
register int t = type(node);
register const char *s = lua_tostring(L, n);
+
if (s == NULL)
return -2;
- if (luaS_ptr_eq(s, list)) {
- s = luaS_head_ptr; /* create a |head| alias for now */
- }
+
if (luaS_ptr_eq(s, next)) {
return 0;
} else if (luaS_ptr_eq(s, id)) {
return 1;
- } else if (luaS_ptr_eq(s, attr) && nodetype_has_attributes(t)) {
- return 3;
- } else if (t == glyph_node) {
- if (luaS_ptr_eq(s, subtype)) {
+ } else if (luaS_ptr_eq(s, subtype)) {
+ if (nodetype_has_subtype(t)) {
return 2;
- } else if (luaS_ptr_eq(s, font)) {
- return 5;
- } else if (luaS_ptr_eq(s, char)) {
- return 4;
- } else if (luaS_ptr_eq(s, prev)) {
+ }
+ } else if (luaS_ptr_eq(s, attr)) {
+ if (nodetype_has_attributes(t)) {
+ return 3;
+ }
+ } else if (luaS_ptr_eq(s, prev)) {
+ if (nodetype_has_prev(t)) {
return -1;
- } else if (luaS_ptr_eq(s, lang)) {
- return 6;
- } else if (luaS_ptr_eq(s, left)) {
- return 7;
- } else if (luaS_ptr_eq(s, right)) {
- return 8;
- } else if (luaS_ptr_eq(s, uchyph)) {
- return 9;
- } else if (luaS_ptr_eq(s, components)) {
- return 10;
- } else if (luaS_ptr_eq(s, xoffset)) {
- return 11;
- } else if (luaS_ptr_eq(s, yoffset)) {
- return 12;
- } else if (luaS_ptr_eq(s, width)) {
- return 13;
- } else if (luaS_ptr_eq(s, height)) {
- return 14;
- } else if (luaS_ptr_eq(s, depth)) {
- return 15;
- } else if (luaS_ptr_eq(s, expansion_factor)) {
- return 16;
}
- } else if (luaS_ptr_eq(s, prev) && nodetype_has_prev(t)) {
- return -1;
- } else if (luaS_ptr_eq(s, subtype) && nodetype_has_subtype(t)) {
- return 2;
} else {
int j;
const char **fields = node_data[t].fields;
- if (t == whatsit_node)
+ if (t == whatsit_node) {
fields = whatsit_node_data[subtype(node)].fields;
- if (fields != NULL) {
- for (j = 0; fields[j] != NULL; j++) {
+ }
+ if (luaS_ptr_eq(s, list)) {
+ /* head and list are equivalent; we don't catch extra virtual fields */
+ s = luaS_head_ptr;
+ }
+ if (fields != NULL) {
+ for (j = 0; fields[j] != NULL; j++) {
if (strcmp(s, fields[j]) == 0) {
- return j + 3;
- }
- }
+ return j + 3;
+ }
+ }
}
}
return -2;
}
-
-static int get_valid_node_field_id(lua_State * L, int n, int node)
-{
- int i = get_node_field_id(L, n, node);
- if (i == -2) {
- const char *s = lua_tostring(L, n);
- luaL_error(L, "Invalid field id %s for node type %s (%d)", s,
- node_data[type(node)].name, subtype(node));
- }
- return i;
-}
-
static int lua_nodelib_has_field(lua_State * L)
{
int i = -2;
@@ -891,7 +1066,6 @@ static int lua_nodelib_whatsits(lua_State * L)
return do_lua_nodelib_types(L, whatsit_node_data);
}
-
/* fetch the list of valid fields */
static int lua_nodelib_fields(lua_State * L)
@@ -908,7 +1082,7 @@ static int lua_nodelib_fields(lua_State * L)
}
lua_checkstack(L, 2);
lua_newtable(L);
- lua_pushstring(L, "next");
+ lua_pushstring(L, "next"); /* next, id, subtype, prev could be predefined string */
lua_rawseti(L, -2, 0);
lua_pushstring(L, "id");
lua_rawseti(L, -2, 1);
@@ -968,6 +1142,27 @@ static int lua_nodelib_tail_only(lua_State * L)
return 1;
}
+static int lua_nodelib_end_of_math(lua_State * L)
+{
+ halfword *n;
+ halfword t;
+ if (lua_isnil(L, 1))
+ return 1; /* the nil itself */
+ n = check_isnode(L, 1);
+ t = *n;
+ if (t == null)
+ return 1; /* the old userdata */
+ while (vlink(t) != null) {
+ t = vlink(t); /* skip first node */
+ if (t && type(t)==math_node) {
+ lua_nodelib_push_fast(L, t);
+ return 1;
+ }
+ }
+ lua_pushnil(L);
+ return 1;
+}
+
/* a few utility functions for attribute stuff */
@@ -1013,8 +1208,8 @@ static int lua_nodelib_unset_attribute(lua_State * L)
halfword *n;
int i, val, ret;
if (lua_gettop(L) <= 3) {
- lua_number2int(i, luaL_checknumber(L, 2));
- lua_number2int(val, luaL_optnumber(L, 3, UNUSED_ATTRIBUTE));
+ i=(int)luaL_checknumber(L, 2);
+ val=(int)luaL_optnumber(L, 3, UNUSED_ATTRIBUTE);
n = check_isnode(L, 1);
ret = unset_attribute(*n, i, val);
if (ret > UNUSED_ATTRIBUTE) {
@@ -1028,7 +1223,6 @@ static int lua_nodelib_unset_attribute(lua_State * L)
}
}
-
/* iteration */
static int nodelib_aux_nil(lua_State * L)
@@ -1106,13 +1300,10 @@ static int lua_nodelib_traverse(lua_State * L)
;
}
-
-
-static int
-do_lua_nodelib_count(lua_State * L, halfword match, int i, halfword first)
+static int do_lua_nodelib_count(lua_State * L, halfword match, int i, halfword first1)
{
int count = 0;
- int t = first;
+ int t = first1;
while (t != match) {
if (i < 0 || type(t) == i) {
count++;
@@ -1165,1038 +1356,793 @@ static int lua_nodelib_count(lua_State * L)
static void nodelib_pushdir(lua_State * L, int n, boolean dirnode)
{
- char s[2];
if (dirnode) {
- s[0] = (char) (n < 0 ? '-' : '+');
- s[1] = 0;
+ lua_pushstring(L, dir_strings[n+64]);
} else {
- s[0] = 0;
- }
- if (n < 0)
- n += 64;
- if (n == dir_TLT) {
- lua_pushfstring(L, "%sTLT", s);
- } else if (n == dir_TRT) {
- lua_pushfstring(L, "%sTRT", s);
- } else if (n == dir_LTL) {
- lua_pushfstring(L, "%sLTL", s);
- } else if (n == dir_RTT) {
- lua_pushfstring(L, "%sRTT", s);
- } else {
- lua_pushstring(L, "???");
+ lua_pushstring(L, dir_strings[n+64]+1);
}
}
-static void lua_nodelib_getfield_whatsit(lua_State * L, int n, int field)
+static void lua_nodelib_getfield_whatsit(lua_State * L, int n, const char *s)
{
- if (field == 2) {
- lua_pushnumber(L, subtype(n));
- } else {
- switch (subtype(n)) {
- case open_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, write_stream(n));
- break;
- case 5:
- nodelib_pushstring(L, open_name(n));
- break;
- case 6:
- nodelib_pushstring(L, open_area(n));
- break;
- case 7:
- nodelib_pushstring(L, open_ext(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case write_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, write_stream(n));
- break;
- case 5:
- tokenlist_to_lua(L, write_tokens(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case close_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, write_stream(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case special_node:
- switch (field) {
- case 4:
- tokenlist_to_luastring(L, write_tokens(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case local_par_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, local_pen_inter(n));
- break;
- case 5:
- lua_pushnumber(L, local_pen_broken(n));
- break;
- case 6:
- nodelib_pushdir(L, local_par_dir(n), false);
- break;
- case 7:
- nodelib_pushlist(L, local_box_left(n));
- break;
- case 8:
- lua_pushnumber(L, local_box_left_width(n));
- break;
- case 9:
- nodelib_pushlist(L, local_box_right(n));
- break;
- case 10:
- lua_pushnumber(L, local_box_right_width(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case dir_node:
- switch (field) {
- case 4:
- nodelib_pushdir(L, dir_dir(n), true);
- break;
- case 5:
- lua_pushnumber(L, dir_level(n));
- break;
- case 6:
- lua_pushnumber(L, dir_dvi_ptr(n));
- break;
- case 7:
- lua_pushnumber(L, dir_dvi_h(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_literal_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, pdf_literal_mode(n));
- break;
- case 5:
- if (pdf_literal_type(n) == lua_refid_literal) {
- lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(n));
- } else {
- tokenlist_to_luastring(L, pdf_literal_data(n));
- }
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_refobj_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, pdf_obj_objnum(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_refxform_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_xform_objnum(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_refximage_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_ximage_transform(n));
- break;
- case 8:
- lua_pushnumber(L, pdf_ximage_index(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_annot_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_annot_objnum(n));
- break;
- case 8:
- tokenlist_to_luastring(L, pdf_annot_data(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_start_link_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_link_objnum(n));
- break;
- case 8:
- tokenlist_to_luastring(L, pdf_link_attr(n));
- break;
- case 9:
- nodelib_pushaction(L, pdf_link_action(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_dest_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_dest_named_id(n));
- break;
- case 8:
- if (pdf_dest_named_id(n) == 1)
- tokenlist_to_luastring(L, pdf_dest_id(n));
- else
- lua_pushnumber(L, pdf_dest_id(n));
- break;
- case 9:
- lua_pushnumber(L, pdf_dest_type(n));
- break;
- case 10:
- lua_pushnumber(L, pdf_dest_xyz_zoom(n));
- break;
- case 11:
- lua_pushnumber(L, pdf_dest_objnum(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case pdf_thread_node:
- case pdf_start_thread_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- lua_pushnumber(L, pdf_thread_named_id(n));
- break;
- case 8:
- if (pdf_thread_named_id(n) == 1)
- tokenlist_to_luastring(L, pdf_thread_id(n));
- else
- lua_pushnumber(L, pdf_thread_id(n));
+ register int t ;
+ t = subtype(n);
+
+ if (t == dir_node) {
+ if (luaS_ptr_eq(s, dir)) {
+ nodelib_pushdir(L, dir_dir(n), true);
+ } else if (luaS_ptr_eq(s, level)) {
+ lua_pushnumber(L, dir_level(n));
+ } else if (luaS_ptr_eq(s, dvi_ptr)) {
+ lua_pushnumber(L, dir_dvi_ptr(n));
+ } else if (luaS_ptr_eq(s, dir_h)) {
+ lua_pushnumber(L, dir_dvi_h(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == user_defined_node) {
+ if (luaS_ptr_eq(s, user_id)) {
+ lua_pushnumber(L, user_node_id(n));
+ } else if (luaS_ptr_eq(s, type)) {
+ lua_pushnumber(L, user_node_type(n));
+ } else if (luaS_ptr_eq(s, value)) {
+ switch (user_node_type(n)) {
+ case 'a':
+ nodelib_pushlist(L, user_node_value(n));
break;
- case 9:
- tokenlist_to_luastring(L, pdf_thread_attr(n));
+ case 'd':
+ lua_pushnumber(L, user_node_value(n));
break;
- default:
- lua_pushnil(L);
- }
- break;
- case late_lua_node:
- switch (field) {
- case 4: /* regid (obsolete?)*/
- lua_pushnumber(L, late_lua_reg(n));
+ case 'n':
+ nodelib_pushlist(L, user_node_value(n));
break;
- case 6: /* name */
- tokenlist_to_luastring(L, late_lua_name(n));
+ case 's':
+ nodelib_pushstring(L, user_node_value(n));
break;
- case 5: /* data */
- case 7: /* string */
- if (late_lua_type(n) == lua_refid_literal) {
- lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(n));
- } else {
- tokenlist_to_luastring(L, late_lua_data(n));
- }
+ case 't':
+ tokenlist_to_lua(L, user_node_value(n));
break;
default:
- lua_pushnil(L);
- }
- break;
- case close_lua_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, late_lua_reg(n));
+ lua_pushnumber(L, user_node_value(n));
break;
- default:
- lua_pushnil(L);
}
- break;
- case pdf_colorstack_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, pdf_colorstack_stack(n));
- break;
- case 5:
- lua_pushnumber(L, pdf_colorstack_cmd(n));
- break;
- case 6:
- tokenlist_to_luastring(L, pdf_colorstack_data(n));
- break;
- default:
- lua_pushnil(L);
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == local_par_node) {
+ if (luaS_ptr_eq(s, pen_inter)) {
+ lua_pushnumber(L, local_pen_inter(n));
+ } else if (luaS_ptr_eq(s, pen_broken)) {
+ lua_pushnumber(L, local_pen_broken(n));
+ } else if (luaS_ptr_eq(s, dir)) {
+ nodelib_pushdir(L, local_par_dir(n), false);
+ } else if (luaS_ptr_eq(s, box_left)) {
+ nodelib_pushlist(L, local_box_left(n));
+ } else if (luaS_ptr_eq(s, box_left_width)) {
+ lua_pushnumber(L, local_box_left_width(n));
+ } else if (luaS_ptr_eq(s, box_right)) {
+ nodelib_pushlist(L, local_box_right(n));
+ } else if (luaS_ptr_eq(s, box_right_width)) {
+ lua_pushnumber(L, local_box_right_width(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_literal_node) {
+ if (luaS_ptr_eq(s, mode)) {
+ lua_pushnumber(L, pdf_literal_mode(n));
+ } else if (luaS_ptr_eq(s, data)) {
+ if (pdf_literal_type(n) == lua_refid_literal) {
+ lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(n));
+ } else {
+ tokenlist_to_luastring(L, pdf_literal_data(n));
}
- break;
- case pdf_setmatrix_node:
- switch (field) {
- case 4:
- tokenlist_to_luastring(L, pdf_setmatrix_data(n));
- break;
- default:
- lua_pushnil(L);
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == late_lua_node) {
+ if (luaS_ptr_eq(s, name)) {
+ tokenlist_to_luastring(L, late_lua_name(n));
+ } else if (luaS_ptr_eq(s, data) || luaS_ptr_eq(s, string)) {
+ if (late_lua_type(n) == lua_refid_literal) {
+ lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(n));
+ } else {
+ tokenlist_to_luastring(L, late_lua_data(n));
}
- break;
- case user_defined_node:
- switch (field) {
- case 4:
- lua_pushnumber(L, user_node_id(n));
- break;
- case 5:
- lua_pushnumber(L, user_node_type(n));
- break;
- case 6:
- switch (user_node_type(n)) {
- case 'a':
- nodelib_pushlist(L, user_node_value(n));
- break;
- case 'd':
- lua_pushnumber(L, user_node_value(n));
- break;
- case 'n':
- nodelib_pushlist(L, user_node_value(n));
- break;
- case 's':
- nodelib_pushstring(L, user_node_value(n));
- break;
- case 't':
- tokenlist_to_lua(L, user_node_value(n));
- break;
- default:
- lua_pushnumber(L, user_node_value(n));
- break;
- }
- break;
- default:
- lua_pushnil(L);
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_annot_node) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, objnum)) {
+ lua_pushnumber(L, pdf_annot_objnum(n));
+ } else if (luaS_ptr_eq(s, data)) {
+ tokenlist_to_luastring(L, pdf_annot_data(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_dest_node) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, named_id)) {
+ lua_pushnumber(L, pdf_dest_named_id(n));
+ } else if (luaS_ptr_eq(s, dest_id)) {
+ if (pdf_dest_named_id(n) == 1)
+ tokenlist_to_luastring(L, pdf_dest_id(n));
+ else
+ lua_pushnumber(L, pdf_dest_id(n));
+ } else if (luaS_ptr_eq(s, dest_type)) {
+ lua_pushnumber(L, pdf_dest_type(n));
+ } else if (luaS_ptr_eq(s, xyz_zoom)) {
+ lua_pushnumber(L, pdf_dest_xyz_zoom(n));
+ } else if (luaS_ptr_eq(s, objnum)) {
+ lua_pushnumber(L, pdf_dest_objnum(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_setmatrix_node) {
+ if (luaS_ptr_eq(s, data)) {
+ tokenlist_to_luastring(L, pdf_setmatrix_data(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_colorstack_node) {
+ if (luaS_ptr_eq(s, stack)) {
+ lua_pushnumber(L, pdf_colorstack_stack(n));
+ } else if (luaS_ptr_eq(s, command)) {
+ lua_pushnumber(L, pdf_colorstack_cmd(n));
+ } else if (luaS_ptr_eq(s, data)) {
+ tokenlist_to_luastring(L, pdf_colorstack_data(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_refobj_node) {
+ if (luaS_ptr_eq(s, objnum)) {
+ lua_pushnumber(L, pdf_obj_objnum(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_refxform_node) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, objnum)) {
+ lua_pushnumber(L, pdf_xform_objnum(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_refximage_node) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, transform)) {
+ lua_pushnumber(L, pdf_ximage_transform(n));
+ } else if (luaS_ptr_eq(s, index)) {
+ lua_pushnumber(L, pdf_ximage_index(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == write_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ lua_pushnumber(L, write_stream(n));
+ } else if (luaS_ptr_eq(s, data)) {
+ tokenlist_to_lua(L, write_tokens(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == special_node) {
+ if (luaS_ptr_eq(s, data)) {
+ tokenlist_to_luastring(L, write_tokens(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == pdf_start_link_node) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, objnum)) {
+ lua_pushnumber(L, pdf_link_objnum(n));
+ } else if (luaS_ptr_eq(s, link_attr)) {
+ tokenlist_to_luastring(L, pdf_link_attr(n));
+ } else if (luaS_ptr_eq(s, action)) {
+ nodelib_pushaction(L, pdf_link_action(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) {
+ if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, named_id)) {
+ lua_pushnumber(L, pdf_thread_named_id(n));
+ } else if (luaS_ptr_eq(s, thread_id)) {
+ if (pdf_thread_named_id(n) == 1) {
+ tokenlist_to_luastring(L, pdf_thread_id(n));
+ } else {
+ lua_pushnumber(L, pdf_thread_id(n));
}
- break;
- default:
+ } else if (luaS_ptr_eq(s, thread_attr)) {
+ tokenlist_to_luastring(L, pdf_thread_attr(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (t == open_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ lua_pushnumber(L, write_stream(n));
+ } else if (luaS_ptr_eq(s, name)) {
+ nodelib_pushstring(L, open_name(n));
+ } else if (luaS_ptr_eq(s, area)) {
+ nodelib_pushstring(L, open_area(n));
+ } else if (luaS_ptr_eq(s, ext)) {
+ nodelib_pushstring(L, open_ext(n));
+ } else {
lua_pushnil(L);
- break;
}
+ } else if (t == close_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ lua_pushnumber(L, write_stream(n));
+ } else {
+ lua_pushnil(L);
+ }
+ } else {
+ lua_pushnil(L);
}
}
+ /* experiment */
+
static int lua_nodelib_getfield(lua_State * L)
{
+ /*
+ the order is somewhat determined by the occurance of nodes and
+ importance of fields
+ */
+
register halfword n;
- register int field;
+ register const char *s;
+ register int t ;
+
n = *((halfword *) lua_touserdata(L, 1));
- field = get_valid_node_field_id(L, 2, n);
- if (field == 0) {
- lua_pushnumber(L, vlink(n));
- lua_nodelib_push(L);
+ t = type(n);
+
+ /*
+
+ somenode[9] as interface to attributes ... 30% faster than has_attribute
+ (1) because there is no lua function overhead, and (2) because we already
+ know that we deal with a node so no checking is needed. The fast typecheck
+ is needed (lua_check... is a slow down actually).
+
+ */
+
+ if (lua_type(L, 2) == LUA_TNUMBER) {
+
+ register halfword p;
+ register int i;
+
+ if (! nodetype_has_attributes(t)) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ p = node_attr(n);
+ if (p == null || vlink(p) == null) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ i = (int) lua_tointeger(L, 2);
+ p = vlink(p);
+ while (p != null) {
+ if (attribute_id(p) == i) {
+ lua_pushnumber(L, (int) attribute_value(p));
+ return 1;
+ } else if (attribute_id(p) > i) {
+ lua_pushnil(L);
+ return 1;
+ }
+ p = vlink(p);
+ }
+
+ lua_pushnil(L);
return 1;
+
}
- if (field == 1) {
- lua_pushnumber(L, type(n));
+
+ s = lua_tostring(L, 2);
+
+ if (luaS_ptr_eq(s, id)) {
+ lua_pushnumber(L, t);
return 1;
- }
- if (field == -1) {
+ } else if (luaS_ptr_eq(s, next)) {
+ lua_pushnumber(L, vlink(n));
+ lua_nodelib_push(L);
+ return 1;
+ } else if (luaS_ptr_eq(s, prev)) {
lua_pushnumber(L, alink(n));
lua_nodelib_push(L);
return 1;
- }
- if (field == 3 && nodetype_has_attributes(type(n))) {
- nodelib_pushattr(L, node_attr(n));
+ } else if (luaS_ptr_eq(s, attr)) {
+ if (nodetype_has_attributes(t)) {
+ nodelib_pushattr(L, node_attr(n));
+ } else {
+ lua_pushnil(L);
+ }
return 1;
- }
- if (field < -1)
- return 0;
- switch (type(n)) {
- case hlist_node:
- case vlist_node:
- switch (field) {
- case 2:
+ } else if (t == glyph_node) {
+ /* candidates: fontchar (font,char) whd (width,height,depth) */
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- nodelib_pushdir(L, box_dir(n), false);
- break;
- case 8:
- lua_pushnumber(L, shift_amount(n));
- break;
- case 9:
- lua_pushnumber(L, glue_order(n));
- break;
- case 10:
- lua_pushnumber(L, glue_sign(n));
- break;
- case 11:
- lua_pushnumber(L, (double) glue_set(n));
- break;
- case 12:
- if (list_ptr(n)) {
- alink(list_ptr(n)) = null;
- }
- nodelib_pushlist(L, list_ptr(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, font)) {
+ lua_pushnumber(L, font(n));
+ } else if (luaS_ptr_eq(s, char)) {
+ lua_pushnumber(L, character(n));
+ } else if (luaS_ptr_eq(s, xoffset)) {
+ lua_pushnumber(L, x_displace(n));
+ } else if (luaS_ptr_eq(s, yoffset)) {
+ lua_pushnumber(L, y_displace(n));
+ } else if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, char_width(font(n),character(n)));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, char_height(font(n),character(n)));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, char_depth(font(n),character(n)));
+ } else if (luaS_ptr_eq(s, expansion_factor)) {
+ lua_pushnumber(L, ex_glyph(n));
+ } else if (luaS_ptr_eq(s, components)) {
+ nodelib_pushlist(L, lig_ptr(n));
+ } else if (luaS_ptr_eq(s, lang)) {
+ lua_pushnumber(L, char_lang(n));
+ } else if (luaS_ptr_eq(s, left)) {
+ lua_pushnumber(L, char_lhmin(n));
+ } else if (luaS_ptr_eq(s, right)) {
+ lua_pushnumber(L, char_rhmin(n));
+ } else if (luaS_ptr_eq(s, uchyph)) {
+ lua_pushnumber(L, char_uchyph(n));
+ } else {
lua_pushnil(L);
}
- break;
- case unset_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- nodelib_pushdir(L, box_dir(n), false);
- break;
- case 8:
- lua_pushnumber(L, glue_shrink(n));
- break;
- case 9:
- lua_pushnumber(L, glue_order(n));
- break;
- case 10:
- lua_pushnumber(L, glue_sign(n));
- break;
- case 11:
- lua_pushnumber(L, glue_stretch(n));
- break;
- case 12:
- lua_pushnumber(L, span_count(n));
- break;
- case 13:
+ return 1;
+ } else if ((t == hlist_node) || (t == vlist_node)) {
+ /* candidates: whd (width,height,depth) */
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, list) || luaS_ptr_eq(s, head)) {
if (list_ptr(n)) {
alink(list_ptr(n)) = null;
}
nodelib_pushlist(L, list_ptr(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case rule_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, width)) {
lua_pushnumber(L, width(n));
- break;
- case 5:
- lua_pushnumber(L, depth(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, height)) {
lua_pushnumber(L, height(n));
- break;
- case 7:
- nodelib_pushdir(L, rule_dir(n), false);
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case ins_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, float_cost(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, depth)) {
lua_pushnumber(L, depth(n));
- break;
- case 6:
- lua_pushnumber(L, height(n));
- break;
- case 7:
- nodelib_pushspec(L, split_top_ptr(n));
- break;
- case 8:
- if (ins_ptr(n)) {
- alink(ins_ptr(n)) = null;
- }
- nodelib_pushlist(L, ins_ptr(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case mark_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, mark_class(n));
- break;
- case 5:
- tokenlist_to_lua(L, mark_ptr(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case adjust_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, subtype(n));
- break;
- case 4:
- if (adjust_ptr(n)) {
- alink(adjust_ptr(n)) = null;
- }
- nodelib_pushlist(L, adjust_ptr(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, dir)) {
+ nodelib_pushdir(L, box_dir(n), false);
+ } else if (luaS_ptr_eq(s, shift)) {
+ lua_pushnumber(L, shift_amount(n));
+ } else if (luaS_ptr_eq(s, glue_order)) {
+ lua_pushnumber(L, glue_order(n));
+ } else if (luaS_ptr_eq(s, glue_sign)) {
+ lua_pushnumber(L, glue_sign(n));
+ } else if (luaS_ptr_eq(s, glue_set)) {
+ lua_pushnumber(L, (double) glue_set(n));
+ } else {
lua_pushnil(L);
}
- break;
- case disc_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == disc_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, pre)) {
nodelib_pushlist(L, vlink(pre_break(n)));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, post)) {
nodelib_pushlist(L, vlink(post_break(n)));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, replace)) {
nodelib_pushlist(L, vlink(no_break(n)));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case math_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, surround(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case glue_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == glue_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, spec)) {
nodelib_pushspec(L, glue_ptr(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, leader)) {
nodelib_pushlist(L, leader_ptr(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case glue_spec_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 3:
+ return 1;
+ } else if (t == glue_spec_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, 0); /* dummy, the only one that prevents move up */
+ } else if (luaS_ptr_eq(s, width)) {
lua_pushnumber(L, width(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, stretch)) {
lua_pushnumber(L, stretch(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, shrink)) {
lua_pushnumber(L, shrink(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, stretch_order)) {
lua_pushnumber(L, stretch_order(n));
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, shrink_order)) {
lua_pushnumber(L, shrink_order(n));
- break;
- case 8:
+ } else if (luaS_ptr_eq(s, ref_count)) {
lua_pushnumber(L, glue_ref_count(n));
- break;
- case 9:
+ } else if (luaS_ptr_eq(s, writable)) {
lua_pushboolean(L, valid_node(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case kern_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == kern_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, kern)) {
lua_pushnumber(L, width(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, expansion_factor)) {
lua_pushnumber(L, ex_kern(n));
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case penalty_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 4:
+ return 1;
+ } else if (t == penalty_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, penalty)) {
lua_pushnumber(L, penalty(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case glyph_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == rule_node) {
+ /* candidates: whd (width,height,depth) */
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, character(n));
- break;
- case 5:
- lua_pushnumber(L, font(n));
- break;
- case 6:
- lua_pushnumber(L, char_lang(n));
- break;
- case 7:
- lua_pushnumber(L, char_lhmin(n));
- break;
- case 8:
- lua_pushnumber(L, char_rhmin(n));
- break;
- case 9:
- lua_pushnumber(L, char_uchyph(n));
- break;
- case 10:
- nodelib_pushlist(L, lig_ptr(n));
- break;
- case 11:
- lua_pushnumber(L, x_displace(n));
- break;
- case 12:
- lua_pushnumber(L, y_displace(n));
- break;
- case 13:
- lua_pushnumber(L, char_width(font(n),character(n)));
- break;
- case 14:
- lua_pushnumber(L, char_height(font(n),character(n)));
- break;
- case 15:
- lua_pushnumber(L, char_depth(font(n),character(n)));
- break;
- case 16:
- lua_pushnumber(L, ex_glyph(n));
- break;
- default:
- lua_pushnil(L);
- }
- break;
- case style_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 4:
- lua_pushstring(L, math_style_names[subtype(n)]);
- break;
- default:
+ } else if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, dir)) {
+ nodelib_pushdir(L, rule_dir(n), false);
+ } else {
lua_pushnil(L);
}
- break;
- case choice_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == whatsit_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- nodelib_pushlist(L, display_mlist(n));
- break;
- case 5:
- nodelib_pushlist(L, text_mlist(n));
- break;
- case 6:
- nodelib_pushlist(L, script_mlist(n));
- break;
- case 7:
- nodelib_pushlist(L, script_script_mlist(n));
- break;
- default:
- lua_pushnil(L);
+ } else {
+ lua_nodelib_getfield_whatsit(L, n, s);
}
- break;
- case simple_noad:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == simple_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, nucleus)) {
nodelib_pushlist(L, nucleus(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, sub)) {
nodelib_pushlist(L, subscr(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, sup)) {
nodelib_pushlist(L, supscr(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case radical_noad:
- switch (field) {
- case 2:
+ return 1;
+ } else if ((t == math_char_node) || (t == math_text_char_node)) {
+ /* candidates: famchar (fam,char) */
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- nodelib_pushlist(L, nucleus(n));
- break;
- case 5:
- nodelib_pushlist(L, subscr(n));
- break;
- case 6:
- nodelib_pushlist(L, supscr(n));
- break;
- case 7:
- nodelib_pushlist(L, left_delimiter(n));
- break;
- case 8:
- nodelib_pushlist(L, degree(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, fam)) {
+ lua_pushnumber(L, math_fam(n));
+ } else if (luaS_ptr_eq(s, char)) {
+ lua_pushnumber(L, math_character(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == mark_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, class)) {
+ lua_pushnumber(L, mark_class(n));
+ } else if (luaS_ptr_eq(s, mark)) {
+ tokenlist_to_lua(L, mark_ptr(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == ins_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, cost)) {
+ lua_pushnumber(L, float_cost(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, spec)) {
+ nodelib_pushspec(L, split_top_ptr(n));
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))) {
+ if (ins_ptr(n)) {
+ alink(ins_ptr(n)) = null;
+ }
+ nodelib_pushlist(L, ins_ptr(n));
+ } else {
lua_pushnil(L);
}
- break;
- case fraction_noad:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == math_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, surround)) {
+ lua_pushnumber(L, surround(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == fraction_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, width)) {
lua_pushnumber(L, thickness(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, num)) {
nodelib_pushlist(L, numerator(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, denom)) {
nodelib_pushlist(L, denominator(n));
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, left)) {
nodelib_pushlist(L, left_delimiter(n));
- break;
- case 8:
+ } else if (luaS_ptr_eq(s, right)) {
nodelib_pushlist(L, right_delimiter(n));
- break;
- default:
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == style_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, style)) {
+ lua_pushstring(L, math_style_names[subtype(n)]);
+ } else {
lua_pushnil(L);
}
- break;
- case accent_noad:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == accent_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, nucleus)) {
nodelib_pushlist(L, nucleus(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, sub)) {
nodelib_pushlist(L, subscr(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, sup)) {
nodelib_pushlist(L, supscr(n));
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, accent)) {
nodelib_pushlist(L, accent_chr(n));
- break;
- case 8:
+ } else if (luaS_ptr_eq(s, bot_accent)) {
nodelib_pushlist(L, bot_accent_chr(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case fence_noad:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == fence_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, delim)) {
nodelib_pushlist(L, delimiter(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case math_char_node:
- case math_text_char_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == delim_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, math_fam(n));
- break;
- case 5:
- lua_pushnumber(L, math_character(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, small_fam)) {
+ lua_pushnumber(L, small_fam(n));
+ } else if (luaS_ptr_eq(s, small_char)) {
+ lua_pushnumber(L, small_char(n));
+ } else if (luaS_ptr_eq(s, large_fam)) {
+ lua_pushnumber(L, large_fam(n));
+ } else if (luaS_ptr_eq(s, large_char)) {
+ lua_pushnumber(L, large_char(n));
+ } else {
lua_pushnil(L);
}
- break;
- case sub_box_node:
- case sub_mlist_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if ((t == sub_box_node) || (t == sub_mlist_node)) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))){
if (math_list(n)) {
alink(math_list(n)) = null;
}
nodelib_pushlist(L, math_list(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case delim_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == radical_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, small_fam(n));
- break;
- case 5:
- lua_pushnumber(L, small_char(n));
- break;
- case 6:
- lua_pushnumber(L, large_fam(n));
- break;
- case 7:
- lua_pushnumber(L, large_char(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, nucleus)) {
+ nodelib_pushlist(L, nucleus(n));
+ } else if (luaS_ptr_eq(s, sub)) {
+ nodelib_pushlist(L, subscr(n));
+ } else if (luaS_ptr_eq(s, sup)) {
+ nodelib_pushlist(L, supscr(n));
+ } else if (luaS_ptr_eq(s, left)) {
+ nodelib_pushlist(L, left_delimiter(n));
+ } else if (luaS_ptr_eq(s, degree)) {
+ nodelib_pushlist(L, degree(n));
+ } else {
lua_pushnil(L);
}
- break;
- case inserting_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == margin_kern_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 3:
- nodelib_pushlist(L, last_ins_ptr(n));
- break;
- case 4:
- nodelib_pushlist(L, best_ins_ptr(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, glyph)) {
+ nodelib_pushlist(L, margin_char(n));
+ } else {
lua_pushnil(L);
}
- break;
- case split_up_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == split_up_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 3:
+ } else if (luaS_ptr_eq(s, last_ins_ptr)) {
nodelib_pushlist(L, last_ins_ptr(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, best_ins_ptr)) {
nodelib_pushlist(L, best_ins_ptr(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, broken_ptr)) {
nodelib_pushlist(L, broken_ptr(n));
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, broken_ins)) {
nodelib_pushlist(L, broken_ins(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case margin_kern_node:
- switch (field) {
- case 2:
+ return 1;
+ } else if (t == choice_node) {
+ if (luaS_ptr_eq(s, subtype)) {
lua_pushnumber(L, subtype(n));
- break;
- case 4:
- lua_pushnumber(L, width(n));
- break;
- case 5:
- nodelib_pushlist(L, margin_char(n));
- break;
- default:
+ } else if (luaS_ptr_eq(s, display)) {
+ nodelib_pushlist(L, display_mlist(n));
+ } else if (luaS_ptr_eq(s, text)) {
+ nodelib_pushlist(L, text_mlist(n));
+ } else if (luaS_ptr_eq(s, script)) {
+ nodelib_pushlist(L, script_mlist(n));
+ } else if (luaS_ptr_eq(s, scriptscript)) {
+ nodelib_pushlist(L, script_script_mlist(n));
+ } else {
lua_pushnil(L);
}
- break;
- case action_node:
- switch (field) {
- case 2:
- lua_pushnil(L); /* dummy subtype */
- break;
- case 3:
+ return 1;
+ } else if (t == inserting_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, last_ins_ptr)) {
+ nodelib_pushlist(L, last_ins_ptr(n));
+ } else if (luaS_ptr_eq(s, best_ins_ptr)) {
+ nodelib_pushlist(L, best_ins_ptr(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == attribute_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, number)) {
+ lua_pushnumber(L, attribute_id(n));
+ } else if (luaS_ptr_eq(s, value)) {
+ lua_pushnumber(L, attribute_value(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == adjust_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))) {
+ if (adjust_ptr(n)) {
+ alink(adjust_ptr(n)) = null;
+ }
+ nodelib_pushlist(L, adjust_ptr(n));
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+ } else if (t == action_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));/* dummy subtype */
+ } else if (luaS_ptr_eq(s, action_type)) {
lua_pushnumber(L, pdf_action_type(n));
- break;
- case 4:
+ } else if (luaS_ptr_eq(s, named_id)) {
lua_pushnumber(L, pdf_action_named_id(n));
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, action_id)) {
if (pdf_action_named_id(n) == 1) {
tokenlist_to_luastring(L, pdf_action_id(n));
} else {
lua_pushnumber(L, pdf_action_id(n));
}
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, file)) {
tokenlist_to_luastring(L, pdf_action_file(n));
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, new_window)) {
lua_pushnumber(L, pdf_action_new_window(n));
- break;
- case 8:
+ } else if (luaS_ptr_eq(s, data)) {
tokenlist_to_luastring(L, pdf_action_tokens(n));
- break;
- case 9:
+ } else if (luaS_ptr_eq(s, ref_count)) {
lua_pushnumber(L, pdf_action_refcount(n));
- break;
- default:
+ } else {
lua_pushnil(L);
}
- break;
- case attribute_list_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- default:
+ return 1;
+ } else if (t == unset_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else if (luaS_ptr_eq(s, width)) {
+ lua_pushnumber(L, width(n));
+ } else if (luaS_ptr_eq(s, height)) {
+ lua_pushnumber(L, height(n));
+ } else if (luaS_ptr_eq(s, depth)) {
+ lua_pushnumber(L, depth(n));
+ } else if (luaS_ptr_eq(s, dir)) {
+ nodelib_pushdir(L, box_dir(n), false);
+ } else if (luaS_ptr_eq(s, shrink)) {
+ lua_pushnumber(L, glue_shrink(n));
+ } else if (luaS_ptr_eq(s, glue_order)) {
+ lua_pushnumber(L, glue_order(n));
+ } else if (luaS_ptr_eq(s, glue_sign)) {
+ lua_pushnumber(L, glue_sign(n));
+ } else if (luaS_ptr_eq(s, stretch)) {
+ lua_pushnumber(L, glue_stretch(n));
+ } else if (luaS_ptr_eq(s, count)) {
+ lua_pushnumber(L, span_count(n));
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))){
+ if (list_ptr(n)) {
+ alink(list_ptr(n)) = null;
+ }
+ nodelib_pushlist(L, list_ptr(n));
+ } else {
lua_pushnil(L);
}
- break;
- case attribute_node:
- switch (field) {
- case 2:
- lua_pushnumber(L, 0);
- break;
- case 3:
- lua_pushnumber(L, attribute_id(n));
- break;
- case 4:
- lua_pushnumber(L, attribute_value(n));
- break;
- default:
+ return 1;
+ } else if (t == attribute_list_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ lua_pushnumber(L, subtype(n));
+ } else {
lua_pushnil(L);
}
- break;
- case whatsit_node:
- lua_nodelib_getfield_whatsit(L, n, field);
- break;
- default:
- lua_pushnil(L);
- break;
+ return 1;
+ } else {
+ return 0;
}
- return 1;
}
-
-
-
static int nodelib_getlist(lua_State * L, int n)
{
halfword *m;
@@ -2208,48 +2154,38 @@ static int nodelib_getlist(lua_State * L, int n)
}
}
-int nodelib_getdir(lua_State * L, int n)
+/* a quick helper because I am too lazy to type this out: */
+
+#define RETURN_DIR_VALUES(a) \
+ if (s==luaS_##a##_ptr) { \
+ return (dir_##a); \
+ } else if (!absolute_only) { \
+ if (s==luaS_p##a##_ptr) \
+ return (dir_##a); \
+ else if (s==luaS_m##a##_ptr) \
+ return ((dir_##a)-64); \
+ }
+
+
+int nodelib_getdir(lua_State * L, int n, int absolute_only)
{
- const char *s = NULL;
- int d = 32; /* invalid number */
if (lua_type(L, n) == LUA_TSTRING) {
- s = lua_tostring(L, n);
- if (strlen(s) == 3) {
- d = 0;
- }
- if (strlen(s) == 4) {
- if (*s == '-')
- d = -64;
- else if (*s == '+')
- d = 0;
- s++;
- }
- if (strlen(s) == 3) {
- if (strcmp(s, "TLT") == 0) {
- d += dir_TLT;
- } else if (strcmp(s, "TRT") == 0) {
- d += dir_TRT;
- } else if (strcmp(s, "LTL") == 0) {
- d += dir_LTL;
- } else if (strcmp(s, "RTT") == 0) {
- d += dir_RTT;
- }
- }
+ const char *s = lua_tostring(L, n);
+ RETURN_DIR_VALUES(TRT);
+ RETURN_DIR_VALUES(TLT);
+ RETURN_DIR_VALUES(LTL);
+ RETURN_DIR_VALUES(RTT);
+ /* still here? that's an error */
+ luaL_error(L, "Bad direction specifier %s", s);
} else {
luaL_error(L, "Direction specifiers have to be strings");
}
- if ((d > 31) || (d < -64) || (d < 0 && (d + 64) > 31)) {
- d = 0;
- luaL_error(L, "Bad direction specifier %s", lua_tostring(L, n));
- }
- return d;
+ return 0;
}
-
#define nodelib_getspec nodelib_getlist
#define nodelib_getaction nodelib_getlist
-
static str_number nodelib_getstring(lua_State * L, int a)
{
size_t k;
@@ -2272,115 +2208,37 @@ static void nodelib_setattr(lua_State * L, int stackindex, halfword n)
}
}
-static int nodelib_cantset(lua_State * L, int field, int n)
+static int nodelib_cantset(lua_State * L, int n, const char *s)
{
- luaL_error(L, "You cannot set field %d in a node of type %s",
- field, node_data[type(n)].name);
+ luaL_error(L,
+ "You cannot set field %s in a node of type %s",
+ s,
+ node_data[type(n)].name);
+
return 0;
}
-static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field)
+static int lua_nodelib_setfield_whatsit(lua_State * L, int n, const char *s)
{
- switch (subtype(n)) {
- case open_node:
- switch (field) {
- case 4:
- write_stream(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- open_name(n) = nodelib_getstring(L, 3);
- break;
- case 6:
- open_area(n) = nodelib_getstring(L, 3);
- break;
- case 7:
- open_ext(n) = nodelib_getstring(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case write_node:
- switch (field) {
- case 4:
- write_stream(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- write_tokens(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case close_node:
- switch (field) {
- case 4:
- write_stream(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case special_node:
- switch (field) {
- case 4:
- write_tokens(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case local_par_node:
- switch (field) {
- case 4:
- local_pen_inter(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- local_pen_broken(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- local_par_dir(n) = nodelib_getdir(L, 3);
- break;
- case 7:
- local_box_left(n) = nodelib_getlist(L, 3);
- break;
- case 8:
- local_box_left_width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 9:
- local_box_right(n) = nodelib_getlist(L, 3);
- break;
- case 10:
- local_box_right_width(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case dir_node:
- switch (field) {
- case 4:
- dir_dir(n) = nodelib_getdir(L, 3);
- break;
- case 5:
+ register int t ;
+ t = subtype(n);
+
+ if (t == dir_node) {
+ if (luaS_ptr_eq(s, dir)) {
+ dir_dir(n) = nodelib_getdir(L, 3, 0);
+ } else if (luaS_ptr_eq(s, level)) {
dir_level(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, dvi_ptr)) {
dir_dvi_ptr(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, dir_h)) {
dir_dvi_h(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_literal_node:
- switch (field) {
- case 4:
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_literal_node) {
+ if (luaS_ptr_eq(s, mode)) {
pdf_literal_mode(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, data)) {
if (ini_version) {
pdf_literal_data(n) = nodelib_gettoks(L, 3);
} else {
@@ -2388,188 +2246,16 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field)
pdf_literal_data(n) = luaL_ref(L, LUA_REGISTRYINDEX);
pdf_literal_type(n) = lua_refid_literal;
}
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_refobj_node:
- switch (field) {
- case 4:
- pdf_obj_objnum(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_refxform_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_xform_objnum(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_refximage_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_ximage_transform(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 8:
- pdf_ximage_index(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_annot_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_annot_objnum(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 8:
- pdf_annot_data(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_start_link_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_link_objnum(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 8:
- pdf_link_attr(n) = nodelib_gettoks(L, 3);
- break;
- case 9:
- pdf_link_action(n) = nodelib_getaction(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_end_link_node:
- switch (field) {
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_dest_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_dest_named_id(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 8:
- if (pdf_dest_named_id(n) == 1)
- pdf_dest_id(n) = nodelib_gettoks(L, 3);
- else
- pdf_dest_id(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 9:
- pdf_dest_type(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 10:
- pdf_dest_xyz_zoom(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 11:
- pdf_dest_objnum(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_thread_node:
- case pdf_start_thread_node:
- switch (field) {
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- pdf_thread_named_id(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 8:
- if (pdf_thread_named_id(n) == 1)
- pdf_thread_id(n) = nodelib_gettoks(L, 3);
- else
- pdf_thread_id(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 9:
- pdf_thread_attr(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_end_thread_node:
- case pdf_save_pos_node:
- return nodelib_cantset(L, field, n);
- break;
- case late_lua_node:
- switch (field) {
- case 4:
- late_lua_reg(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5: /* data */
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == late_lua_node) {
+ if (luaS_ptr_eq(s, data)) {
late_lua_data(n) = nodelib_gettoks(L, 3);
late_lua_type(n) = normal;
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, name)) {
late_lua_name(n) = nodelib_gettoks(L, 3);
- break;
- case 7: /* string */
+ } else if (luaS_ptr_eq(s, string)) {
if (ini_version) {
late_lua_data(n) = nodelib_gettoks(L, 3);
late_lua_type(n) = normal;
@@ -2578,58 +2264,15 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field)
late_lua_data(n) = luaL_ref(L, LUA_REGISTRYINDEX);
late_lua_type(n) = lua_refid_literal;
}
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case close_lua_node:
- switch (field) {
- case 4:
- late_lua_reg(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_colorstack_node:
- switch (field) {
- case 4:
- pdf_colorstack_stack(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- pdf_colorstack_cmd(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- pdf_colorstack_data(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_setmatrix_node:
- switch (field) {
- case 4:
- pdf_setmatrix_data(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case pdf_save_node:
- case pdf_restore_node:
- case cancel_boundary_node:
- return nodelib_cantset(L, field, n);
- break;
- case user_defined_node:
- switch (field) {
- case 4:
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == user_defined_node) {
+ if (luaS_ptr_eq(s, user_id)) {
user_node_id(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, type)) {
user_node_type(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, value)) {
switch (user_node_type(n)) {
case 'a':
user_node_value(n) = nodelib_getlist(L, 3);
@@ -2650,14 +2293,186 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field)
user_node_value(n) = (halfword) lua_tointeger(L, 3);
break;
}
- break;
- default:
- return nodelib_cantset(L, field, n);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_annot_node) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, objnum)) {
+ pdf_annot_objnum(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, data)) {
+ pdf_annot_data(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_dest_node) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, named_id)) {
+ pdf_dest_named_id(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, dest_id)) {
+ if (pdf_dest_named_id(n) == 1) {
+ pdf_dest_id(n) = nodelib_gettoks(L, 3);
+ } else {
+ pdf_dest_id(n) = (halfword) lua_tointeger(L, 3);
+ }
+ } else if (luaS_ptr_eq(s, dest_type)) {
+ pdf_dest_type(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, xyz_zoom)) {
+ pdf_dest_xyz_zoom(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, objnum)) {
+ pdf_dest_objnum(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
}
- break;
- default:
+ } else if (t == pdf_setmatrix_node) {
+ if (luaS_ptr_eq(s, data)) {
+ pdf_setmatrix_data(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_refobj_node) {
+ if (luaS_ptr_eq(s, objnum)) {
+ pdf_obj_objnum(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_refxform_node) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, objnum)) {
+ pdf_xform_objnum(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_refximage_node) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, transform)) {
+ pdf_ximage_transform(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, index)) {
+ pdf_ximage_index(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == local_par_node) {
+ if (luaS_ptr_eq(s, pen_inter)) {
+ local_pen_inter(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, pen_broken)) {
+ local_pen_broken(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, dir)) {
+ local_par_dir(n) = nodelib_getdir(L, 3, 1);
+ } else if (luaS_ptr_eq(s, box_left)) {
+ local_box_left(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, box_left_width)) {
+ local_box_left_width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, box_right)) {
+ local_box_right(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, box_right_width)) {
+ local_box_right_width(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_start_link_node) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, objnum)) {
+ pdf_link_objnum(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, link_attr)) {
+ pdf_link_attr(n) = nodelib_gettoks(L, 3);
+ } else if (luaS_ptr_eq(s, action)) {
+ pdf_link_action(n) = nodelib_getaction(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == write_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ write_stream(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, data)) {
+ write_tokens(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == pdf_colorstack_node) {
+ if (luaS_ptr_eq(s, stack)) {
+ pdf_colorstack_stack(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, command)) {
+ pdf_colorstack_cmd(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, data)) {
+ pdf_colorstack_data(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if ((t == pdf_thread_node) || (t == pdf_start_thread_node)) {
+ if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, named_id)) {
+ pdf_thread_named_id(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, thread_id)) {
+ if (pdf_thread_named_id(n) == 1) {
+ pdf_thread_id(n) = nodelib_gettoks(L, 3);
+ } else {
+ pdf_thread_id(n) = (halfword) lua_tointeger(L, 3);
+ }
+ } else if (luaS_ptr_eq(s, thread_attr)) {
+ pdf_thread_attr(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == special_node) {
+ if (luaS_ptr_eq(s, data)) {
+ write_tokens(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == open_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ write_stream(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, name)) {
+ open_name(n) = nodelib_getstring(L, 3);
+ } else if (luaS_ptr_eq(s, area)) {
+ open_area(n) = nodelib_getstring(L, 3);
+ } else if (luaS_ptr_eq(s, ext)) {
+ open_ext(n) = nodelib_getstring(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == close_node) {
+ if (luaS_ptr_eq(s, stream)) {
+ write_stream(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if ((t == pdf_end_link_node) || (t == pdf_end_thread_node) || (t == pdf_save_pos_node) ||
+ (t == pdf_save_node) || (t == pdf_restore_node) || (t == cancel_boundary_node)) {
+ return nodelib_cantset(L, n, s);
+ } else {
/* do nothing */
- break;
}
return 0;
}
@@ -2665,614 +2480,454 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field)
static int lua_nodelib_setfield(lua_State * L)
{
register halfword n;
- register int field;
+ register const char *s;
+ register int t ;
+
n = *((halfword *) lua_touserdata(L, 1));
- field = get_valid_node_field_id(L, 2, n);
- if (field < -1)
+ t = type(n);
+
+ if (lua_type(L, 2) == LUA_TNUMBER) {
+
+ register int i, val;
+
+ if (lua_gettop(L) == 3) {
+ i = (int) lua_tointeger(L, 2);
+ val = (int) lua_tointeger(L, 3);
+ if (val == UNUSED_ATTRIBUTE) {
+ (void) unset_attribute(n, i, val);
+ } else {
+ set_attribute(n, i, val);
+ }
+ } else {
+ luaL_error(L, "incorrect number of arguments");
+ }
return 0;
- if (field !=0 && /* .next assignments are always allowed */
- !valid_node(n)) {
- return luaL_error(L, "You can't assign to this %s node (%d)\n", node_data[type(n)].name, n);
- /* return implied */
}
- if (field == 0) {
+
+ s = lua_tostring(L, 2);
+
+ if (luaS_ptr_eq(s, id)) {
+ lua_pushnumber(L, t);
+ } else if (luaS_ptr_eq(s, next)) {
halfword x = nodelib_getlist(L, 3);
if (x>0 && type(x) == glue_spec_node) {
return luaL_error(L, "You can't assign a %s node to a next field\n", node_data[type(x)].name);
}
vlink(n) = x;
- } else if (field == -1) {
+ } else if (luaS_ptr_eq(s, prev)) {
halfword x = nodelib_getlist(L, 3);
if (x>0 && type(x) == glue_spec_node) {
return luaL_error(L, "You can't assign a %s node to a prev field\n", node_data[type(x)].name);
}
alink(n) = x;
- } else if (field == 3 && nodetype_has_attributes(type(n))) {
- nodelib_setattr(L, 3, n);
- } else if (type(n) == glyph_node) {
- switch (field) {
- case 2:
+ } else if (luaS_ptr_eq(s, attr)) {
+ if (nodetype_has_attributes(type(n))) {
+ nodelib_setattr(L, 3, n);
+ }
+ } else if (t == glyph_node) {
+ if (luaS_ptr_eq(s, subtype)) {
subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- character(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
+ } else if (luaS_ptr_eq(s, font)) {
font(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
+ } else if (luaS_ptr_eq(s, char)) {
+ character(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, xoffset)) {
+ x_displace(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, yoffset)) {
+ y_displace(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, width)) {
+ /* not yet */
+ } else if (luaS_ptr_eq(s, height)) {
+ /* not yet */
+ } else if (luaS_ptr_eq(s, depth)) {
+ /* not yet */
+ } else if (luaS_ptr_eq(s, expansion_factor)) {
+ ex_glyph(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, components)) {
+ lig_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, lang)) {
set_char_lang(n, (halfword) lua_tointeger(L, 3));
- break;
- case 7:
+ } else if (luaS_ptr_eq(s, left)) {
set_char_lhmin(n, (halfword) lua_tointeger(L, 3));
- break;
- case 8:
+ } else if (luaS_ptr_eq(s, right)) {
set_char_rhmin(n, (halfword) lua_tointeger(L, 3));
- break;
- case 9:
+ } else if (luaS_ptr_eq(s, uchyph)) {
set_char_uchyph(n, (halfword) lua_tointeger(L, 3));
- break;
- case 10:
- lig_ptr(n) = nodelib_getlist(L, 3);
- break;
- case 11:
- x_displace(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 12:
- y_displace(n) = (halfword) lua_tointeger(L, 3);
- break;
- /* 13,14,15 are virtual width, height, depth */
- case 16:
- ex_glyph(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
+ } else {
+ return nodelib_cantset(L, n, s);
}
- } else {
- switch (type(n)) {
- case hlist_node:
- case vlist_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- box_dir(n) = nodelib_getdir(L, 3);
- break;
- case 8:
- shift_amount(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 9:
- glue_order(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 10:
- glue_sign(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 11:
- glue_set(n) = (glue_ratio) lua_tonumber(L, 3);
- break;
- case 12:
- list_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case unset_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- box_dir(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 8:
- glue_shrink(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 9:
- glue_order(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 10:
- glue_sign(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 11:
- glue_stretch(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 12:
- span_count(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 13:
- list_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case rule_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- rule_dir(n) = nodelib_getdir(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case ins_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- float_cost(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- depth(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- height(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- split_top_ptr(n) = nodelib_getspec(L, 3);
- break;
- case 8:
- ins_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case mark_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- mark_class(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- mark_ptr(n) = nodelib_gettoks(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case adjust_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- adjust_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case disc_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- set_disc_field(pre_break(n), nodelib_getlist(L, 3));
- break;
- case 5:
- set_disc_field(post_break(n), nodelib_getlist(L, 3));
- break;
- case 6:
- set_disc_field(no_break(n), nodelib_getlist(L, 3));
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case math_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- surround(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case glue_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- glue_ptr(n) = nodelib_getspec(L, 3);
- break;
- case 5:
- leader_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case glue_spec_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 3:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 4:
- stretch(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- shrink(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- stretch_order(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 7:
- shrink_order(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 8:
- glue_ref_count(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
-
- }
- break;
- case kern_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- ex_kern(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case penalty_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 4:
- penalty(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case action_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 3:
- pdf_action_type(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 5:
- if (pdf_action_named_id(n) == 1) {
- pdf_action_id(n) = nodelib_gettoks(L, 3);
- } else {
- pdf_action_id(n) = (halfword) lua_tointeger(L, 3);
- }
- break;
- case 6:
- pdf_action_file(n) = nodelib_gettoks(L, 3);
- break;
- case 7:
- pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 8:
- pdf_action_tokens(n) = nodelib_gettoks(L, 3);
- break;
- case 9:
- pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case style_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 4:
- subtype(n) =
- (quarterword) luaL_checkoption(L, 3, "text",
- math_style_names);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case choice_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- display_mlist(n) = nodelib_getlist(L, 3);
- break;
- case 5:
- text_mlist(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- script_mlist(n) = nodelib_getlist(L, 3);
- break;
- case 7:
- script_script_mlist(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case simple_noad:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- nucleus(n) = nodelib_getlist(L, 3);
- break;
- case 5:
- subscr(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- supscr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case radical_noad:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- nucleus(n) = nodelib_getlist(L, 3);
- break;
- case 5:
- subscr(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- supscr(n) = nodelib_getlist(L, 3);
- break;
- case 7:
- left_delimiter(n) = nodelib_getlist(L, 3);
- break;
- case 8:
- degree(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case fraction_noad:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- thickness(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- numerator(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- denominator(n) = nodelib_getlist(L, 3);
- break;
- case 7:
- left_delimiter(n) = nodelib_getlist(L, 3);
- break;
- case 8:
- right_delimiter(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case accent_noad:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- nucleus(n) = nodelib_getlist(L, 3);
- break;
- case 5:
- subscr(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- supscr(n) = nodelib_getlist(L, 3);
- break;
- case 7:
- accent_chr(n) = nodelib_getlist(L, 3);
- break;
- case 8:
- bot_accent_chr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case fence_noad:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- delimiter(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case math_char_node:
- case math_text_char_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- math_fam(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- math_character(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case sub_box_node:
- case sub_mlist_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- math_list(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case delim_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- small_fam(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- small_char(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 6:
- large_fam(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 7:
- large_char(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case margin_kern_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 4:
- width(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 5:
- margin_char(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case inserting_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 3:
- last_ins_ptr(n) = nodelib_getlist(L, 3);
- break;
- case 4:
- best_ins_ptr(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case split_up_node:
- switch (field) {
- case 2:
- subtype(n) = (quarterword) lua_tointeger(L, 3);
- break;
- case 3:
- last_ins_ptr(n) = nodelib_getlist(L, 3);
- break;
- case 4:
- best_ins_ptr(n) = nodelib_getlist(L, 3);
- break;
- case 5:
- broken_ptr(n) = nodelib_getlist(L, 3);
- break;
- case 6:
- broken_ins(n) = nodelib_getlist(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case attribute_list_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case attribute_node:
- switch (field) {
- case 2: /* dummy subtype */
- break;
- case 3:
- attribute_id(n) = (halfword) lua_tointeger(L, 3);
- break;
- case 4:
- attribute_value(n) = (halfword) lua_tointeger(L, 3);
- break;
- default:
- return nodelib_cantset(L, field, n);
- }
- break;
- case whatsit_node:
- lua_nodelib_setfield_whatsit(L, n, field);
- break;
- default:
- /* do nothing */
- break;
+ } else if ((t == hlist_node) || (t == vlist_node)) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, list) || luaS_ptr_eq(s, head)) {
+ list_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, dir)) {
+ box_dir(n) = nodelib_getdir(L, 3, 1);
+ } else if (luaS_ptr_eq(s, shift)) {
+ shift_amount(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glue_order)) {
+ glue_order(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glue_sign)) {
+ glue_sign(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glue_set)) {
+ glue_set(n) = (glue_ratio) lua_tonumber(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == disc_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, pre)) {
+ set_disc_field(pre_break(n), nodelib_getlist(L, 3));
+ } else if (luaS_ptr_eq(s, post)) {
+ set_disc_field(post_break(n), nodelib_getlist(L, 3));
+ } else if (luaS_ptr_eq(s, replace)) {
+ set_disc_field(no_break(n), nodelib_getlist(L, 3));
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == glue_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, spec)) {
+ glue_ptr(n) = nodelib_getspec(L, 3);
+ } else if (luaS_ptr_eq(s, leader)) {
+ leader_ptr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == glue_spec_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3); /* dummy, the only one that prevents move up */
+ } else if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, stretch)) {
+ stretch(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, shrink)) {
+ shrink(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, stretch_order)) {
+ stretch_order(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, shrink_order)) {
+ lua_pushnumber(L, shrink_order(n));
+ /* } else if (luaS_ptr_eq(s, ref_count)) {
+ glue_ref_count(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, writable)) {
+ */
+ /* can't be set */
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == kern_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, kern)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, expansion_factor)) {
+ ex_kern(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == penalty_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else if (luaS_ptr_eq(s, penalty)) {
+ penalty(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == rule_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, dir)) {
+ rule_dir(n) = nodelib_getdir(L, 3, 1);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == whatsit_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else {
+ lua_nodelib_setfield_whatsit(L, n, s);
+ }
+ } else if (t == simple_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, nucleus)) {
+ nucleus(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sub)) {
+ subscr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sup)) {
+ supscr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if ((t == math_char_node) || (t == math_text_char_node)) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, fam)) {
+ math_fam(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, char)) {
+ math_character(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == mark_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, class)) {
+ mark_class(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, mark)) {
+ mark_ptr(n) = nodelib_gettoks(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == ins_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, cost)) {
+ float_cost(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, spec)) {
+ split_top_ptr(n) = nodelib_getspec(L, 3);
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))) {
+ ins_ptr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == math_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, surround)) {
+ surround(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == fraction_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, width)) {
+ thickness(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, num)) {
+ numerator(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, denom)) {
+ denominator(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, left)) {
+ left_delimiter(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, right)) {
+ right_delimiter(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == style_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else if (luaS_ptr_eq(s, style)) {
+ lua_pushstring(L, math_style_names[subtype(n)]);
+ } else {
+ /* return nodelib_cantset(L, n, s); */
+ subtype(n) = (quarterword) luaL_checkoption(L, 3, "text", math_style_names);
+ }
+ } else if (t == accent_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, nucleus)) {
+ nucleus(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sub)) {
+ subscr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sup)) {
+ supscr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, accent)) {
+ accent_chr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, bot_accent)) {
+ bot_accent_chr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == fence_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, delim)) {
+ delimiter(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == delim_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, small_fam)) {
+ small_fam(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, small_char)) {
+ small_char(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, large_fam)) {
+ large_fam(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, large_char)) {
+ large_char(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if ((t == sub_box_node) || (t == sub_mlist_node)) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))){
+ math_list(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == radical_noad) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, nucleus)) {
+ nucleus(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sub)) {
+ subscr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, sup)) {
+ supscr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, left)) {
+ left_delimiter(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, degree)) {
+ degree(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == margin_kern_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glyph)) {
+ margin_char(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == split_up_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, last_ins_ptr)) {
+ last_ins_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, best_ins_ptr)) {
+ best_ins_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, broken_ptr)) {
+ broken_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, broken_ins)) {
+ broken_ins(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == choice_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, display)) {
+ display_mlist(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, text)) {
+ text_mlist(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, script)) {
+ script_mlist(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, scriptscript)) {
+ script_script_mlist(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
}
+ } else if (t == inserting_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, last_ins_ptr)) {
+ last_ins_ptr(n) = nodelib_getlist(L, 3);
+ } else if (luaS_ptr_eq(s, best_ins_ptr)) {
+ best_ins_ptr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == attribute_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else if (luaS_ptr_eq(s, number)) {
+ attribute_id(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, value)) {
+ attribute_value(n) = (halfword) lua_tointeger(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == adjust_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ subtype(n) = (quarterword) lua_tointeger(L, 3);
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))) {
+ adjust_ptr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == action_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else if (luaS_ptr_eq(s, action_type)) {
+ pdf_action_type(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, named_id)) {
+ pdf_action_named_id(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, action_id)) {
+ if (pdf_action_named_id(n) == 1) {
+ pdf_action_id(n) = nodelib_gettoks(L, 3);
+ } else {
+ pdf_action_id(n) = (halfword) lua_tointeger(L, 3);
+ }
+ } else if (luaS_ptr_eq(s, file)) {
+ pdf_action_file(n) = nodelib_gettoks(L, 3);
+ } else if (luaS_ptr_eq(s, new_window)) {
+ pdf_action_new_window(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, data)) {
+ pdf_action_tokens(n) = nodelib_gettoks(L, 3);
+ /* } else if (luaS_ptr_eq(s, ref_count)) {
+ pdf_action_refcount(n) = (halfword) lua_tointeger(L, 3); */
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == unset_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else if (luaS_ptr_eq(s, width)) {
+ width(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, height)) {
+ height(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, depth)) {
+ depth(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, dir)) {
+ box_dir(n) = nodelib_getdir(L, 3, 1);
+ } else if (luaS_ptr_eq(s, shrink)) {
+ glue_shrink(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glue_order)) {
+ glue_order(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, glue_sign)) {
+ glue_sign(n) = (quarterword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, stretch)) {
+ glue_stretch(n) = (halfword) lua_tointeger(L, 3);
+ } else if (luaS_ptr_eq(s, count)) {
+ span_count(n) = (quarterword) lua_tointeger(L, 3);
+ } else if ((luaS_ptr_eq(s, list)) || (luaS_ptr_eq(s, head))){
+ list_ptr(n) = nodelib_getlist(L, 3);
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else if (t == attribute_list_node) {
+ if (luaS_ptr_eq(s, subtype)) {
+ /* dummy subtype */
+ } else {
+ return nodelib_cantset(L, n, s);
+ }
+ } else {
+ return luaL_error(L, "You can't assign to this %s node (%d)\n", node_data[t].name, n);
}
return 0;
}
@@ -3296,7 +2951,6 @@ static int lua_nodelib_print(lua_State * L)
return 1;
}
-
static int lua_nodelib_equal(lua_State * L)
{
register halfword n, m;
@@ -3434,8 +3088,6 @@ static int lua_nodelib_first_character(lua_State * L)
return lua_nodelib_first_glyph(L);
}
-
-
/* this is too simplistic, but it helps Hans to get going */
static halfword do_ligature_n(halfword prev, halfword stop, halfword lig)
@@ -3447,9 +3099,8 @@ static halfword do_ligature_n(halfword prev, halfword stop, halfword lig)
return lig;
}
-
-
/* node.do_ligature_n(node prev, node last, node lig) */
+
static int lua_nodelib_do_ligature_n(lua_State * L)
{
halfword n, m, o, p, tmp_head;
@@ -3477,6 +3128,7 @@ static int lua_nodelib_usedlist(lua_State * L)
}
/* node.protrusion_skipable(node m) */
+
static int lua_nodelib_cp_skipable(lua_State * L)
{
halfword n;
@@ -3512,14 +3164,14 @@ static int lua_nodelib_currentattr(lua_State * L)
}
}
-
-static const struct luaL_reg nodelib_f[] = {
+static const struct luaL_Reg nodelib_f[] = {
{"copy", lua_nodelib_copy},
{"copy_list", lua_nodelib_copy_list},
{"count", lua_nodelib_count},
{"current_attr", lua_nodelib_currentattr},
{"dimensions", lua_nodelib_dimensions},
{"do_ligature_n", lua_nodelib_do_ligature_n},
+ {"end_of_math", lua_nodelib_end_of_math},
{"family_font", lua_nodelib_mfont},
{"fields", lua_nodelib_fields},
{"first_character", lua_nodelib_first_character},
@@ -3558,10 +3210,10 @@ static const struct luaL_reg nodelib_f[] = {
{"vpack", lua_nodelib_vpack},
{"whatsits", lua_nodelib_whatsits},
{"write", lua_nodelib_append},
- {NULL, NULL} /* sentinel */
+ {NULL, NULL} /* sentinel */
};
-static const struct luaL_reg nodelib_m[] = {
+static const struct luaL_Reg nodelib_m[] = {
{"__index", lua_nodelib_getfield},
{"__newindex", lua_nodelib_setfield},
{"__tostring", lua_nodelib_print},
@@ -3569,14 +3221,11 @@ static const struct luaL_reg nodelib_m[] = {
{NULL, NULL} /* sentinel */
};
-
-
int luaopen_node(lua_State * L)
{
luaL_newmetatable(L, NODE_METATABLE);
luaL_register(L, NULL, nodelib_m);
luaL_register(L, "node", nodelib_f);
- init_luaS_index(luatex_node);
initialize_luaS_indexes(L);
return 1;
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c
index 29c7f3bb00f..10a9c667c93 100644
--- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c
+++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c
@@ -25,7 +25,7 @@
#include <time.h>
static const char _svn_version[] =
- "$Id: loslibext.c 4167 2011-04-16 09:20:26Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.70.x/source/texk/web2c/luatexdir/lua/loslibext.c $";
+ "$Id: loslibext.c 4479 2012-11-07 16:38:55Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/loslibext.c $";
#if defined(_WIN32) || defined(__NT__)
# define MKDIR(a,b) mkdir(a)
@@ -143,14 +143,14 @@ static const char _svn_version[] =
# include <unistd.h>
# define DEFAULT_PATH "/bin:/usr/bin:."
-static int exec_command(const char *file, char *const *argv, char *const *envp)
+static int exec_command(const char *file, char *const *av, char *const *envp)
{
char *path;
const char *searchpath, *esp;
size_t prefixlen, filelen, totallen;
if (strchr(file, '/')) /* Specific path */
- return envp ? execve(file, argv, envp) : execv(file, argv);
+ return envp ? execve(file, av, envp) : execv(file, av);
filelen = strlen(file);
path = NULL;
@@ -191,9 +191,9 @@ static int exec_command(const char *file, char *const *argv, char *const *envp)
path[totallen] = '\0';
if (envp) {
- execve(path, argv, envp);
+ execve(path, av, envp);
} else {
- execv(path, argv);
+ execv(path, av);
}
free(path);
path = NULL;
@@ -234,7 +234,7 @@ static int exec_command(const char *file, char *const *argv, char *const *envp)
# define INVALID_RET_UNKNOWN 148
# define INVALID_RET_INTR 149
-static int spawn_command(const char *file, char *const *argv, char *const *envp)
+static int spawn_command(const char *file, char *const *av, char *const *envp)
{
pid_t pid, wait_pid;
int status;
@@ -259,7 +259,7 @@ static int spawn_command(const char *file, char *const *argv, char *const *envp)
for (f = 0; f < 256; f++)
(void) fsync(f);
- if (exec_command(file, argv, envp)) {
+ if (exec_command(file, av, envp)) {
/* let's hope no-one uses these values */
switch (errno) {
case E2BIG:
@@ -1016,7 +1016,7 @@ static int os_execute(lua_State * L)
}
-void open_oslibext(lua_State * L, int safer_option)
+void open_oslibext(lua_State * L, int safer)
{
find_env(L);
@@ -1039,7 +1039,7 @@ void open_oslibext(lua_State * L, int safer_option)
lua_setfield(L, -2, "gettimeofday");
#endif
- if (!safer_option) {
+ if (!safer) {
lua_pushcfunction(L, os_setenv);
lua_setfield(L, -2, "setenv");
lua_pushcfunction(L, os_exec);
diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c
index 7ece70e857f..62895b909b4 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c
@@ -1,6 +1,6 @@
/* lpdflib.c
- Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
+ Copyright 2006-2011 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -18,12 +18,14 @@
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
static const char _svn_version[] =
- "$Id: lpdflib.c 3941 2010-11-01 23:31:27Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lpdflib.c $";
+ "$Id: lpdflib.c 4524 2012-12-20 15:38:02Z taco $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lpdflib.c $";
#include "ptexlib.h"
#include "lua/luatex-api.h"
+#define PDF_ENV "pdf_env"
+
static int luapdfprint(lua_State * L)
{
int n;
@@ -103,7 +105,7 @@ static int l_immediateobj(lua_State * L)
n = lua_gettop(L);
if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) {
first_arg++;
- lua_number2int(k, lua_tonumber(L, 1));
+ k=(int)lua_tonumber(L, 1);
check_obj_type(static_pdf, obj_type_obj, k);
if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0)
luaL_error(L, "pdf.immediateobj() object in use");
@@ -119,11 +121,11 @@ static int l_immediateobj(lua_State * L)
case 1:
if (!lua_isstring(L, first_arg))
luaL_error(L, "pdf.immediateobj() 1st argument must be string");
- pdf_begin_obj(static_pdf, k, 1);
+ pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS);
st1.s = lua_tolstring(L, first_arg, &st1.l);
pdf_out_block(static_pdf, st1.s, st1.l);
if (st1.s[st1.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
pdf_end_obj(static_pdf);
break;
case 2:
@@ -138,15 +140,16 @@ static int l_immediateobj(lua_State * L)
if (n == first_arg + 2)
luaL_error(L,
"pdf.immediateobj() 3rd argument forbidden in file mode");
- pdf_begin_obj(static_pdf, k, 1);
+ pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS);
buf.s = fread_to_buf(L, st2.s, &buf.l);
pdf_out_block(static_pdf, (const char *) buf.s, buf.l);
if (buf.s[buf.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
xfree(buf.s);
pdf_end_obj(static_pdf);
} else {
- pdf_begin_dict(static_pdf, k, 0); /* 0 = not an object stream candidate! */
+ pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* not an object stream candidate! */
+ pdf_begin_dict(static_pdf);
if (n == first_arg + 2) { /* write attr text */
if (!lua_isstring(L, first_arg + 2))
luaL_error(L,
@@ -154,8 +157,10 @@ static int l_immediateobj(lua_State * L)
st3.s = lua_tolstring(L, first_arg + 2, &st3.l);
pdf_out_block(static_pdf, st3.s, st3.l);
if (st3.s[st3.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
}
+ pdf_dict_add_streaminfo(static_pdf);
+ pdf_end_dict(static_pdf);
pdf_begin_stream(static_pdf);
if (st1.l == 6 && strncmp((const char *) st1.s, "stream", 6) == 0) {
pdf_out_block(static_pdf, st2.s, st2.l);
@@ -168,6 +173,7 @@ static int l_immediateobj(lua_State * L)
} else
luaL_error(L, "pdf.immediateobj() invalid argument");
pdf_end_stream(static_pdf);
+ pdf_end_obj(static_pdf);
}
break;
default:
@@ -178,7 +184,7 @@ static int l_immediateobj(lua_State * L)
}
/**********************************************************************/
-/* for LUA_ENVIRONINDEX table lookup (instead of repeated strcmp()) */
+/* for lookup within table in LUA_REGISTRYINDEX (instead of repeated strcmp()) */
typedef enum { P__ZERO,
P_CATALOG,
@@ -217,9 +223,9 @@ static const parm_struct pdf_parms[] = {
static int table_obj(lua_State * L)
{
- int k, type;
+ int k, type, obj_compression;
int compress_level = -1; /* unset */
- int os_level = 1; /* default: put non-stream objects into object streams */
+ int os_threshold = OBJSTM_ALWAYS; /* default: put non-stream objects into object streams */
int saved_compress_level = static_pdf->compress_level;
const_lstring attr, st;
lstring buf;
@@ -236,20 +242,22 @@ static int table_obj(lua_State * L)
luaL_error(L, "pdf.obj(): object \"type\" missing");
if (!lua_isstring(L, -1)) /* !vs t */
luaL_error(L, "pdf.obj(): object \"type\" must be string");
- lua_pushvalue(L, -1); /* vs vs t */
- lua_gettable(L, LUA_ENVIRONINDEX); /* i? vs t */
- if (!lua_isnumber(L, -1)) /* !i vs t */
+ lua_pushstring(L, PDF_ENV); /* s vs t */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t vs t */
+ lua_pushvalue(L, -2); /* vs t vs t */
+ lua_gettable(L, -2); /* i? t vs t */
+ if (!lua_isnumber(L, -1)) /* !i t vs t */
luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type",
- lua_tostring(L, -2));
- type = (int) lua_tointeger(L, -1); /* i vs t */
+ lua_tostring(L, -3));
+ type = (int) lua_tointeger(L, -1); /* i t vs t */
switch (type) {
case P_RAW:
case P_STREAM:
break;
default:
- luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", lua_tostring(L, -2)); /* i vs t */
+ luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", lua_tostring(L, -3)); /* i vs t */
}
- lua_pop(L, 2); /* t */
+ lua_pop(L, 3); /* t */
/* get optional "immediate" */
@@ -332,10 +340,14 @@ static int table_obj(lua_State * L)
"pdf.obj(): \"objcompression\" key not allowed for stream object");
if (!lua_isboolean(L, -1)) /* !b t */
luaL_error(L, "pdf.obj(): \"objcompression\" must be boolean");
- os_level = lua_toboolean(L, -1); /* 0 or 1 */
- /* 0: never compress; 1: depends then on \pdfobjcompresslevel */
+ obj_compression = lua_toboolean(L, -1); /* 0 or 1 */
+ /* OBJSTM_NEVER: never into object stream; OBJSTM_ALWAYS: depends then on \pdfobjcompresslevel */
+ if (obj_compression > 0)
+ os_threshold = OBJSTM_ALWAYS;
+ else
+ os_threshold = OBJSTM_NEVER;
if (immediate == 0)
- obj_obj_pdfoslevel(static_pdf, k) = os_level;
+ obj_obj_objstm_threshold(static_pdf, k) = os_threshold;
}
lua_pop(L, 1); /* t */
@@ -354,7 +366,7 @@ static int table_obj(lua_State * L)
switch (type) {
case P_RAW:
if (immediate == 1)
- pdf_begin_obj(static_pdf, k, os_level);
+ pdf_begin_obj(static_pdf, k, os_threshold);
if (!lua_isnil(L, -2)) { /* file-s? string-s? t */
/* from string */
lua_pop(L, 1); /* string-s? t */
@@ -365,7 +377,7 @@ static int table_obj(lua_State * L)
st.s = lua_tolstring(L, -1, &st.l);
pdf_out_block(static_pdf, st.s, st.l);
if (st.s[st.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
} else
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */
} else {
@@ -378,7 +390,7 @@ static int table_obj(lua_State * L)
buf.s = fread_to_buf(L, st.s, &buf.l);
pdf_out_block(static_pdf, (const char *) buf.s, buf.l);
if (buf.s[buf.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
xfree(buf.s);
} else {
set_obj_obj_is_file(static_pdf, k);
@@ -390,14 +402,17 @@ static int table_obj(lua_State * L)
break;
case P_STREAM:
if (immediate == 1) {
- pdf_begin_dict(static_pdf, k, 0); /* 0 = not an object stream candidate! */
+ pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* 0 = not an object stream candidate! */
+ pdf_begin_dict(static_pdf);
if (attr.s != NULL) {
pdf_out_block(static_pdf, attr.s, attr.l);
if (attr.s[attr.l - 1] != '\n')
- pdf_puts(static_pdf, "\n");
+ pdf_out(static_pdf, '\n');
}
if (compress_level > -1)
static_pdf->compress_level = compress_level;
+ pdf_dict_add_streaminfo(static_pdf);
+ pdf_end_dict(static_pdf);
pdf_begin_stream(static_pdf);
} else {
set_obj_obj_is_stream(static_pdf, k);
@@ -430,8 +445,10 @@ static int table_obj(lua_State * L)
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* nil t */
}
}
- if (immediate == 1)
+ if (immediate == 1) {
pdf_end_stream(static_pdf);
+ pdf_end_obj(static_pdf);
+ }
break;
default:
assert(0);
@@ -449,7 +466,7 @@ static int orig_obj(lua_State * L)
n = lua_gettop(L);
if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) {
first_arg++;
- lua_number2int(k, lua_tonumber(L, 1));
+ k=(int)lua_tonumber(L, 1);
check_obj_type(static_pdf, obj_type_obj, k);
if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0)
luaL_error(L, "pdf.obj() object in use");
@@ -585,11 +602,13 @@ static int getpdf(lua_State * L)
char *s;
int i, l;
if (lua_isstring(L, 2) && (lua_tostring(L, 2) != NULL)) {
- lua_pushvalue(L, 2); /* st ... */
- lua_gettable(L, LUA_ENVIRONINDEX); /* i? ... */
- if (lua_isnumber(L, -1)) { /* i ... */
- i = (int) lua_tointeger(L, -1); /* i ... */
- lua_pop(L, 1); /* ... */
+ lua_pushstring(L, PDF_ENV); /* s ... */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t ... */
+ lua_pushvalue(L, 2); /* st t ... */
+ lua_gettable(L, -2); /* i? t ... */
+ if (lua_isnumber(L, -1)) { /* i t ... */
+ i = (int) lua_tointeger(L, -1); /* i t ... */
+ lua_pop(L, 2); /* ... */
switch (i) {
case P_PDFCATALOG:
case P_CATALOG:
@@ -621,7 +640,7 @@ static int getpdf(lua_State * L)
lua_rawget(L, -2);
}
} else {
- lua_pop(L, 1); /* ... */
+ lua_pop(L, 2); /* ... */
lua_rawget(L, -2);
}
} else {
@@ -637,11 +656,13 @@ static int setpdf(lua_State * L)
return 0;
}
(void) luaL_checkstring(L, 2); /* ... */
- lua_pushvalue(L, 2); /* st ... */
- lua_gettable(L, LUA_ENVIRONINDEX); /* i? ... */
- if (lua_isnumber(L, -1)) { /* i ... */
- i = (int) lua_tointeger(L, -1); /* i ... */
- lua_pop(L, 1); /* ... */
+ lua_pushstring(L, PDF_ENV); /* s ... */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t ... */
+ lua_pushvalue(L, 2); /* st t ... */
+ lua_gettable(L, -2); /* i? t ... */
+ if (lua_isnumber(L, -1)) { /* i t ... */
+ i = (int) lua_tointeger(L, -1); /* i t ... */
+ lua_pop(L, 2); /* ... */
switch (i) {
case P_PDFCATALOG:
case P_CATALOG:
@@ -666,7 +687,7 @@ static int setpdf(lua_State * L)
lua_rawset(L, -3);
}
} else {
- lua_pop(L, 1); /* ... */
+ lua_pop(L, 2); /* ... */
lua_rawset(L, -3);
}
return 0;
@@ -738,12 +759,12 @@ static int l_pageref(lua_State * L)
n = (int) luaL_checkinteger(L, 1);
if (n <= 0)
luaL_error(L, "pdf.pageref() needs page number > 0");
- n = get_obj(static_pdf, obj_type_page, n, false);
+ n = pdf_get_obj(static_pdf, obj_type_page, n, false);
lua_pushnumber(L, n);
return 1;
}
-static const struct luaL_reg pdflib[] = {
+static const struct luaL_Reg pdflib[] = {
{"immediateobj", l_immediateobj},
{"mapfile", l_mapfile},
{"mapline", l_mapline},
@@ -764,7 +785,7 @@ static const struct luaL_reg pdflib[] = {
int luaopen_pdf(lua_State * L)
{
- preset_environment(L, pdf_parms);
+ preset_environment(L, pdf_parms, PDF_ENV);
luaL_register(L, "pdf", pdflib);
/* build meta table */
luaL_newmetatable(L, "pdf_meta");
diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc b/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc
new file mode 100644
index 00000000000..2b36d106234
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc
@@ -0,0 +1,952 @@
+/* lcallbacklib.c
+
+ Copyright 2012 Taco Hoekwater <taco@luatex.org>
+
+ This file is part of LuaTeX.
+
+ LuaTeX is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ LuaTeX is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+# include <stdlib.h>
+# include <stdio.h>
+# include <stdarg.h>
+# include <string.h>
+# include <assert.h>
+# include <math.h>
+
+extern "C" {
+# include <lua52/lua.h>
+# include <lua52/lauxlib.h>
+# include <lua52/lualib.h>
+}
+
+# include <poppler/poppler-config.h>
+# include <goo/GooString.h>
+# include <goo/gmem.h>
+# include <goo/gfile.h>
+# include <Object.h>
+# include <Stream.h>
+# include <Gfx.h>
+# include <Annot.h>
+# include <Array.h>
+# include <Dict.h>
+# include <XRef.h>
+# include <Catalog.h>
+# include <Link.h>
+# include <Page.h>
+# include <GfxFont.h>
+# include <PDFDoc.h>
+# include <GlobalParams.h>
+# include <Error.h>
+
+# include <lua/luatex-api.h>
+
+static const char _svn_version[] =
+ "$Id: lpdfscannerlib.cc 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc $";
+
+#define SCANNER "pdfscanner"
+
+#define MAXOPERANDS 1000
+
+typedef enum {
+ pdf_integer = 1,
+ pdf_real,
+ pdf_boolean,
+ pdf_name,
+ pdf_operator,
+ pdf_string,
+ pdf_startarray,
+ pdf_stoparray,
+ pdf_startdict,
+ pdf_stopdict,
+} pdf_token_type ;
+
+
+typedef struct Token {
+ pdf_token_type type;
+ double value;
+ const char *string;
+} Token;
+
+typedef struct ObjectList {
+ struct ObjectList *next;
+ Object *stream;
+} ObjectList;
+
+typedef struct scannerdata {
+ int _ininlineimage;
+ int _nextoperand;
+ Token ** _operandstack;
+ Object * _stream;
+ ObjectList * _streams;
+} scannerdata;
+
+typedef enum { ALLOC_POPPLER, ALLOC_LEPDF } alloctype;
+
+#define M_Object "Object"
+#define M_Stream "Stream"
+
+typedef struct {
+ void *d;
+ alloctype atype; // was it allocated by poppler or the lepdflib.cc?
+ void *pd; // reference to PdfDocument, or NULL
+ unsigned long pc; // counter to detect PDFDoc change
+} udstruct;
+
+static void clear_operand_stack (scannerdata *self, int from);
+static Token *_parseToken (scannerdata *self, int c);
+static void push_token (lua_State *L, scannerdata *self);
+
+void *xmalloc (size_t size)
+{
+ void *new_mem = (void *)malloc(size);
+ if (new_mem == NULL) {
+ fprintf(stderr, "fatal: memory exhausted (xmalloc of %lu bytes).\n", (unsigned long)size);
+ exit(1);
+ }
+ return new_mem;
+}
+
+void *xrealloc (void *old_ptr, size_t size)
+{
+ void *new_mem = (void *)realloc(old_ptr, size);
+ if (new_mem == NULL) {
+ fprintf(stderr,"fatal: memory exhausted (realloc of %lu bytes).\n", (unsigned long)size);
+ exit(EXIT_FAILURE);
+ }
+ return new_mem;
+}
+
+#define xreallocarray(ptr,type,size) ((type*)xrealloc(ptr,(size+1)*sizeof(type)))
+
+#define INITBUFSIZE 64
+
+#define define_buffer(a) \
+ char *a = (char *)xmalloc (INITBUFSIZE); \
+ int a##_size = INITBUFSIZE; \
+ int a##index = 0; \
+ memset (a,0,INITBUFSIZE)
+
+#define check_overflow(a, wsize) do { \
+ if (wsize >= a##_size) { \
+ int nsize = a##_size + a##_size / 4; \
+ a = (char *) xreallocarray(a, char, (unsigned) nsize); \
+ memset (a+a##_size, 0, a##_size / 4); \
+ a##_size = nsize; \
+ } \
+ } while (0)
+
+
+static scannerdata * scanner_push(lua_State * L)
+{
+ scannerdata *a = (scannerdata *)lua_newuserdata(L, sizeof(scannerdata));
+ luaL_getmetatable(L, SCANNER);
+ lua_setmetatable(L, -2);
+ return a;
+}
+
+static scannerdata *scanner_check (lua_State *L, int index)
+{
+ scannerdata *bar;
+ luaL_checktype(L, index, LUA_TUSERDATA);
+ bar = (scannerdata *)luaL_checkudata(L, index, SCANNER);
+ return bar;
+}
+
+static void free_token (Token *token)
+{
+ if (token->string) {
+ free((void *)token->string);
+ }
+ free(token);
+}
+
+static void clear_operand_stack (scannerdata *self, int from)
+{
+ int i = self->_nextoperand-1;
+ while (i>=from) {
+ if (self->_operandstack[i]) {
+ free_token(self->_operandstack[i]);
+ self->_operandstack[i] = NULL;
+ }
+ i--;
+ }
+ self->_nextoperand = from;
+}
+
+static void push_operand (scannerdata *self, Token *token)
+{
+ if (self->_nextoperand+1> MAXOPERANDS) {
+ fprintf(stderr, "out of operand stack space");
+ exit(1);
+ }
+ self->_operandstack[self->_nextoperand++] = token;
+}
+
+static Token * new_operand (pdf_token_type c)
+{
+ Token *token = (Token *)xmalloc(sizeof(Token));
+ memset (token, 0, sizeof(Token));
+ token->type = c;
+ return token;
+}
+
+static void _nextStream (scannerdata *self) {
+ self->_stream->streamClose();
+ ObjectList *rover = self->_streams;
+ self->_stream = rover->stream;
+ self->_stream->streamReset();
+ self->_streams = rover->next;
+ free(rover);
+}
+
+static int streamGetChar (scannerdata *self) {
+ int i = self->_stream->streamGetChar();
+ if (i<0 && self->_streams) {
+ _nextStream(self);
+ i = streamGetChar(self);
+ }
+ return i;
+}
+
+static int streamLookChar (scannerdata *self) {
+ int i= self->_stream->streamLookChar();
+ if (i<0 && self->_streams) {
+ _nextStream(self);
+ i = streamLookChar(self);
+ }
+ return i;
+}
+
+static Token * _parseSpace (scannerdata *self)
+{
+ return _parseToken (self,streamGetChar(self));
+}
+
+static Token * _parseString (scannerdata *self, int c)
+{
+ // local token = {type = pdf_string,value = ''}
+ define_buffer(found);
+ int level = 1;
+ while (1) {
+ c = streamGetChar(self);
+ if (c == '(') {
+ level = level + 1 ;
+ }
+ if (c == ')') {
+ level = level - 1 ;
+ if (level < 1) break;
+ }
+ if (c == '\\') {
+ int next = streamGetChar(self);
+ if (next == '(' || next == ')' || next == '\\') {
+ c = next;
+ } else if (next == '\n' || next == '\r') {
+ c = '\0';
+ } else if (next == 'n') {
+ c = '\n';
+ } else if (next == 'r') {
+ c = '\r';
+ } else if (next == 't') {
+ c = '\t';
+ } else if (next == 'b') {
+ c = '\b';
+ } else if (next == 'f') {
+ c = '\f';
+ } else if (next >= '0' && next <= '7') {
+ next = next - '0';
+ int next2 = streamLookChar(self);
+ if (next2 >= '0' && next2 <= '7') {
+ next2 = streamGetChar(self);
+ next2 = next2 - '0';
+ int next3 = streamLookChar(self);
+ if (next3 >= '0' && next3 <= '7') {
+ next3 = streamGetChar(self);
+ next3 = next3 - '0';
+ c = (next*64+next2*8+next3);
+ } else {
+ c = (next*8+next2);
+ }
+ } else {
+ c = next;
+ }
+ } else {
+ c = next;
+ }
+ }
+ check_overflow(found,foundindex);
+ if (c>=0) {
+ found[foundindex++] = c;
+ }
+ }
+ Token *token = new_operand(pdf_string);
+ token->value = foundindex;
+ token->string = found;
+ return token;
+}
+
+
+static Token * _parseNumber (scannerdata *self, int c)
+{
+ double value = 0;
+ pdf_token_type type = pdf_integer;
+ int isfraction = 0;
+ int isnegative = 0;
+ int i = 0;
+ if (c == '-') {
+ isnegative = 1;
+ c = streamGetChar(self);
+ }
+ if (c == '.') {
+ type = pdf_real;
+ isfraction = 1;
+ } else {
+ value = c - '0';
+ }
+ c = streamLookChar(self);
+ if ((c>= '0'&& c<= '9') || c == '.') {
+ c = streamGetChar(self);
+ while (1) {
+ if (c == '.') {
+ type = pdf_real;
+ isfraction = 1;
+ } else {
+ i = c - '0';
+ if (isfraction>0) {
+ value = value + (i/(pow(10.0,isfraction)));
+ isfraction = isfraction + 1;
+ } else {
+ value = (value * 10) + i;
+ }
+ }
+ c = streamLookChar(self);
+ if (! ((c>= '0' && c<= '9') || c == '.')) break ;
+ c = streamGetChar(self);
+ }
+ }
+ if (isnegative) {
+ value = -value;
+ }
+ Token *token = new_operand(type);
+ token->value = value;
+ return token;
+}
+
+
+static Token *_parseName (scannerdata *self, int c)
+{
+ define_buffer(found);
+ c = streamGetChar(self);
+ while (1) {
+ check_overflow(found,foundindex);
+ found[foundindex++] = c;
+ c = streamLookChar(self);
+ if (c == ' ' || c == '\n' || c == '\r' || c == '\t' ||
+ c == '/' || c == '[' || c == '(' || c == '<') break ;
+ c = streamGetChar(self);
+ }
+ Token *token = new_operand(pdf_name);
+ token->string = found;
+ token->value = strlen(found);
+ return token;
+}
+
+#define hexdigit(c) \
+ (c>= '0' && c<= '9') ? (c - '0') : ((c>= 'A' && c<= 'F') ? (c - 'A' + 10) : (c - 'a' + 10))
+
+static Token *_parseHexstring (scannerdata *self, int c)
+{
+ int isodd = 1;
+ int hexval = 0;
+ define_buffer(found);
+ while (1) {
+ if ((c>= '0' && c<= '9') ||
+ (c>= 'A' && c<= 'F') ||
+ (c>= 'a' && c<= 'f')) {
+ if (isodd==1) {
+ int v = hexdigit(c);
+ hexval = 16 * v;
+ } else {
+ hexval += hexdigit(c);
+ check_overflow(found,foundindex);
+ found[foundindex++] = hexval;
+ }
+ isodd = (isodd==1 ? 0 : 1);
+ }
+ c = streamGetChar(self);
+ if (c == '>') break;
+ }
+ Token *token = new_operand(pdf_string);
+ token->value = foundindex;
+ token->string = found;
+ return token;
+}
+
+
+// -- this is rather horrible
+static Token *_parseInlineImage (scannerdata *self, int c)
+{
+ define_buffer(found);
+ if (c == ' ') { // first space can be ignored
+ c = streamGetChar(self);
+ }
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ while (1) {
+ c = streamLookChar(self);
+ while (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
+ c = streamGetChar(self);
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ c = streamLookChar(self);
+ }
+ if (c == 'E') {
+ c = streamGetChar(self);
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ c = streamLookChar(self);
+ if (c == 'I') {
+ c = streamGetChar(self);
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ c = streamLookChar(self);
+ if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
+ found[--foundindex] = '\0';
+ found[--foundindex] = '\0';
+ /* remove optional end-of-line */
+ if (found[foundindex-1] == '\n') {
+ found[--foundindex] = '\0';
+ }
+ if (found[foundindex-1] == '\r') {
+ found[--foundindex] = '\0';
+ }
+ break;
+ }
+ } else {
+ c = streamGetChar(self);
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ }
+ } else {
+ c = streamGetChar(self);
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ }
+ }
+ Token *token = new_operand(pdf_string);
+ token->value = foundindex;
+ token->string = found;
+ return token;
+}
+
+static Token *_parseOperator (scannerdata *self, int c)
+{
+ define_buffer(found);
+ while (1) {
+ check_overflow(found, foundindex);
+ found[foundindex++] = c;
+ c = streamLookChar(self);
+ if ((c<0) || (c == ' ' || c == '\n' || c == '\r' || c == '\t' ||
+ c == '/' || c == '[' || c == '(' || c == '<'))
+ break ;
+ c = streamGetChar(self);
+ }
+ // print (found)
+ if (strcmp(found, "ID") == 0) {
+ self->_ininlineimage = 1;
+ }
+ if (strcmp(found,"false") == 0) {
+ Token *token = new_operand(pdf_boolean);
+ token->value = 0;
+ return token;
+ } else if (strcmp(found,"true") == 0) {
+ Token *token = new_operand(pdf_boolean);
+ token->value = 1.0;
+ return token;
+ } else {
+ Token *token = new_operand(pdf_operator);
+ token->string = found;
+ return token;
+ }
+}
+
+
+static Token * _parseComment (scannerdata *self, int c)
+{
+ do {
+ c = streamGetChar(self);
+ } while (c != '\n' && c != '\r');
+ return _parseToken(self,streamGetChar(self));
+}
+
+static Token *_parseLt (scannerdata *self, int c)
+{
+ c = streamGetChar(self);
+ if (c == '<') {
+ return new_operand(pdf_startdict);
+ } else {
+ return _parseHexstring(self,c);
+ }
+}
+
+static Token * _parseGt (scannerdata *self, int c)
+{
+ c = streamGetChar(self);
+ if (c== '>') {
+ return new_operand(pdf_stopdict);
+ } else {
+ fprintf(stderr,"stray > in stream");
+ return NULL;
+ }
+}
+
+
+static Token *_parseError (int c)
+{
+ fprintf(stderr, "stray %c [%d] in stream", c, c);
+ return NULL;
+}
+
+static Token *_parseStartarray ()
+{
+ return new_operand (pdf_startarray);
+}
+
+static Token *_parseStoparray ()
+{
+ return new_operand (pdf_stoparray);
+}
+
+
+static Token *_parseToken (scannerdata *self, int c)
+{
+ if (self->_ininlineimage==1) {
+ self->_ininlineimage = 2;
+ return _parseInlineImage(self,c);
+ } else if (self->_ininlineimage==2) {
+ self->_ininlineimage = 0;
+ Token *token = new_operand(pdf_operator);
+ token->string = strdup("EI");
+ return token;
+ }
+ if (c<0) return NULL ;
+ switch (c) {
+ case '(': return _parseString(self,c); break;
+ case ')': return _parseError(c); break;
+ case '[': return _parseStartarray(); break;
+ case ']': return _parseStoparray(); break;
+ case '/': return _parseName(self,c); break;
+ case '<': return _parseLt(self,c); break;
+ case '>': return _parseGt(self,c); break;
+ case '%': return _parseComment(self,c); break;
+ case ' ':
+ case '\r':
+ case '\n':
+ case '\t':
+ return _parseSpace(self); break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case '-':
+ case '.':
+ return _parseNumber(self,c); break;
+ default:
+ if (c<=127) {
+ return _parseOperator(self,c);
+ } else {
+ return _parseError(c);
+ }
+ }
+}
+
+static int scanner_scan(lua_State * L)
+{
+ Token *token;
+ scannerdata *self;
+ if (lua_gettop(L) != 3) {
+ return 0;
+ }
+ luaL_checktype(L, 2, LUA_TTABLE);
+ luaL_checktype(L, 3, LUA_TTABLE);
+ self = scanner_push(L);
+ memset(self,0,sizeof(scannerdata));
+ self->_operandstack = (Token **)xmalloc (MAXOPERANDS * sizeof (Token));
+ memset (self->_operandstack,0,(MAXOPERANDS * sizeof (Token)));
+ // 4 = self
+ if (lua_type(L,1)== LUA_TTABLE) {
+ udstruct *uin;
+ int i = 1;
+ while (1) {
+ lua_rawgeti(L,1,i);
+ if (lua_type(L,-1)== LUA_TUSERDATA) {
+ uin = (udstruct *) luaL_checkudata(L, -1, M_Object);
+ if (((Object *) uin->d)->isStream()) {
+ ObjectList *rover = self->_streams;
+ ObjectList *item = (ObjectList *)xmalloc (sizeof(ObjectList));
+ item->stream = ((Object *) uin->d);
+ item->next = NULL;
+ if (!rover) {
+ rover = item;
+ self->_streams = rover;
+ } else {
+ while (rover->next)
+ rover = rover->next;
+ rover->next = item;
+ }
+ }
+ } else { // done
+ ObjectList *rover = self->_streams;
+ self->_stream = rover->stream;
+ self->_streams = rover->next;
+ free(rover);
+ lua_pop(L,1);
+ break;
+ }
+ lua_pop(L,1);
+ i++;
+ }
+
+ } else {
+ udstruct *uin;
+ luaL_checktype(L, 1, LUA_TUSERDATA);
+ uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
+ if (((Object *) uin->d)->isStream()) {
+ self->_stream = ((Object *) uin->d);
+ } else if (((Object *) uin->d)->isArray()) {
+ Array *arrayref = ((Object *) uin->d)->getArray();
+ int count = arrayref->getLength();
+ int i;
+ for (i=0;i<count;i++) {
+ Object *val = new Object();
+ arrayref->get(i, val);
+ if (val->isStream()) {
+ ObjectList *rover = self->_streams;
+ ObjectList *item = (ObjectList *)xmalloc (sizeof(ObjectList));
+ item->stream = val;
+ item->next = NULL;
+ if (!rover) {
+ rover = item;
+ self->_streams = rover;
+ } else {
+ while (rover->next)
+ rover = rover->next;
+ rover->next = item;
+ }
+ }
+ }
+ ObjectList *rover = self->_streams;
+ self->_stream = rover->stream;
+ self->_streams = rover->next;
+ }
+
+ }
+ assert (lua_gettop(L) == 4);
+ self->_stream->streamReset();
+ token = _parseToken(self,streamGetChar(self));
+ while (token) {
+ if (token->type == pdf_operator) {
+ lua_pushstring(L, token->string);
+ free_token(token);
+ lua_rawget(L,2); // operator table
+ if (lua_isfunction(L,-1)) {
+ lua_pushvalue(L,4);
+ lua_pushvalue(L,3);
+ (void)lua_call(L,2,0);
+ } else {
+ lua_pop(L,1); // nil
+ }
+ clear_operand_stack(self,0);
+ } else {
+ push_operand(self, token);
+ }
+ if (!self->_stream) {
+ break;
+ }
+ token = _parseToken(self,streamGetChar(self));
+ }
+ /* wrap up */
+ if (self->_stream) {
+ self->_stream->streamClose();
+ self->_stream = NULL;
+ }
+ clear_operand_stack(self,0);
+ free(self->_operandstack);
+ return 0;
+}
+
+static int scanner_done(lua_State * L)
+{
+ int c;
+ scannerdata *self = scanner_check(L,1);
+ while ((c=streamGetChar(self))>=0)
+ ;
+ return 0;
+}
+
+// here are the stack popping functions, and their helpers
+
+static void operandstack_backup (scannerdata *self) {
+ int i = self->_nextoperand-1;
+ int balance = 0;
+ int backupstart = 0;
+ int backupstop = self->_operandstack[i]->type;
+ if (backupstop == pdf_stopdict) {
+ backupstart = pdf_startdict;
+ } else if (backupstop == pdf_stoparray) {
+ backupstart = pdf_startarray;
+ } else {
+ return;
+ }
+ for (;i>=0;i--) {
+ if (self->_operandstack[i]->type == backupstop) {
+ balance++;
+ } else if (self->_operandstack[i]->type == backupstart) {
+ balance--;
+ }
+ if (balance==0) {
+ break;
+ }
+ }
+ self->_nextoperand = i+1;
+}
+
+static void push_array (lua_State *L, scannerdata *self)
+{
+ int balance = 1; // nesting tracking
+ int index = 1; // lua array index
+ Token *token = self->_operandstack[self->_nextoperand++];
+ lua_newtable(L);
+ while (token) {
+ if (token->type == pdf_stoparray)
+ balance --;
+ if (token->type == pdf_startarray)
+ balance ++;
+ if (!balance) {
+ break;
+ } else {
+ push_token(L,self);
+ lua_rawseti(L,-2, index++);
+ }
+ token = self->_operandstack[self->_nextoperand++];
+ }
+}
+
+
+static void push_dict (lua_State *L, scannerdata *self)
+{
+ int balance = 1; // nesting tracking
+ int needskey = 1; // toggle between lua value and lua key
+ Token *token = self->_operandstack[self->_nextoperand++];
+ lua_newtable(L);
+ while (token) {
+ if (token->type == pdf_stopdict)
+ balance --;
+ if (token->type == pdf_startdict)
+ balance ++;
+ if (!balance) {
+ break;
+ } else {
+ if (needskey) {
+ lua_pushlstring(L, token->string, token->value);
+ needskey = 0;
+ } else {
+ push_token(L,self);
+ needskey = 1;
+ lua_rawset(L,-3);
+ }
+ }
+ token = self->_operandstack[self->_nextoperand++];
+ }
+}
+
+const char *typenames[pdf_stopdict+1] =
+ { "unknown", "integer", "real", "boolean", "name", "operator",
+ "string", "array", "array", "dict", "dict" };
+
+static void push_token (lua_State *L, scannerdata *self)
+{
+ Token *token = self->_operandstack[self->_nextoperand-1];
+ lua_createtable(L,2,0);
+ lua_pushstring (L, typenames[token->type]);
+ lua_rawseti(L,-2,1);
+ if (token->type == pdf_string || token->type == pdf_name) {
+ lua_pushlstring(L, token->string, token->value);
+ } else if (token->type == pdf_real || token->type == pdf_integer) {
+ lua_pushnumber(L, token->value);
+ } else if (token->type == pdf_boolean) {
+ lua_pushboolean(L, (int)token->value);
+ } else if (token->type == pdf_startarray) {
+ push_array(L, self);
+ } else if (token->type == pdf_startdict) {
+ push_dict(L, self);
+ } else {
+ lua_pushnil(L);
+ }
+ lua_rawseti(L,-2, 2);
+}
+
+static int scanner_popsingular (lua_State * L, int token_type) {
+ int clear = 0; // how much of the operand stack needs deleting
+ scannerdata *self = scanner_check(L,1);
+ if (self->_nextoperand==0) {
+ return 0;
+ }
+ clear = self->_nextoperand-1;
+ Token *token = self->_operandstack[self->_nextoperand-1];
+ if (token ==NULL || (token->type != token_type )) {
+ return 0;
+ }
+ // the simple cases can be written out directly, but dicts and
+ // arrays are better done via the recursive function
+ if (token_type == pdf_stoparray || token_type == pdf_stopdict) {
+ operandstack_backup(self);
+ clear = self->_nextoperand-1;
+ push_token(L, self);
+ lua_rawgeti(L,-1,2);
+ } else if (token_type == pdf_real || token_type == pdf_integer) {
+ lua_pushnumber(L, token->value);
+ } else if (token_type == pdf_boolean) {
+ lua_pushboolean(L,(int)token->value);
+ } else if (token_type == pdf_name || token_type == pdf_string) {
+ lua_pushlstring(L, token->string, token->value);
+ } else {
+ return 0;
+ }
+ clear_operand_stack(self,clear);
+ return 1;
+}
+
+static int scanner_popanything (lua_State * L) {
+ int clear = 0; // how much of the operand stack needs deleting
+ scannerdata *self = scanner_check(L,1);
+ if (self->_nextoperand==0) {
+ return 0;
+ }
+ clear = self->_nextoperand-1;
+ Token *token = self->_operandstack[self->_nextoperand-1];
+ if (token ==NULL) {
+ return 0;
+ }
+ int token_type = token->type;
+ // the simple cases can be written out directly, but dicts and
+ // arrays are better done via the recursive function
+ if (token_type == pdf_stoparray || token_type == pdf_stopdict) {
+ operandstack_backup(self);
+ clear = self->_nextoperand-1;
+ push_token(L, self);
+ } else {
+ push_token(L, self);
+ }
+ clear_operand_stack(self,clear);
+ return 1;
+}
+
+
+static int scanner_popnumber(lua_State * L)
+{
+ if(scanner_popsingular(L,pdf_real))
+ return 1;
+ if (scanner_popsingular(L,pdf_integer))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_popboolean(lua_State * L)
+{
+ if(scanner_popsingular(L,pdf_boolean))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_popstring(lua_State * L)
+{
+ if (scanner_popsingular(L,pdf_string))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_popname(lua_State * L)
+{
+ if (scanner_popsingular(L,pdf_name))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_poparray(lua_State * L)
+{
+ if (scanner_popsingular(L,pdf_stoparray))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_popdictionary(lua_State * L)
+{
+ if (scanner_popsingular(L,pdf_stopdict))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static int scanner_popany(lua_State * L)
+{
+ if (scanner_popanything(L))
+ return 1;
+ lua_pushnil(L);
+ return 1;
+}
+
+static const luaL_Reg scannerlib_meta[] = {
+ {0, 0}
+};
+
+static const struct luaL_Reg scannerlib_m[] = {
+ {"done", scanner_done},
+ {"popNumber", scanner_popnumber},
+ {"popName", scanner_popname},
+ {"popString", scanner_popstring},
+ {"popArray", scanner_poparray},
+ {"popDict", scanner_popdictionary},
+ {"popBool", scanner_popboolean},
+ {"pop", scanner_popany},
+ {NULL, NULL} /* sentinel */
+};
+
+
+static const luaL_Reg scannerlib[] = {
+ {"scan", scanner_scan},
+ {NULL, NULL}
+};
+
+LUALIB_API int luaopen_pdfscanner(lua_State * L)
+{
+ luaL_newmetatable(L, SCANNER);
+ luaL_openlib(L, 0, scannerlib_meta, 0);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "__index");
+ luaL_register(L, NULL, scannerlib_m);
+ luaL_register(L, "pdfscanner", scannerlib);
+ return 1;
+}
+
diff --git a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c
index 07d5c1be1ed..cb881b94879 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c
@@ -1,6 +1,6 @@
/* lstatslib.c
-
- Copyright 2006-2009 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 2006-2011 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -18,8 +18,8 @@
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
static const char _svn_version[] =
- "$Id: lstatslib.c 3477 2010-03-12 13:59:34Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lstatslib.c $";
+ "$Id: lstatslib.c 4524 2012-12-20 15:38:02Z taco $ "
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lstatslib.c $";
#include "ptexlib.h"
#include "lua/luatex-api.h"
@@ -88,21 +88,21 @@ static lua_Number get_pdf_gone(void)
static lua_Number get_pdf_ptr(void)
{
if (static_pdf != NULL)
- return (lua_Number) static_pdf->ptr;
+ return (lua_Number) (static_pdf->buf->p - static_pdf->buf->data);
return (lua_Number) 0;
}
static lua_Number get_pdf_os_cntr(void)
{
if (static_pdf != NULL)
- return (lua_Number) static_pdf->os_cntr;
+ return (lua_Number) static_pdf->os->ostm_ctr;
return (lua_Number) 0;
}
static lua_Number get_pdf_os_objidx(void)
{
if (static_pdf != NULL)
- return (lua_Number) static_pdf->os_idx;
+ return (lua_Number) static_pdf->os->idx;
return (lua_Number) 0;
}
@@ -174,12 +174,12 @@ static struct statistic stats[] = {
{"luatex_revision", 'S', (void *) &luatexrevision},
{"ini_version", 'b', &ini_version},
/*
- * mem stat
+ * mem stat
*/
{"var_used", 'g', &var_used},
{"dyn_used", 'g', &dyn_used},
- /*
- * traditional tex stats
+ /*
+ * traditional tex stats
*/
{"str_ptr", 'g', &str_ptr},
{"init_str_ptr", 'g', &init_str_ptr},
@@ -336,7 +336,7 @@ static int statslist(lua_State * L)
-static const struct luaL_reg statslib[] = {
+static const struct luaL_Reg statslib[] = {
{"list", statslist},
{NULL, NULL} /* sentinel */
};
diff --git a/Build/source/texk/web2c/luatexdir/lua/lstrlibext.c b/Build/source/texk/web2c/luatexdir/lua/lstrlibext.c
new file mode 100644
index 00000000000..860f251ebd5
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/lua/lstrlibext.c
@@ -0,0 +1,379 @@
+/* lstrlibext.c
+
+ Copyright 2012 Taco Hoekwater <taco@luatex.org>
+
+ This file is part of LuaTeX.
+
+ LuaTeX is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ LuaTeX is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
+
+/* The relative ordering of the header files is important here,
+ otherwise some of the defines that are needed for lua_sdump
+ come out wrong.
+ */
+#define LUA_CORE
+#include "lua.h"
+#include "lua52/luaconf.h"
+#include "lua52/lapi.h"
+#include "lua52/lundump.h"
+
+#include "ptexlib.h"
+
+static const char _svn_version[] =
+ "$Id: lstrlibext.c 4544 2012-12-25 14:07:44Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lstrlibext.c $";
+
+static int str_split (lua_State *L) {
+ size_t l;
+ size_t i;
+ int n;
+ char *q, *p, *orig;
+ int mult = 0;
+ const char *s = luaL_checklstring(L, 1, &l);
+ const char *joiner = luaL_optstring(L, 2, " +");
+ lua_newtable(L);
+ if (l == 0) {
+ lua_pushvalue(L,1);
+ lua_rawseti(L,-2,1);
+ return 1;
+ }
+ orig = p = malloc(l+1);
+ if (p==NULL) {
+ fprintf(stderr, "fatal: memory exhausted (malloc of %u bytes).\n",(int)(l+1));
+ exit(EXIT_FAILURE);
+ }
+ strcpy(p,s);
+ n = 1;
+ q = p;
+
+ if (*joiner == 0) {
+ for (i=0;i<l;i++) {
+ lua_pushlstring(L,q,1); q++;
+ lua_rawseti(L,-2,n); n++;
+ }
+ free(orig);
+ return 1;
+ }
+ if (*(joiner+1) == '+') {
+ mult = 1;
+ while(*p==*joiner) {
+ p++;
+ l--;
+ }
+ q = p;
+ }
+ for (i=0;i<l;i++) {
+ if (*(p+i)==*joiner) {
+ *(p+i) = 0;
+ lua_pushlstring(L,q,((p+i)-q));
+ lua_rawseti(L,-2,n); n++;
+ if (mult) {
+ while(*(p+i+1)==*joiner) {
+ i++;
+ }
+ }
+ q = p+i+1;
+ }
+ }
+ if (mult && q==(p+l)) {
+ free(orig);
+ return 1;
+ }
+ if(q<=(p+l)) {
+ lua_pushlstring(L,q,strlen(q));
+ lua_rawseti(L,-2,n);
+ }
+ free(orig);
+ return 1;
+}
+
+static int characters_aux (lua_State *L) {
+ size_t ls;
+ char b[2];
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+ if (ind<(int)ls) {
+ lua_pushinteger(L, (ind+1)); /* iterator */
+ lua_replace(L, lua_upvalueindex(2));
+ b[0] = *(s+ind); b[1] = 0;
+ lua_pushlstring(L, b, 1);
+ return 1;
+ }
+ return 0; /* string ended */
+}
+
+
+static int str_characters (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, characters_aux, 2);
+ return 1;
+}
+
+
+static int utf_failed(lua_State *L, int new_ind) {
+ static char fffd [3] = {0xEF,0xBF,0xBD};
+ lua_pushinteger(L, new_ind); /* iterator */
+ lua_replace(L, lua_upvalueindex(2));
+ lua_pushlstring(L, fffd, 3);
+ return 1;
+}
+
+static int utfcharacters_aux (lua_State *L) {
+ static const unsigned char mask[4] = {0x80,0xE0,0xF0,0xF8};
+ static const unsigned char mequ[4] = {0x00,0xC0,0xE0,0xF0};
+ size_t ls;
+ unsigned char c;
+ int j;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+ if (ind>=(int)ls) return 0; /* end of string */
+ c = (unsigned) s[ind];
+ for (j=0;j<4;j++) {
+ if ((c&mask[j])==mequ[j]) {
+ int k;
+ if (ind+1+j>(int)ls) return utf_failed(L,ls); /* will not fit */
+ for (k=1; k<=j; k++) {
+ c = (unsigned) s[ind+k];
+ if ((c&0xC0)!=0x80) return utf_failed(L,ind+k); /* bad follow */
+ }
+ lua_pushinteger(L, ind+1+j); /* iterator */
+ lua_replace(L, lua_upvalueindex(2));
+ lua_pushlstring(L, s+ind, 1+j);
+ return 1;
+ }
+ }
+ return utf_failed(L,ind+1); /* we found a follow byte! */
+}
+
+
+static int str_utfcharacters (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, utfcharacters_aux, 2);
+ return 1;
+}
+
+
+static int utfvalues_aux (lua_State *L) {
+ size_t ls;
+ unsigned char i = 0;
+ unsigned char j = 0;
+ unsigned char k = 0;
+ unsigned char l = 0;
+ unsigned int v = 0xFFFD;
+ int numbytes = 1;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+
+ if (ind<(int)ls) {
+ i = *(s+ind);
+ if (i<0x80) {
+ v = i;
+ } else if (i>=0xF0) {
+ if ((ind+3)<(int)ls && ((unsigned)*(s+ind+1))>=0x80
+ && ((unsigned)*(s+ind+2))>=0x80 && ((unsigned)*(s+ind+3))>=0x80) {
+ numbytes = 4;
+ j = ((unsigned)*(s+ind+1))-128;
+ k = ((unsigned)*(s+ind+2))-128;
+ l = ((unsigned)*(s+ind+3))-128;
+ v = (((((i-0xF0)*64) + j)*64) + k)*64 + l;
+ }
+ } else if (i>=0xE0) {
+ if ((ind+2)<(int)ls && ((unsigned)*(s+ind+1))>=0x80 && ((unsigned)*(s+ind+2))>=0x80) {
+ numbytes = 3;
+ j = ((unsigned)*(s+ind+1))-128;
+ k = ((unsigned)*(s+ind+2))-128;
+ v = (((i-0xE0)*64) + j)*64 + k;
+ }
+
+ } else if (i>=0xC0) {
+ if ((ind+1)<(int)ls && ((unsigned)*(s+ind+1))>=0x80) {
+ numbytes = 2;
+ j = ((unsigned)*(s+ind+1))-128;
+ v = ((i-0xC0)*64) + j;
+ }
+ }
+ lua_pushinteger(L, (ind+numbytes)); /* iterator */
+ lua_replace(L, lua_upvalueindex(2));
+ lua_pushinteger(L, v);
+ return 1;
+ }
+ return 0; /* string ended */
+}
+
+
+static int str_utfvalues (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, utfvalues_aux, 2);
+ return 1;
+}
+
+
+
+static int characterpairs_aux (lua_State *L) {
+ size_t ls;
+ char b[2];
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+ if (ind<(int)ls) {
+ if (ind+1<(int)ls) {
+ lua_pushinteger(L, (ind+2)); /* iterator */
+ } else {
+ lua_pushinteger(L, (ind+1)); /* iterator */
+ }
+ lua_replace(L, lua_upvalueindex(2));
+ b[0] = *(s+ind); b[1] = 0;
+ lua_pushlstring(L, b, 1);
+ if (ind+1<(int)ls) {
+ b[0] = *(s+ind+1);
+ lua_pushlstring(L, b, 1);
+ } else {
+ lua_pushlstring(L, b+1, 0);
+ }
+ return 2;
+ }
+ return 0; /* string ended */
+}
+
+
+static int str_characterpairs (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, characterpairs_aux, 2);
+ return 1;
+}
+
+static int bytes_aux (lua_State *L) {
+ size_t ls;
+ unsigned char i;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+ if (ind<(int)ls) {
+ lua_pushinteger(L, (ind+1)); /* iterator */
+ lua_replace(L, lua_upvalueindex(2));
+ i = (unsigned char)*(s+ind);
+ lua_pushinteger(L, i); /* byte */
+ return 1;
+ }
+ return 0; /* string ended */
+}
+
+static int str_bytes (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, bytes_aux, 2);
+ return 1;
+}
+
+static int bytepairs_aux (lua_State *L) {
+ size_t ls;
+ unsigned char i;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ int ind = lua_tointeger(L, lua_upvalueindex(2));
+ if (ind<(int)ls) {
+ if (ind+1<(int)ls) {
+ lua_pushinteger(L, (ind+2)); /* iterator */
+ } else {
+ lua_pushinteger(L, (ind+1)); /* iterator */
+ }
+ lua_replace(L, lua_upvalueindex(2));
+ i = (unsigned char)*(s+ind);
+ lua_pushinteger(L, i); /* byte one */
+ if (ind+1<(int)ls) {
+ i = (unsigned char)*(s+ind+1);
+ lua_pushinteger(L, i); /* byte two */
+ } else {
+ lua_pushnil(L); /* odd string length */
+ }
+ return 2;
+ }
+ return 0; /* string ended */
+}
+
+
+static int str_bytepairs (lua_State *L) {
+ luaL_checkstring(L, 1);
+ lua_settop(L, 1);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, bytepairs_aux, 2);
+ return 1;
+}
+
+
+
+static int writer (lua_State *L, const void* b, size_t size, void* B) {
+ (void)L;
+ luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
+ return 0;
+}
+
+static int lua_sdump (lua_State *L, lua_Writer writer, void *data, int stripping) {
+ int status;
+ TValue *o;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ o = L->top - 1;
+ if (isLfunction(o))
+ status = luaU_dump(L, getproto(o), writer, data, stripping);
+ else
+ status = 1;
+ lua_unlock(L);
+ return status;
+}
+
+static int str_dump (lua_State *L) {
+ luaL_Buffer b;
+ int stripping = 0;
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ if (lua_gettop(L)==2) {
+ stripping = lua_toboolean(L,2);
+ }
+ lua_settop(L, 1);
+ luaL_buffinit(L,&b);
+ if (lua_sdump(L, writer, &b, stripping) != 0)
+ return luaL_error(L, "unable to dump given function");
+ luaL_pushresult(&b);
+ return 1;
+}
+
+
+
+static const luaL_Reg strlibext[] = {
+ {"utfvalues", str_utfvalues},
+ {"utfcharacters", str_utfcharacters},
+ {"characters", str_characters},
+ {"characterpairs", str_characterpairs},
+ {"bytes", str_bytes},
+ {"bytepairs", str_bytepairs},
+ {"explode", str_split},
+ {"dump", str_dump},
+ {NULL, NULL}
+};
+
+void open_strlibext(lua_State * L)
+{
+ const luaL_Reg *lib;
+ lua_getglobal(L, "string");
+ for (lib=strlibext;lib->name;lib++) {
+ lua_pushcfunction(L, lib->func);
+ lua_setfield(L, -2, lib->name);
+ }
+ lua_pop(L,1);
+}
+
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c
index 0a30e552587..c1dc4c8935d 100644
--- a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c
@@ -21,7 +21,7 @@
#include "lua/luatex-api.h"
static const char _svn_version[] =
- "$Id: ltexiolib.c 3550 2010-03-26 14:37:09Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/ltexiolib.c $";
+ "$Id: ltexiolib.c 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltexiolib.c $";
typedef void (*texio_printer) (const char *);
@@ -134,7 +134,7 @@ void flush_loggable_info(void)
}
-static const struct luaL_reg texiolib[] = {
+static const struct luaL_Reg texiolib[] = {
{"write", texio_print},
{"write_nl", texio_printnl},
{NULL, NULL} /* sentinel */
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
index e9e05b8b7aa..3a387793f92 100644
--- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c
@@ -1,6 +1,6 @@
/* ltexlib.c
-
- Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
+
+ Copyright 2006-2012 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -23,7 +23,7 @@
static const char _svn_version[] =
- "$Id: ltexlib.c 4274 2011-05-18 11:23:45Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.70.1/source/texk/web2c/luatexdir/lua/ltexlib.c $";
+ "$Id: ltexlib.c 4569 2013-01-30 10:08:33Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltexlib.c $";
#define attribute(A) eqtb[attribute_base+(A)].hh.rh
#define dimen(A) eqtb[scaled_base+(A)].hh.rh
@@ -95,7 +95,7 @@ static int do_luacprint(lua_State * L, int partial, int deftable)
n = lua_gettop(L);
if (cattable != NO_CAT_TABLE) {
if (lua_type(L, 1) == LUA_TNUMBER && n > 1) {
- lua_number2int(cattable, lua_tonumber(L, 1));
+ cattable=(int)lua_tonumber(L, 1);
startstrings = 2;
if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) {
cattable = DEFAULT_CAT_TABLE;
@@ -153,7 +153,7 @@ static int luactprint(lua_State * L)
lua_pushnumber(L, 1);
lua_gettable(L, -2);
if (lua_type(L, -1) == LUA_TNUMBER) {
- lua_number2int(cattable, lua_tonumber(L, -1));
+ cattable=(int)lua_tonumber(L, -1);
startstrings = 2;
if (cattable != -1 && cattable != -2 && !valid_catcode_table(cattable)) {
cattable = DEFAULT_CAT_TABLE;
@@ -261,9 +261,9 @@ void luacstring_close(int n)
free(next->text);
t = next;
next = next->next;
- if (t==read_spindle.tail) {
- read_spindle.tail = NULL; /* prevent double free */
- }
+ if (t==read_spindle.tail) {
+ read_spindle.tail = NULL; // prevent double-free
+ }
free(t);
}
read_spindle.head = NULL;
@@ -289,10 +289,10 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret,
int d; /* the digit just scanned */
boolean vacuous; /* have no digits appeared? */
boolean OK_so_far; /* has an error message been issued? */
- int radix = 0; /* the radix of the integer */
+ int radix1 = 0; /* the radix of the integer */
int c = 0; /* the current character */
const char *s; /* where we stopped in the string |ss| */
- integer cur_val = 0; /* return value */
+ integer val = 0; /* return value */
s = ss;
do {
do {
@@ -305,26 +305,26 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret,
} while (c == '+');
- radix = 10;
+ radix1 = 10;
m = 214748364;
if (c == '\'') {
- radix = 8;
+ radix1 = 8;
m = 02000000000;
c = *s++;
} else if (c == '"') {
- radix = 16;
+ radix1 = 16;
m = 01000000000;
c = *s++;
}
vacuous = true;
- cur_val = 0;
+ val = 0;
OK_so_far = true;
/* Accumulate the constant until |cur_tok| is not a suitable digit */
while (1) {
- if ((c < '0' + radix) && (c >= '0') && (c <= '0' + 9)) {
+ if ((c < '0' + radix1) && (c >= '0') && (c <= '0' + 9)) {
d = c - '0';
- } else if (radix == 16) {
+ } else if (radix1 == 16) {
if ((c <= 'A' + 5) && (c >= 'A')) {
d = c - 'A' + 10;
} else if ((c <= 'a' + 5) && (c >= 'a')) {
@@ -336,14 +336,14 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret,
break;
}
vacuous = false;
- if ((cur_val >= m) && ((cur_val > m) || (d > 7) || (radix != 10))) {
+ if ((val >= m) && ((val > m) || (d > 7) || (radix1 != 10))) {
if (OK_so_far) {
luaL_error(L, "Number too big");
- cur_val = infinity;
+ val = infinity;
OK_so_far = false;
}
} else {
- cur_val = cur_val * radix + d;
+ val = val * radix1 + d;
}
c = *s++;
}
@@ -352,9 +352,9 @@ static const char *scan_integer_part(lua_State * L, const char *ss, int *ret,
luaL_error(L, "Missing number, treated as zero");
}
if (negative)
- cur_val = -cur_val;
- *ret = cur_val;
- *radix_ret = radix;
+ val = -val;
+ *ret = val;
+ *radix_ret = radix1;
if (c != ' ' && s > ss)
s--;
return s;
@@ -372,10 +372,9 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret)
int k; /* number of digits in a decimal fraction */
scaled v; /* an internal dimension */
int save_cur_val; /* temporary storage of |cur_val| */
- int arith_error = false;
int c; /* the current character */
const char *s = ss; /* where we are in the string */
- int radix = 0; /* the current radix */
+ int radix1 = 0; /* the current radix */
int rdig[18]; /* to save the |dig[]| array */
int saved_tex_remainder; /* to save |tex_remainder| */
int saved_arith_error; /* to save |arith_error| */
@@ -399,16 +398,16 @@ static const char *scan_dimen_part(lua_State * L, const char *ss, int *ret)
c = '.';
}
if (c != '.') {
- s = scan_integer_part(L, (s > ss ? (s - 1) : ss), &cur_val, &radix);
+ s = scan_integer_part(L, (s > ss ? (s - 1) : ss), &cur_val, &radix1);
c = *s;
} else {
- radix = 10;
+ radix1 = 10;
cur_val = 0;
c = *(--s);
}
if (c == ',')
c = '.';
- if ((radix == 10) && (c == '.')) {
+ if ((radix1 == 10) && (c == '.')) {
/* Scan decimal fraction */
for (k = 0; k < 18; k++)
rdig[k] = dig[k];
@@ -577,7 +576,7 @@ static int tex_scaledimen(lua_State * L)
return 0;
}
} else {
- lua_number2int(sp, lua_tonumber(L, 1));
+ sp=(int)lua_tonumber(L, 1);
}
lua_pushnumber(L, sp);
return 1;
@@ -623,28 +622,31 @@ static int texerror (lua_State * L)
return 0;
}
-
static int get_item_index(lua_State * L, int i, int base)
{
size_t kk;
int k;
- int cur_cs;
+ int cur_cs1;
const char *s;
- if (lua_type(L, i) == LUA_TSTRING) {
+ switch (lua_type(L, i)) {
+ case LUA_TSTRING:
s = lua_tolstring(L, i, &kk);
- cur_cs = string_lookup(s, kk);
- if (cur_cs == undefined_control_sequence || cur_cs == undefined_cs_cmd) {
+ cur_cs1 = string_lookup(s, kk);
+ if (cur_cs1 == undefined_control_sequence || cur_cs1 == undefined_cs_cmd)
k = -1; /* guarandeed invalid */
- } else {
- k = (equiv(cur_cs) - base);
- }
- } else {
+ else
+ k = (equiv(cur_cs1) - base);
+ break;
+ case LUA_TNUMBER:
k = (int) luaL_checkinteger(L, i);
+ break;
+ default:
+ luaL_error(L, "argument must be a string or a number");
+ k = -1; /* not a valid index */
}
return k;
}
-
static int vsetdimen(lua_State * L, int is_global)
{
int i, j, err;
@@ -662,7 +664,7 @@ static int vsetdimen(lua_State * L, int is_global)
luaL_error(L, "unsupported value type");
}
} else {
- lua_number2int(j, lua_tonumber(L, i));
+ j=(int)lua_tonumber(L, i);
}
k = get_item_index(L, (i - 1), scaled_base);
check_index_range(k, "setdimen");
@@ -886,19 +888,25 @@ static int gettoks(lua_State * L)
static int get_box_id(lua_State * L, int i)
{
const char *s;
- int cur_cs, cur_cmd;
+ int cur_cs1, cur_cmd1;
size_t k = 0;
int j = -1;
- if (lua_type(L, i) == LUA_TSTRING) {
+ switch (lua_type(L, i)) {
+ case LUA_TSTRING:
s = lua_tolstring(L, i, &k);
- cur_cs = string_lookup(s, k);
- cur_cmd = eq_type(cur_cs);
- if (cur_cmd == char_given_cmd ||
- cur_cmd == math_given_cmd || cur_cmd == omath_given_cmd) {
- j = equiv(cur_cs);
+ 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);
}
- } else {
- lua_number2int(j, lua_tonumber(L, (i)));
+ break;
+ case LUA_TNUMBER:
+ j=(int)lua_tonumber(L, (i));
+ break;
+ default:
+ luaL_error(L, "argument must be a string or a number");
+ j = -1; /* not a valid box id */
}
return j;
}
@@ -915,13 +923,12 @@ static int getbox(lua_State * L)
static int vsetbox(lua_State * L, int is_global)
{
- int i, j, k, err;
+ int j, k, err;
int save_global_defs = int_par(global_defs_code);
if (is_global)
int_par(global_defs_code) = 1;
k = get_box_id(L, -2);
check_index_range(k, "setbox");
- i = get_tex_box_register(k);
if (lua_isboolean(L, -1)) {
j = lua_toboolean(L, -1);
if (j == 0)
@@ -962,11 +969,11 @@ static int setbox(lua_State * L)
luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); }
-static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword),
+static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword),
void (*settwo)(int,halfword,quarterword), const char *name, int lim)
{
int ch;
- halfword val, ucval;
+ halfword val, ucval;
int level = cur_level;
int n = lua_gettop(L);
int f = 1;
@@ -975,7 +982,7 @@ static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword),
if (n>2 && lua_isstring(L, f)) {
const char *s = lua_tostring(L, f);
if (strcmp(s, "global") == 0) {
- level = level_one;
+ level = level_one;
f++;
}
}
@@ -1044,7 +1051,7 @@ static int setcatcode(lua_State * L)
if (n>2 && lua_isstring(L, f)) {
const char *s = lua_tostring(L, f);
if (strcmp(s, "global") == 0) {
- level = level_one;
+ level = level_one;
f++;
}
}
@@ -1084,7 +1091,7 @@ static int setmathcode(lua_State * L)
if (n>2 && lua_isstring(L, f)) {
const char *s = lua_tostring(L, f);
if (strcmp(s, "global") == 0) {
- level = level_one;
+ level = level_one;
f++;
}
}
@@ -1139,7 +1146,7 @@ static int setdelcode(lua_State * L)
if (n>2 && lua_isstring(L, f)) {
const char *s = lua_tostring(L, f);
if (strcmp(s, "global") == 0) {
- level = level_one;
+ level = level_one;
f++;
}
}
@@ -1194,7 +1201,7 @@ static int settex(lua_State * L)
const char *st;
int i, j, texstr;
size_t k;
- int cur_cs, cur_cmd;
+ int cur_cs1, cur_cmd1;
int isglobal = 0;
j = 0;
i = lua_gettop(L);
@@ -1207,19 +1214,19 @@ static int settex(lua_State * L)
if (strcmp(s, "global") == 0)
isglobal = 1;
}
- cur_cs = string_lookup(st, k);
+ cur_cs1 = string_lookup(st, k);
flush_str(texstr);
- cur_cmd = eq_type(cur_cs);
- if (is_int_assign(cur_cmd)) {
+ cur_cmd1 = eq_type(cur_cs1);
+ if (is_int_assign(cur_cmd1)) {
if (lua_isnumber(L, i)) {
int luai;
- lua_number2int(luai, lua_tonumber(L, i));
+ luai=(int)lua_tonumber(L, i);
assign_internal_value((isglobal ? 4 : 0),
- equiv(cur_cs), luai);
+ equiv(cur_cs1), luai);
} else {
luaL_error(L, "unsupported value type");
}
- } else if (is_dim_assign(cur_cmd)) {
+ } else if (is_dim_assign(cur_cmd1)) {
if (!lua_isnumber(L, i)) {
if (lua_isstring(L, i)) {
j = dimen_to_number(L, lua_tostring(L, i));
@@ -1227,18 +1234,18 @@ static int settex(lua_State * L)
luaL_error(L, "unsupported value type");
}
} else {
- lua_number2int(j, lua_tonumber(L, i));
+ j=(int)lua_tonumber(L, i);
}
- assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs), j);
- } else if (is_glue_assign(cur_cmd)) {
- halfword *j = check_isnode(L, i); /* the value */
+ assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), j);
+ } else if (is_glue_assign(cur_cmd1)) {
+ halfword *j1 = check_isnode(L, i); /* the value */
{ int a = isglobal;
- define(equiv(cur_cs), assign_glue_cmd, *j);
+ define(equiv(cur_cs1), assign_glue_cmd, *j1);
}
- } else if (is_toks_assign(cur_cmd)) {
+ } else if (is_toks_assign(cur_cmd1)) {
if (lua_isstring(L, i)) {
j = tokenlist_from_lua(L); /* uses stack -1 */
- assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs), j);
+ assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs1), j);
} else {
luaL_error(L, "unsupported value type");
@@ -1296,7 +1303,7 @@ static int do_convert(lua_State * L, int cur_code)
if (lua_gettop(L) < 1) {
/* error */
}
- lua_number2int(i, lua_tonumber(L, 1)); /* these fall through! */
+ i=(int)lua_tonumber(L, 1); /* these fall through! */
default:
texstr = the_convert_string(cur_code, i);
if (texstr) {
@@ -1314,14 +1321,14 @@ static int do_convert(lua_State * L, int cur_code)
}
-static int do_scan_internal(lua_State * L, int cur_cmd, int cur_code)
+static int do_scan_internal(lua_State * L, int cur_cmd1, int cur_code)
{
int texstr;
char *str = NULL;
int save_cur_val, save_cur_val_level;
save_cur_val = cur_val;
save_cur_val_level = cur_val_level;
- scan_something_simple(cur_cmd, cur_code);
+ scan_something_simple(cur_cmd1, cur_code);
if (cur_val_level == int_val_level ||
cur_val_level == dimen_val_level || cur_val_level == attr_val_level) {
@@ -1401,10 +1408,6 @@ static int do_lastitem(lua_State * L, int cur_code)
case random_seed_code:
case pdf_last_link_code:
case luatex_version_code:
- case Aleph_version_code:
- case Omega_version_code:
- case Aleph_minor_version_code:
- case Omega_minor_version_code:
case eTeX_minor_version_code:
case eTeX_version_code:
case current_group_level_code:
@@ -1437,7 +1440,9 @@ static int tex_setmathparm(lua_State * L)
}
i = luaL_checkoption(L, (n - 2), NULL, math_param_names);
j = luaL_checkoption(L, (n - 1), NULL, math_style_names);
- lua_number2int(k, lua_tonumber(L, n));
+ if (!lua_isnumber(L, n))
+ luaL_error(L, "argument must be a number");
+ k=(int)lua_tonumber(L, n);
def_math_param(i, j, (scaled) k, l);
}
return 0;
@@ -1533,22 +1538,22 @@ static int get_parshape(lua_State * L)
static int gettex(lua_State * L)
{
- int cur_cs = -1;
+ int cur_cs1 = -1;
int retval = 1; /* default is to return nil */
-
- if (lua_isstring(L, 2)) { /* 1 == 'tex' */
+ int t = lua_gettop(L);
+ if (lua_isstring(L, t)) { /* 1 == 'tex', 2 == 'boxmaxdepth', or 1 == 'boxmaxdepth' */
int texstr;
size_t k;
- const char *st = lua_tolstring(L, 2, &k);
+ const char *st = lua_tolstring(L, t, &k);
texstr = maketexlstring(st, k);
- cur_cs = prim_lookup(texstr); /* not found == relax == 0 */
+ cur_cs1 = prim_lookup(texstr); /* not found == relax == 0 */
flush_str(texstr);
}
- if (cur_cs > 0) {
- int cur_cmd, cur_code;
- cur_cmd = get_prim_eq_type(cur_cs);
- cur_code = get_prim_equiv(cur_cs);
- switch (cur_cmd) {
+ if (cur_cs1 > 0) {
+ int cur_cmd1, cur_code;
+ cur_cmd1 = get_prim_eq_type(cur_cs1);
+ cur_code = get_prim_equiv(cur_cs1);
+ switch (cur_cmd1) {
case last_item_cmd:
retval = do_lastitem(L, cur_code);
break;
@@ -1568,8 +1573,7 @@ static int gettex(lua_State * L)
case set_page_dimen_cmd:
case char_given_cmd:
case math_given_cmd:
- case omath_given_cmd:
- retval = do_scan_internal(L, cur_cmd, cur_code);
+ retval = do_scan_internal(L, cur_cmd1, cur_code);
break;
case set_tex_shape_cmd:
retval = get_parshape(L);
@@ -1579,7 +1583,9 @@ static int gettex(lua_State * L)
break;
}
} else {
- lua_rawget(L, 1); /* fetch other index from table */
+ if (t == 2) {
+ lua_rawget(L, 1);
+ }
}
return retval;
}
@@ -1734,7 +1740,7 @@ static int lua_nest_setfield(lua_State * L)
const char *field = lua_tostring(L, -2);
r = *rv;
if (strcmp(field, "mode") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->mode_field = i;
} else if (strcmp(field, "head") == 0) {
n = check_isnode(L, -1);
@@ -1746,16 +1752,16 @@ static int lua_nest_setfield(lua_State * L)
n = check_isnode(L, -1);
r->eTeX_aux_field = *n;
} else if (strcmp(field, "prevgraf") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->pg_field = i;
} else if (strcmp(field, "modeline") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->ml_field = i;
} else if (strcmp(field, "prevdepth") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->prev_depth_field = i;
} else if (strcmp(field, "spacefactor") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->space_factor_field = i;
} else if (strcmp(field, "noad") == 0) {
n = check_isnode(L, -1);
@@ -1766,13 +1772,13 @@ static int lua_nest_setfield(lua_State * L)
} else if (strcmp(field, "mathdir") == 0) {
r->math_field = lua_toboolean(L, -1);
} else if (strcmp(field, "mathstyle") == 0) {
- lua_number2int(i, lua_tonumber(L, -1));
+ i=(int)lua_tonumber(L, -1);
r->math_style_field = i;
}
return 0;
}
-static const struct luaL_reg nest_m[] = {
+static const struct luaL_Reg nest_m[] = {
{"__index", lua_nest_getfield},
{"__newindex", lua_nest_setfield},
{NULL, NULL} /* sentinel */
@@ -1790,7 +1796,7 @@ static int getnest(lua_State * L)
int ptr;
list_state_record **nestitem;
if (lua_isnumber(L, 2)) {
- lua_number2int(ptr, lua_tonumber(L, 2));
+ ptr=(int)lua_tonumber(L, 2);
if (ptr >= 0 && ptr <= nest_ptr) {
nestitem = lua_newuserdata(L, sizeof(list_state_record *));
*nestitem = &nest[ptr];
@@ -1913,7 +1919,7 @@ static int tex_hashpairs(lua_State * L)
str_number s = 0;
int cs = 1;
lua_newtable(L);
- while (cs < eqtb_size) {
+ while (cs < hash_size) {
s = hash_text(cs);
if (s > 0) {
char *ss = makecstring(s);
@@ -1955,12 +1961,11 @@ static int tex_extraprimitives(lua_State * L)
{
int n, i;
int mask = 0;
- str_number s = 0;
int cs = 0;
n = lua_gettop(L);
if (n == 0) {
mask = etex_command + aleph_command + omega_command +
- pdftex_command + luatex_command;
+ pdftex_command + luatex_command + umath_command;
} else {
for (i = 1; i <= n; i++) {
if (lua_isstring(L, i)) {
@@ -1978,7 +1983,9 @@ static int tex_extraprimitives(lua_State * L)
} else if (strcmp(s, "omega") == 0) {
mask |= omega_command;
} else if (strcmp(s, "luatex") == 0) {
- mask |= luatex_command;
+ mask |= luatex_command | umath_command;
+ } else if (strcmp(s, "umath") == 0) {
+ mask |= umath_command;
}
}
}
@@ -1986,6 +1993,7 @@ static int tex_extraprimitives(lua_State * L)
lua_newtable(L);
i = 1;
while (cs < prim_size) {
+ str_number s = 0;
s = get_prim_text(cs);
if (s > 0) {
if (get_prim_origin(cs) & mask) {
@@ -2023,8 +2031,8 @@ static int tex_enableprimitives(lua_State * L)
char *newprim;
int val;
size_t newl;
- halfword cur_cmd = get_prim_eq_type(prim_val);
- halfword cur_chr = get_prim_equiv(prim_val);
+ halfword cur_cmd1 = get_prim_eq_type(prim_val);
+ halfword cur_chr1 = get_prim_equiv(prim_val);
if (strncmp(pre, prim, l) != 0) { /* not a prefix */
newl = strlen(prim) + l;
newprim = (char *) xmalloc((unsigned) (newl + 1));
@@ -2038,8 +2046,8 @@ static int tex_enableprimitives(lua_State * L)
val = string_lookup(newprim, newl);
if (val == undefined_control_sequence ||
eq_type(val) == undefined_cs_cmd) {
- primitive_def(newprim, newl, (quarterword) cur_cmd,
- cur_chr);
+ primitive_def(newprim, newl, (quarterword) cur_cmd1,
+ cur_chr1);
}
free(newprim);
}
@@ -2064,7 +2072,7 @@ static int tex_enableprimitives(lua_State * L)
lua_pushstring(L,(A)); \
lua_gettable(L,-2); \
if (lua_type(L, -1) == LUA_TNUMBER) { \
- lua_number2int(B,lua_tonumber(L, -1)); \
+ B=(int)lua_tonumber(L, -1); \
} else { \
B = (C); \
} \
@@ -2076,7 +2084,7 @@ static int tex_enableprimitives(lua_State * L)
lua_pushstring(L,(A)); \
lua_gettable(L,-2); \
if (lua_type(L, -1) == LUA_TNUMBER) { \
- lua_number2int(B,lua_tonumber(L, -1)); \
+ B=(int)lua_tonumber(L, -1); \
D = null; \
} else if (lua_type(L, -1) == LUA_TTABLE){ \
B = 0; \
@@ -2092,7 +2100,7 @@ static int tex_enableprimitives(lua_State * L)
lua_pushstring(L,(A)); \
lua_gettable(L,-2); \
if (lua_type(L, -1) == LUA_TNUMBER) { \
- lua_number2int(B,lua_tonumber(L, -1)); \
+ B=(int)lua_tonumber(L, -1); \
} else { \
B = (C); \
} \
@@ -2136,11 +2144,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) {
- lua_number2int(indent, lua_tonumber(L, -1));
+ indent=(int)lua_tonumber(L, -1);
lua_pop(L, 1);
lua_rawgeti(L, -1, 2); /* width */
if (lua_type(L, -1) == LUA_TNUMBER) {
- lua_number2int(width, lua_tonumber(L, -1));
+ width=(int)lua_tonumber(L, -1);
lua_pop(L, 1);
varmem[p + 2 * j].cint = indent;
varmem[p + 2 * j + 1].cint = width;
@@ -2176,7 +2184,7 @@ static halfword nodelib_topenalties(lua_State * L, int i)
j++;
if (lua_isnumber(L, -1)) {
int pen = 0;
- lua_number2int(pen, lua_tonumber(L, -1));
+ pen=(int)lua_tonumber(L, -1);
varmem[p+j].cint = pen;
}
lua_pop(L, 1);
@@ -2233,7 +2241,7 @@ static int tex_run_linebreak(lua_State * L)
lua_pushstring(L, "pardir");
lua_gettable(L, -2);
if (lua_type(L, -1) == LUA_TSTRING) {
- paragraph_dir = nodelib_getdir(L, -1);
+ paragraph_dir = nodelib_getdir(L, -1, 1);
}
lua_pop(L, 1);
@@ -2266,11 +2274,11 @@ static int tex_run_linebreak(lua_State * L)
get_int_par("finalhyphendemerits", finalhyphendemerits,
int_par(final_hyphen_demerits_code));
get_int_par("hangafter", hangafter, int_par(hang_after_code));
- get_intx_par("interlinepenalty", interlinepenalty,int_par(inter_line_penalty_code),
+ get_intx_par("interlinepenalty", interlinepenalty,int_par(inter_line_penalty_code),
interlinepenalties, equiv(inter_line_penalties_loc));
- get_intx_par("clubpenalty", clubpenalty, int_par(club_penalty_code),
+ get_intx_par("clubpenalty", clubpenalty, int_par(club_penalty_code),
clubpenalties, equiv(club_penalties_loc));
- get_intx_par("widowpenalty", widowpenalty, int_par(widow_penalty_code),
+ get_intx_par("widowpenalty", widowpenalty, int_par(widow_penalty_code),
widowpenalties, equiv(widow_penalties_loc));
get_int_par("brokenpenalty", brokenpenalty, int_par(broken_penalty_code));
get_dimen_par("emergencystretch", emergencystretch,
@@ -2345,8 +2353,8 @@ static int tex_shipout(lua_State * L)
static int tex_badness(lua_State * L)
{
scaled t,s;
- lua_number2int(t,lua_tonumber(L,1));
- lua_number2int(s,lua_tonumber(L,2));
+ t=(int)lua_tonumber(L,1);
+ s=(int)lua_tonumber(L,2);
lua_pushnumber(L, badness(t,s));
return 1;
}
@@ -2384,7 +2392,7 @@ static int tex_run_boot(lua_State * L)
random_seed = (microseconds * 1000) + (epochseconds % 1000000);
init_randoms(random_seed);
initialize_math();
- fixup_selector(log_opened);
+ fixup_selector(log_opened_global);
check_texconfig_init();
text_dir_ptr = new_dir(0);
history = spotless; /* ready to go! */
@@ -2432,7 +2440,7 @@ void init_tex_table(lua_State * L)
-static const struct luaL_reg texlib[] = {
+static const struct luaL_Reg texlib[] = {
{"run", tex_run_main}, /* may be needed */
{"finish", tex_run_end}, /* may be needed */
{"write", luacwrite},
diff --git a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c
index 9632c9ec533..67029176e81 100644
--- a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c
@@ -1,6 +1,6 @@
/* ltokenlib.c
- Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
+ Copyright 2006-2012 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
@@ -21,9 +21,9 @@
#include "lua/luatex-api.h"
static const char _svn_version[] =
- "$Id: ltokenlib.c 3404 2010-01-28 11:17:10Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/ltokenlib.c $";
+ "$Id: ltokenlib.c 4524 2012-12-20 15:38:02Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltokenlib.c $";
-#define is_valid_token(L,i) (lua_istable(L,i) && lua_objlen(L,i)==3)
+#define is_valid_token(L,i) (lua_istable(L,i) && lua_rawlen(L,i)==3)
#define get_token_cmd(L,i) lua_rawgeti(L,i,1)
#define get_token_chr(L,i) lua_rawgeti(L,i,2)
#define get_token_cs(L,i) lua_rawgeti(L,i,3)
@@ -128,13 +128,15 @@ static int run_get_command_name(lua_State * L)
static int run_get_csname_name(lua_State * L)
{
- int cs, cmd;
+ int cs /*, cmd*/;
unsigned char *s;
if (is_valid_token(L, -1)) {
get_token_cmd(L, -1);
+ /*
if (lua_isnumber(L, -1)) {
cmd = (int) lua_tointeger(L, -1);
}
+ */
lua_pop(L, 1);
cs = 0;
get_token_cs(L, -1);
@@ -262,7 +264,7 @@ static int run_build(lua_State * L)
}
-static const struct luaL_reg tokenlib[] = {
+static const struct luaL_Reg tokenlib[] = {
{"get_next", run_get_next},
{"expand", run_expand},
{"lookup", run_lookup},
diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.w b/Build/source/texk/web2c/luatexdir/lua/luagen.w
index f992a15b17e..707e7de2bdb 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luagen.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luagen.w
@@ -1,26 +1,26 @@
% luagen.w
-%
-% Copyright 2009 Taco Hoekwater <taco@@luatex.org>
-
+%
+% Copyright 2009-2012 Taco Hoekwater <taco@@luatex.org>
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
static const char _svn_version[] =
- "$Id: luagen.w 3583 2010-04-02 17:40:44Z hhenkel $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luagen.w $";
+ "$Id: luagen.w 4442 2012-05-25 22:40:34Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luagen.w $";
#include "ptexlib.h"
#include "pdf/pdfpage.h"
diff --git a/Build/source/texk/web2c/luatexdir/lua/luainit.w b/Build/source/texk/web2c/luatexdir/lua/luainit.w
index 11b2883b113..7205b801682 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luainit.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luainit.w
@@ -1,32 +1,33 @@
% luainit.w
-%
-% Copyright 2006-2012 Taco Hoekwater <taco@@luatex.org>
-
+%
+% Copyright 2006-2011 Taco Hoekwater <taco@@luatex.org>
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
+static const char _svn_version[] =
+ "$Id: luainit.w 4524 2012-12-20 15:38:02Z taco $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luainit.w $";
+
#include <kpathsea/c-stat.h>
#include "ptexlib.h"
#include "lua/luatex-api.h"
-static const char _svn_version[] =
- "$Id: luainit.w 4260 2011-05-13 07:03:44Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.70.x/source/texk/web2c/luatexdir/lua/luainit.w $";
-
-@
+@
TH: TODO
This file is getting a bit messy, but it is not simple to fix unilaterally.
@@ -132,7 +133,7 @@ static char *ex_selfdir(char *argv0)
FATAL1("This path points to an invalid file : %s\n", short_path);
}
#endif /* __MINGW32__ */
- return xdirname(path);
+ return xdirname(path);
#else /* WIN32 */
return kpse_selfdir(argv0);
#endif
@@ -140,14 +141,14 @@ static char *ex_selfdir(char *argv0)
@ @c
static void
-prepare_cmdline(lua_State * L, char **argv, int argc, int zero_offset)
+prepare_cmdline(lua_State * L, char **av, int ac, int zero_offset)
{
int i;
char *s;
- luaL_checkstack(L, argc + 3, "too many arguments to script");
+ luaL_checkstack(L, ac + 3, "too many arguments to script");
lua_createtable(L, 0, 0);
- for (i = 0; i < argc; i++) {
- lua_pushstring(L, argv[i]);
+ for (i = 0; i < ac; i++) {
+ lua_pushstring(L, av[i]);
lua_rawseti(L, -2, (i - zero_offset));
}
lua_setglobal(L, "arg");
@@ -226,7 +227,7 @@ static struct option long_options[]
};
@ @c
-static void parse_options(int argc, char **argv)
+static void parse_options(int ac, char **av)
{
#ifdef WIN32
/* save argc and argv */
@@ -243,7 +244,7 @@ static void parse_options(int argc, char **argv)
luainit = 1;
}
for (;;) {
- g = getopt_long_only(argc, argv, "+", long_options, &option_index);
+ g = getopt_long_only(ac, av, "+", long_options, &option_index);
if (g == -1) /* End of arguments, exit the loop. */
break;
@@ -344,7 +345,7 @@ static void parse_options(int argc, char **argv)
"the terms of the GNU General Public License, version 2. For more\n"
"information about these matters, see the file named COPYING and\n"
"the LuaTeX source.\n\n"
- "Copyright 2012 Taco Hoekwater, the LuaTeX Team.\n");
+ "Copyright 2011 Taco Hoekwater, the LuaTeX Team.\n");
/* *INDENT-ON* */
uexit(0);
} else if (ARGUMENT_IS("credits")) {
@@ -363,7 +364,7 @@ static void parse_options(int argc, char **argv)
"lua by Roberto Ierusalimschy, Waldemar Celes,\n"
" Luiz Henrique de Figueiredo\n"
"metapost by John Hobby, Taco Hoekwater and friends.\n"
- "poppler by Derek Noonburg, Kristian H\\ogsberg (partial)\n"
+ "poppler by Derek Noonburg, Kristian H\\ogsberg (partial)\n"
"fontforge by George Williams (partial)\n\n"
"Some extensions to lua and additional lua libraries are used, as well as\n"
"libraries for graphic inclusion. More details can be found in the source.\n"
@@ -580,7 +581,6 @@ function, the other for its environment .
@c
static int lua_loader_function = 0;
-static int lua_loader_env = 0;
static int luatex_kpse_lua_find(lua_State * L)
{
@@ -588,13 +588,10 @@ static int luatex_kpse_lua_find(lua_State * L)
const char *name;
name = luaL_checkstring(L, 1);
if (program_name_set == 0) {
- lua_CFunction orig_func;
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_loader_function);
- lua_rawgeti(L, LUA_REGISTRYINDEX, lua_loader_env);
- lua_replace(L, LUA_ENVIRONINDEX);
- orig_func = lua_tocfunction(L, -1);
- lua_pop(L, 1);
- return (orig_func) (L);
+ lua_pushvalue(L, -2);
+ lua_call(L, 1, 1);
+ return 1;
}
filename = luatex_kpse_find_aux(L, name, kpse_lua_format, "lua");
if (filename == NULL)
@@ -608,7 +605,7 @@ static int luatex_kpse_lua_find(lua_State * L)
@ @c
static int clua_loader_function = 0;
-static int clua_loader_env = 0;
+extern int searcher_C_luatex (lua_State *L, const char *name, const char *filename);
static int luatex_kpse_clua_find(lua_State * L)
{
@@ -620,86 +617,73 @@ static int luatex_kpse_clua_find(lua_State * L)
}
name = luaL_checkstring(L, 1);
if (program_name_set == 0) {
- lua_CFunction orig_func;
lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_function);
- lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_env);
- lua_replace(L, LUA_ENVIRONINDEX);
- orig_func = lua_tocfunction(L, -1);
- lua_pop(L, 1);
- return (orig_func) (L);
- }
- filename = luatex_kpse_find_aux(L, name, kpse_clua_format, "C");
- if (filename == NULL)
- return 1; /* library not found in this path */
- return loader_C_luatex(L, name, filename);
-}
-
-@ @c
-static int clua_loadall_function = 0;
-static int clua_loadall_env = 0;
-
-static int luatex_kpse_cluaall_find(lua_State * L)
-{
- const char *filename;
- const char *name;
- char *fixedname;
- const char *p = NULL;
- if (safer_option) {
- lua_pushliteral(L, "\n\t[All-in-one searcher disabled in safer mode]");
- return 1; /* library not found in this path */
- }
- name = luaL_checkstring(L, 1);
- p = strchr(name, '.');
- if (program_name_set == 0) {
- lua_CFunction orig_func;
- lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loadall_function);
- lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loadall_env);
- lua_replace(L, LUA_ENVIRONINDEX);
- orig_func = lua_tocfunction(L, -1);
- lua_pop(L, 1);
- return (orig_func) (L);
+ lua_pushvalue(L, -2);
+ lua_call(L, 1, 1);
+ return 1;
+ } else {
+ const char *path_saved;
+ char *prefix, *postfix, *p, *total;
+ char *extensionless;
+ filename = luatex_kpse_find_aux(L, name, kpse_clua_format, "C");
+ if (filename == NULL)
+ return 1; /* library not found in this path */
+ extensionless = strdup(filename);
+ if (!extensionless) return 1; /* allocation failure */
+ p = strstr(extensionless, name);
+ if (!p) return 1; /* this would be exceedingly weird */
+ *p = '\0';
+ prefix = strdup(extensionless);
+ if (!prefix) return 1; /* allocation failure */
+ postfix = strdup(p+strlen(name));
+ if (!postfix) return 1; /* allocation failure */
+ total = malloc(strlen(prefix)+strlen(postfix)+2);
+ if (!total) return 1; /* allocation failure */
+ snprintf(total,strlen(prefix)+strlen(postfix)+2, "%s?%s", prefix, postfix);
+ /* save package.path */
+ lua_getglobal(L,"package");
+ lua_getfield(L,-1,"cpath");
+ path_saved = lua_tostring(L,-1);
+ lua_pop(L,1);
+ /* set package.path = "?" */
+ lua_pushstring(L,total);
+ lua_setfield(L,-2,"cpath");
+ lua_pop(L,1); /* pop "package" */
+ /* run function */
+ lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_function);
+ lua_pushstring(L, name);
+ lua_call(L, 1, 1);
+ /* restore package.path */
+ lua_getglobal(L,"package");
+ lua_pushstring(L,path_saved);
+ lua_setfield(L,-2,"cpath");
+ lua_pop(L,1); /* pop "package" */
+ free(extensionless);
+ free(total);
+ return 1;
}
- if (p == NULL) return 0; /* is root */
- fixedname = xmalloc((size_t)(p - name)+1);
- memcpy(fixedname,name,(size_t)(p - name));
- fixedname[(p - name)] = '\0';
- filename = luatex_kpse_find_aux(L, fixedname, kpse_clua_format, "All-in-one");
- free(fixedname);
- if (filename == NULL)
- return 1; /* library not found in this path */
- return loader_Call_luatex(L, name, filename);
}
@ Setting up the new search functions.
- This replaces package.loaders[2] with the function defined above.
+This replaces package.searchers[2] and package.searchers[3] with the
+functions defined above.
@c
static void setup_lua_path(lua_State * L)
{
lua_getglobal(L, "package");
- lua_getfield(L, -1, "loaders");
- lua_rawgeti(L, -1, 2); /* package.loaders[2] */
- lua_getfenv(L, -1);
- lua_loader_env = luaL_ref(L, LUA_REGISTRYINDEX);
+ lua_getfield(L, -1, "searchers");
+ lua_rawgeti(L, -1, 2); /* package.searchers[2] */
lua_loader_function = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushcfunction(L, luatex_kpse_lua_find);
lua_rawseti(L, -2, 2); /* replace the normal lua loader */
- lua_rawgeti(L, -1, 3); /* package.loaders[3] */
- lua_getfenv(L, -1);
- clua_loader_env = luaL_ref(L, LUA_REGISTRYINDEX);
+ lua_rawgeti(L, -1, 3); /* package.searchers[3] */
clua_loader_function = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushcfunction(L, luatex_kpse_clua_find);
lua_rawseti(L, -2, 3); /* replace the normal lua lib loader */
- lua_rawgeti(L, -1, 4); /* package.loaders[4] */
- lua_getfenv(L, -1);
- clua_loadall_env = luaL_ref(L, LUA_REGISTRYINDEX);
- clua_loadall_function = luaL_ref(L, LUA_REGISTRYINDEX);
- lua_pushcfunction(L, luatex_kpse_cluaall_find);
- lua_rawseti(L, -2, 4); /* replace the normal lua lib loader */
-
lua_pop(L, 2); /* pop the array and table */
}
@@ -780,11 +764,10 @@ void lua_initialize(int ac, char **av)
argc = ac;
argv = av;
- {
+ if (luatex_svn < 0) {
const char *fmt = "This is LuaTeX, Version %s-%s" WEB2CVERSION;
size_t len;
char buf[16];
-
sprintf(buf, "%d", luatex_date_info);
len = strlen(fmt) + strlen(luatex_version_string) + strlen(buf) - 3;
@@ -792,6 +775,14 @@ void lua_initialize(int ac, char **av)
that get replaced by the arguments. */
banner = xmalloc(len);
sprintf(banner, fmt, luatex_version_string, buf);
+ } else {
+ const char *fmt = "This is LuaTeX, Version %s-%s " WEB2CVERSION "(rev %d)";
+ size_t len;
+ char buf[16];
+ sprintf(buf, "%d", luatex_date_info);
+ len = strlen(fmt) + strlen(luatex_version_string) + strlen(buf) + 6;
+ banner = xmalloc(len);
+ sprintf(banner, fmt, luatex_version_string, buf, luatex_svn);
}
ptexbanner = banner;
@@ -859,6 +850,7 @@ void lua_initialize(int ac, char **av)
init_tex_table(Luas);
if (lua_pcall(Luas, 0, 0, 0)) {
fprintf(stdout, "%s\n", lua_tostring(Luas, -1));
+ lua_traceback(Luas);
exit(1);
}
/* no filename? quit now! */
@@ -911,7 +903,7 @@ void lua_initialize(int ac, char **av)
shellenabledp = 1;
restrictedshell = 1;
}
- free(v1);
+ free(v1);
}
/* If shell escapes are restricted, get allowed cmds from cnf. */
if (shellenabledp && restrictedshell == 1) {
@@ -919,7 +911,7 @@ void lua_initialize(int ac, char **av)
get_lua_string("texconfig", "shell_escape_commands", &v1);
if (v1) {
mk_shellcmdlist(v1);
- free(v1);
+ free(v1);
}
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/luanode.w b/Build/source/texk/web2c/luatexdir/lua/luanode.w
index 7b280d525ee..c2a13decdca 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luanode.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luanode.w
@@ -1,31 +1,30 @@
% luanode.w
-%
+%
% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
-
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
+static const char _svn_version[] =
+ "$Id: luanode.w 4442 2012-05-25 22:40:34Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luanode.w $";
+
#include "ptexlib.h"
#include "lua/luatex-api.h"
-
-static const char _svn_version[] =
- "$Id: luanode.w 4092 2011-03-16 14:53:39Z taco $ "
-"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luanode.w $";
-
@ @c
static const char *group_code_names[] = {
"",
diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.w b/Build/source/texk/web2c/luatexdir/lua/luastuff.w
index 510f2607214..f93aabf7b96 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luastuff.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.w
@@ -1,26 +1,26 @@
% luastuff.w
-
-% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
-
+%
+% Copyright 2006-2013 Taco Hoekwater <taco@@luatex.org>
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
static const char _svn_version[] =
- "$Id: luastuff.w 4001 2010-11-28 15:49:46Z taco $ "
- "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luastuff.w $";
+ "$Id: luastuff.w 4573 2013-02-03 16:47:07Z hhenkel $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luastuff.w $";
#include "ptexlib.h"
#include "lua/luatex-api.h"
@@ -96,18 +96,20 @@ static int my_luapanic(lua_State * L)
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{"package", luaopen_package},
+ {"coroutine", luaopen_coroutine},
{"table", luaopen_table},
- {"io", luaopen_io},
+ {"io", open_iolibext},
{"os", luaopen_os},
{"string", luaopen_string},
{"math", luaopen_math},
{"debug", luaopen_debug},
{"unicode", luaopen_unicode},
{"zip", luaopen_zip},
- {"lpeg", luaopen_lpeg},
+ {"bit32", luaopen_bit32},
{"md5", luaopen_md5},
{"lfs", luaopen_lfs},
{"profiler", luaopen_profiler},
+ {"lpeg", luaopen_lpeg},
{NULL, NULL}
};
@@ -115,11 +117,10 @@ static const luaL_Reg lualibs[] = {
@ @c
static void do_openlibs(lua_State * L)
{
- const luaL_Reg *lib = lualibs;
- for (; lib->func; lib++) {
- lua_pushcfunction(L, lib->func);
- lua_pushstring(L, lib->name);
- lua_call(L, 1, 0);
+ const luaL_Reg *lib;
+ for (lib = lualibs; lib->func; lib++) {
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1); /* remove lib */
}
}
@@ -136,17 +137,21 @@ static int load_aux (lua_State *L, int status) {
@ @c
static int luatex_loadfile (lua_State *L) {
+ int status = 0;
const char *fname = luaL_optstring(L, 1, NULL);
- if (!lua_only && !fname) {
- if (interaction == batch_mode) {
- lua_pushnil(L);
- lua_pushstring(L, "reading from stdin is disabled in batch mode");
- return 2; /* return nil plus error message */
- } else {
- tprint_nl("lua> ");
- }
+ const char *mode = luaL_optstring(L, 2, NULL);
+ int env = !lua_isnone(L, 3); /* 'env' parameter? */
+ if (!lua_only && !fname && interaction == batch_mode) {
+ lua_pushnil(L);
+ lua_pushstring(L, "reading from stdin is disabled in batch mode");
+ return 2; /* return nil plus error message */
}
- return load_aux(L, luaL_loadfile(L, fname));
+ status = luaL_loadfilex(L, fname, mode);
+ if (status == LUA_OK && env) { /* 'env' parameter? */
+ lua_pushvalue(L, 3);
+ lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */
+ }
+ return load_aux(L, status);
}
@ @c
@@ -180,7 +185,7 @@ void luainterpreter(void)
lua_atpanic(L, &my_luapanic);
do_openlibs(L); /* does all the 'simple' libraries */
-
+
lua_pushcfunction(L,luatex_dofile);
lua_setglobal(L, "dofile");
lua_pushcfunction(L,luatex_loadfile);
@@ -189,6 +194,10 @@ void luainterpreter(void)
luatex_md5_lua_open(L);
open_oslibext(L, safer_option);
+/*
+ open_iolibext(L);
+*/
+ open_strlibext(L);
open_lfslibext(L);
/* luasockets */
@@ -236,6 +245,7 @@ void luainterpreter(void)
luaopen_font(L);
luaopen_lang(L);
luaopen_mplib(L);
+ luaopen_vf(L);
/* |luaopen_pdf(L);| */
/* environment table at |LUA_ENVIRONINDEX| needs to load this way: */
@@ -243,14 +253,15 @@ void luainterpreter(void)
lua_pushstring(L, "pdf");
lua_call(L, 1, 0);
- /* |luaopen_img(L);| */
- lua_pushcfunction(L, luaopen_img);
- lua_pushstring(L, "img");
- lua_call(L, 1, 0);
+ luaL_requiref(L, "img", luaopen_img, 1);
+ lua_pop(L, 1);
+
+ luaL_requiref(L, "epdf", luaopen_epdf, 1);
+ lua_pop(L, 1);
- /* |luaopen_epdf(L);| */
- lua_pushcfunction(L, luaopen_epdf);
- lua_pushstring(L, "epdf");
+ /* |luaopen_pdfscanner(L);| */
+ lua_pushcfunction(L, luaopen_pdfscanner);
+ lua_pushstring(L, "pdfscanner");
lua_call(L, 1, 0);
lua_createtable(L, 0, 0);
@@ -328,7 +339,7 @@ void unhide_lua_value(lua_State * L, const char *name, const char *item, int r)
@ @c
int lua_traceback(lua_State * L)
{
- lua_getfield(L, LUA_GLOBALSINDEX, "debug");
+ lua_getglobal(L, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
return 1;
@@ -362,7 +373,7 @@ static void luacall(int p, int nameptr, boolean is_string)
lua_rawgeti(Luas, LUA_REGISTRYINDEX, p);
ss = lua_tolstring(Luas, -1, &ll);
s = xmalloc(ll+1);
- memcpy(s,ss,ll+1);
+ memcpy(s,ss,ll+1);
lua_pop(Luas,1);
} else {
int l = 0;
@@ -386,7 +397,7 @@ static void luacall(int p, int nameptr, boolean is_string)
snprintf((char *) lua_id, 20, "\\latelua ");
}
- i = lua_load(Luas, getS, &ls, lua_id);
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
if (i != 0) {
Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1));
} else {
@@ -445,7 +456,7 @@ void luatokencall(int p, int nameptr)
} else {
lua_id = xstrdup("\\directlua ");
}
- i = lua_load(Luas, getS, &ls, lua_id);
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
xfree(s);
if (i != 0) {
Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1));
@@ -470,13 +481,12 @@ void luatokencall(int p, int nameptr)
lua_State *luatex_error(lua_State * L, int is_fatal)
{
- const char *luaerr;
- size_t len = 0;
+ const_lstring luaerr;
char *err = NULL;
if (lua_isstring(L, -1)) {
- luaerr = lua_tolstring(L, -1, &len);
- err = (char *) xmalloc((unsigned) (len + 1));
- snprintf(err, (len + 1), "%s", luaerr);
+ luaerr.s = lua_tolstring(L, -1, &luaerr.l);
+ err = (char *) xmalloc((unsigned) (luaerr.l + 1));
+ snprintf(err, (luaerr.l + 1), "%s", luaerr.s);
}
if (is_fatal > 0) {
/* Normally a memory error from lua.
@@ -495,16 +505,22 @@ lua_State *luatex_error(lua_State * L, int is_fatal)
}
@ @c
-void preset_environment(lua_State * L, const parm_struct * p)
+void preset_environment(lua_State * L, const parm_struct * p, const char *s)
{
int i;
assert(L != NULL);
- lua_newtable(L); /* t */
+ /* double call with same s gives assert(0) */
+ lua_pushstring(L, s); /* s */
+ lua_gettable(L, LUA_REGISTRYINDEX); /* t */
+ assert(lua_isnil(L, -1));
+ lua_pop(L, 1); /* - */
+ lua_pushstring(L, s); /* s */
+ lua_newtable(L); /* t s */
for (i = 1, ++p; p->name != NULL; i++, p++) {
assert(i == p->idx);
- lua_pushstring(L, p->name); /* k t */
- lua_pushinteger(L, p->idx); /* v k t */
- lua_settable(L, -3); /* t */
+ lua_pushstring(L, p->name); /* k t s */
+ lua_pushinteger(L, p->idx); /* v k t s */
+ lua_settable(L, -3); /* t s */
}
- lua_replace(L, LUA_ENVIRONINDEX); /* - */
+ lua_settable(L, LUA_REGISTRYINDEX); /* - */
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
index 9de349a78e9..e89f20e4e61 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
+++ b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
-/* $Id: luatex-api.h 4001 2010-11-28 15:49:46Z taco $ */
+/* $Id: luatex-api.h 4569 2013-01-30 10:08:33Z taco $ */
#ifndef LUATEX_API_H
# define LUATEX_API_H 1
@@ -25,9 +25,13 @@
# include <stdlib.h>
# include <stdio.h>
# include <stdarg.h>
-# include "lua51/lua.h"
-# include "lua51/lauxlib.h"
-# include "lua51/lualib.h"
+# include "lua52/lua.h"
+# include "lua52/lauxlib.h"
+# include "lua52/lualib.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
typedef struct LoadS {
char *s;
@@ -72,9 +76,12 @@ extern void luatex_socketlua_open(lua_State * L);
extern int luaopen_img(lua_State * L);
extern int l_new_image(lua_State * L);
extern int luaopen_epdf(lua_State * L);
+extern int luaopen_pdfscanner(lua_State * L);
extern int luaopen_mplib(lua_State * L);
extern void open_oslibext(lua_State * L, int safer_option);
+extern int open_iolibext(lua_State * L);
+extern void open_strlibext(lua_State * L);
extern void open_lfslibext(lua_State * L);
extern void initfilecallbackids(int max);
@@ -94,6 +101,7 @@ extern int luaopen_lua(lua_State * L, char *fname);
extern int luaopen_stats(lua_State * L);
extern int luaopen_font(lua_State * L);
+extern int luaopen_vf(lua_State * L);
extern int font_to_lua(lua_State * L, int f);
extern int font_from_lua(lua_State * L, int f); /* return is boolean */
@@ -103,7 +111,7 @@ extern void tokenlist_to_luastring(lua_State * L, int p);
extern int tokenlist_from_lua(lua_State * L);
extern void lua_nodelib_push(lua_State * L);
-extern int nodelib_getdir(lua_State * L, int n);
+extern int nodelib_getdir(lua_State * L, int n, int absolute_only);
extern int luaopen_node(lua_State * L);
extern void nodelist_to_lua(lua_State * L, int n);
@@ -153,7 +161,8 @@ typedef struct {
int idx; /* index within img_parms array */
} parm_struct;
-extern void preset_environment(lua_State * L, const parm_struct * p);
+extern void preset_environment(lua_State * L, const parm_struct * p,
+ const char *s);
extern char *startup_filename;
extern int safer_option;
@@ -200,5 +209,7 @@ extern char **environ;
#endif
extern int luac_main(int argc, char *argv[]); /* texluac.w */
-
+#ifdef __cplusplus
+}
+#endif
#endif /* LUATEX_API_H */
diff --git a/Build/source/texk/web2c/luatexdir/lua/luatoken.w b/Build/source/texk/web2c/luatexdir/lua/luatoken.w
index d7bc02a7d52..d4b2e156091 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luatoken.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luatoken.w
@@ -1,30 +1,30 @@
% luatoken.w
-%
-% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
-
+%
+% Copyright 2006-2012 Taco Hoekwater <taco@@luatex.org>
+%
% This file is part of LuaTeX.
-
+%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
-
+%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
-
+%
% You should have received a copy of the GNU General Public License along
-% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
+% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
@ @c
+static const char _svn_version[] =
+ "$Id: luatoken.w 4562 2013-01-21 02:58:59Z khaled $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luatoken.w $";
+
#include "ptexlib.h"
#include "lua/luatex-api.h"
-static const char _svn_version[] =
- "$Id: luatoken.w 3849 2010-09-01 09:10:48Z taco $ "
-"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luatoken.w $";
-
@ @c
command_item command_names[] = {
{"relax", relax_cmd, NULL},
@@ -101,7 +101,6 @@ command_item command_names[] = {
{"assign_local_box", assign_local_box_cmd, NULL},
{"char_given", char_given_cmd, NULL},
{"math_given", math_given_cmd, NULL},
- {"omath_given", omath_given_cmd, NULL},
{"xmath_given", xmath_given_cmd, NULL},
{"last_item", last_item_cmd, NULL},
{"toks_register", toks_register_cmd, NULL},
@@ -187,7 +186,7 @@ int get_command_id(const char *s)
static int get_cur_cmd(lua_State * L)
{
int r = 0;
- size_t len = lua_objlen(L, -1);
+ size_t len = lua_rawlen(L, -1);
cur_cs = 0;
if (len == 3 || len == 2) {
r = 1;
@@ -214,7 +213,7 @@ static int token_from_lua(lua_State * L)
{
int cmd, chr;
int cs = 0;
- size_t len = lua_objlen(L, -1);
+ size_t len = lua_rawlen(L, -1);
if (len == 3 || len == 2) {
lua_rawgeti(L, -1, 1);
cmd = (int) lua_tointeger(L, -1);
@@ -319,7 +318,7 @@ int tokenlist_from_lua(lua_State * L)
token_link(r) = null;
p = r;
if (lua_istable(L, -1)) {
- j = lua_objlen(L, -1);
+ j = lua_rawlen(L, -1);
if (j > 0) {
for (i = 1; i <= j; i++) {
lua_rawgeti(L, -1, (int) i);
@@ -337,9 +336,9 @@ int tokenlist_from_lua(lua_State * L)
if (s[i] == 32) {
tok = token_val(10, s[i]);
} else {
- int j = (int) str2uni((const unsigned char *) (s + i));
- i = i + (size_t) (utf8_size(j) - 1);
- tok = token_val(12, j);
+ int j1 = (int) str2uni((const unsigned char *) (s + i));
+ i = i + (size_t) (utf8_size(j1) - 1);
+ tok = token_val(12, j1);
}
store_new_token(tok);
}
@@ -374,7 +373,7 @@ void do_get_token_lua(int callback_id)
/* build a token list */
r = get_avail();
p = r;
- j = lua_objlen(L, -1);
+ j = lua_rawlen(L, -1);
if (j > 0) {
for (i = 1; i <= j; i++) {
lua_rawgeti(L, -1, (int) i);
diff --git a/Build/source/texk/web2c/luatexdir/lua/texluac.w b/Build/source/texk/web2c/luatexdir/lua/texluac.w
index 153ae7a8934..9b239c0f8a8 100644
--- a/Build/source/texk/web2c/luatexdir/lua/texluac.w
+++ b/Build/source/texk/web2c/luatexdir/lua/texluac.w
@@ -1,7 +1,7 @@
-% texlua.w
+% texluac.w
%
% Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
-% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
+% Copyright 2006-2013 Taco Hoekwater <taco@@luatex.org>
%
% Permission is hereby granted, free of charge, to any person obtaining
% a copy of this software and associated documentation files (the
@@ -10,10 +10,10 @@
% distribute, sublicense, and/or sell copies of the Software, and to
% permit persons to whom the Software is furnished to do so, subject to
% the following conditions:
-*
+%
% The above copyright notice and this permission notice shall be
% included in all copies or substantial portions of the Software.
-*
+%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -21,10 +21,14 @@
% CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
% TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
% SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+%
% This file is part of LuaTeX.
@ @c
+static const char _svn_version[] =
+ "$Id: texluac.w 4561 2013-01-20 21:28:09Z oneiros $"
+ "$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/texluac.w $";
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,24 +37,30 @@
#define luac_c
#define LUA_CORE
-#include "lua51/lua.h"
-#include "lua51/lauxlib.h"
+#include "lua52/lua.h"
+#include "lua52/lauxlib.h"
-#include "lua51/ldo.h"
-#include "lua51/lfunc.h"
-#include "lua51/lmem.h"
-#include "lua51/lobject.h"
-#include "lua51/lopcodes.h"
-#include "lua51/lstring.h"
-#include "lua51/lundump.h"
+#include "lua52/ldo.h"
+#include "lua52/lfunc.h"
+#include "lua52/lmem.h"
+#include "lua52/lobject.h"
+#include "lua52/lopcodes.h"
+#include "lua52/lstring.h"
+#include "lua52/lundump.h"
#include "lua/luatex-api.h"
+#include <ctype.h>
+#include <stdio.h>
-@ @c
-static const char _svn_version[] =
- "$Id: texluac.w 3707 2010-05-28 13:24:16Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/texluac.w $";
+#include "ldebug.h"
+#include "lobject.h"
+#include "lopcodes.h"
+static void PrintFunction(const Proto* f, int full);
+#define luaU_print PrintFunction
+
+@ @c
/* fix for non-gcc compilation: */
#if !defined(__GNUC__) || (__GNUC__ < 2)
# define __attribute__(x)
@@ -60,6 +70,7 @@ static const char _svn_version[] =
#define PROGNAME "texluac" /* default program name */
#define OUTPUT PROGNAME ".out" /* default output file */
+static int listing=0; /* list bytecodes? */
static int dumping = 1; /* dump bytecodes? */
static int stripping = 0; /* strip debug information? */
static char Output[] = { OUTPUT }; /* default output file name */
@@ -71,181 +82,400 @@ static const char *progname = PROGNAME; /* actual program name */
__attribute__ ((noreturn))
static void fatal(const char *message)
{
- fprintf(stderr, "%s: %s\n", progname, message);
- exit(EXIT_FAILURE);
+ fprintf(stderr,"%s: %s\n",progname,message);
+ exit(EXIT_FAILURE);
}
@ @c
__attribute__ ((noreturn))
static void cannot(const char *what)
{
- fprintf(stderr, "%s: cannot %s %s: %s\n", progname, what, output,
- strerror(errno));
- exit(EXIT_FAILURE);
+ fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
+ exit(EXIT_FAILURE);
}
@ @c
__attribute__ ((noreturn))
-static void usage(const char *message)
+static void usage(const char* message)
{
- if (*message == '-')
- fprintf(stderr, "%s: unrecognized option " LUA_QS "\n", progname,
- message);
- else
- fprintf(stderr, "%s: %s\n", progname, message);
- fprintf(stderr,
- "usage: %s [options] [filenames].\n"
- "Available options are:\n"
- " - process stdin\n"
- " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
- " -p parse only\n"
- " -s strip debug information\n"
- " -v show version information\n"
- " -- stop handling options\n", progname, Output);
- exit(EXIT_FAILURE);
+ if (*message=='-')
+ fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
+ else
+ fprintf(stderr,"%s: %s\n",progname,message);
+ fprintf(stderr,
+ "usage: %s [options] [filenames]\n"
+ "Available options are:\n"
+ " -l list (use -l -l for full listing)\n"
+ " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
+ " -p parse only\n"
+ " -s strip debug information\n"
+ " -v show version information\n"
+ " -- stop handling options\n"
+ " - stop handling options and process stdin\n"
+ ,progname,Output);
+ exit(EXIT_FAILURE);
}
@ @c
#define IS(s) (strcmp(argv[i],s)==0)
-static int doargs(int argc, char *argv[])
+static int doargs(int argc, char* argv[])
{
- int i;
- int version = 0;
- if (argv[0] != NULL && *argv[0] != 0)
- progname = argv[0];
- for (i = 1; i < argc; i++) {
- if (*argv[i] != '-') /* end of options; keep it */
- break;
- else if (IS("--")) { /* end of options; skip it */
- ++i;
- if (version)
- ++version;
- break;
- } else if (IS("-")) /* end of options; use stdin */
- break;
- else if (IS("-o")) { /* output file */
- output = argv[++i];
- if (output == NULL || *output == 0)
- usage(LUA_QL("-o") " needs argument");
- if (IS("-"))
- output = NULL;
- } else if (IS("-p")) /* parse only */
- dumping = 0;
- else if (IS("-s")) /* strip debug information */
- stripping = 1;
- else if (IS("-v")) /* show version */
- ++version;
- else if (IS("--luaconly")) /* ignore */
- ;
- else if (IS("--luac")) /* ignore */
- ;
- else /* unknown option */
- usage(argv[i]);
- }
- if (i == argc && (!dumping)) {
- dumping = 0;
- argv[--i] = Output;
- }
- if (version) {
- printf("%s %s\n", LUA_RELEASE, LUA_COPYRIGHT);
- if (version == argc - 1)
- exit(EXIT_SUCCESS);
- }
- return i;
+ int i;
+ int version=0;
+ if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
+ for (i=1; i<argc; i++)
+ {
+ if (*argv[i]!='-') /* end of options; keep it */
+ break;
+ else if (IS("--")) /* end of options; skip it */
+ {
+ ++i;
+ if (version) ++version;
+ break;
+ }
+ else if (IS("-")) /* end of options; use stdin */
+ break;
+ else if (IS("-l")) /* list */
+ ++listing;
+ else if (IS("-o")) /* output file */
+ {
+ output=argv[++i];
+ if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
+ usage(LUA_QL("-o") " needs argument");
+ if (IS("-")) output=NULL;
+ }
+ else if (IS("-p")) /* parse only */
+ dumping=0;
+ else if (IS("-s")) /* strip debug information */
+ stripping=1;
+ else if (IS("-v")) /* show version */
+ ++version;
+ else /* unknown option */
+ usage(argv[i]);
+ }
+ if (i==argc && (listing || !dumping))
+ {
+ dumping=0;
+ argv[--i]=Output;
+ }
+ if (version)
+ {
+ printf("%s\n",LUA_COPYRIGHT);
+ if (version==argc-1) exit(EXIT_SUCCESS);
+ }
+ return i;
}
@ @c
-#define toproto(L,i) (clvalue(L->top+(i))->l.p)
+#define FUNCTION "(function()end)();"
-static const Proto *combine(lua_State * L, int n)
+static const char* reader(lua_State *L, void *ud, size_t *size)
{
- if (n == 1)
- return toproto(L, -1);
- else {
- int i, pc;
- Proto *f = luaF_newproto(L);
- setptvalue2s(L, L->top, f);
- incr_top(L);
- f->source = luaS_newliteral(L, "=(" PROGNAME ")");
- f->maxstacksize = 1;
- pc = 2 * n + 1;
- f->code = luaM_newvector(L, (unsigned long) pc, Instruction);
- f->sizecode = pc;
- f->p = luaM_newvector(L, (unsigned long) n, Proto *);
- f->sizep = n;
- pc = 0;
- for (i = 0; i < n; i++) {
- f->p[i] = toproto(L, i - n - 1);
- f->code[pc++] = CREATE_ABx(OP_CLOSURE, 0, i);
- f->code[pc++] = CREATE_ABC(OP_CALL, 0, 1, 1);
- }
- f->code[pc++] = CREATE_ABC(OP_RETURN, 0, 1, 0);
- return f;
- }
+ UNUSED(L);
+ if ((*(int*)ud)--)
+ {
+ *size=sizeof(FUNCTION)-1;
+ return FUNCTION;
+ }
+ else
+ {
+ *size=0;
+ return NULL;
+ }
}
-@ @c
-static int writer(lua_State * L, const void *p, size_t size, void *u)
+#define toproto(L,i) getproto(L->top+(i))
+
+static const Proto* combine(lua_State* L, int n)
{
- UNUSED(L);
- return (fwrite(p, size, 1, (FILE *) u) != 1) && (size != 0);
+ if (n==1)
+ return toproto(L,-1);
+ else
+ {
+ Proto* f;
+ int i=n;
+ if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));
+ f=toproto(L,-1);
+ for (i=0; i<n; i++)
+ {
+ f->p[i]=toproto(L,i-n-1);
+ if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
+ }
+ f->sizelineinfo=0;
+ return f;
+ }
}
@ @c
-struct Smain {
- int argc;
- char **argv;
-};
+static int writer(lua_State* L, const void* p, size_t size, void* u)
+{
+ UNUSED(L);
+ return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
+}
-@ @c
-static int pmain(lua_State * L)
+static int pmain(lua_State* L)
{
- struct Smain *s = (struct Smain *) lua_touserdata(L, 1);
- int argc = s->argc;
- char **argv = s->argv;
- const Proto *f;
- int i;
- if (!lua_checkstack(L, argc))
- fatal("too many input files");
- for (i = 0; i < argc; i++) {
- const char *filename = IS("-") ? NULL : argv[i];
- if (luaL_loadfile(L, filename) != 0)
- fatal(lua_tostring(L, -1));
- }
- f = combine(L, argc);
- if (dumping) {
- FILE *D = (output == NULL) ? stdout : fopen(output, "wb");
- if (D == NULL)
- cannot("open");
- lua_lock(L);
- luaU_dump(L, f, writer, D, stripping);
- lua_unlock(L);
- if (ferror(D))
- cannot("write");
- if (fclose(D))
- cannot("close");
- }
- return 0;
+ int argc=(int)lua_tointeger(L,1);
+ char** argv=(char**)lua_touserdata(L,2);
+ const Proto* f;
+ int i;
+ if (!lua_checkstack(L,argc)) fatal("too many input files");
+ for (i=0; i<argc; i++)
+ {
+ const char* filename=IS("-") ? NULL : argv[i];
+ if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
+ }
+ f=combine(L,argc);
+ if (listing) luaU_print(f,listing>1);
+ if (dumping)
+ {
+ FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
+ if (D==NULL) cannot("open");
+ lua_lock(L);
+ luaU_dump(L,f,writer,D,stripping);
+ lua_unlock(L);
+ if (ferror(D)) cannot("write");
+ if (fclose(D)) cannot("close");
+ }
+ return 0;
}
@ @c
-int luac_main(int argc, char *argv[])
+int luac_main(int ac, char *av[])
{
lua_State *L;
- struct Smain s;
- int i = doargs(argc, argv);
- argc -= i;
- argv += i;
- if (argc <= 0)
+ int i = doargs(ac, av);
+ ac -= i;
+ av += i;
+ if (ac <= 0)
usage("no input files given");
- L = lua_open();
+ L=luaL_newstate();
if (L == NULL)
fatal("not enough memory for state");
- s.argc = argc;
- s.argv = argv;
- if (lua_cpcall(L, pmain, &s) != 0)
- fatal(lua_tostring(L, -1));
+ lua_pushcfunction(L,&pmain);
+ lua_pushinteger(L,ac);
+ lua_pushlightuserdata(L,av);
+ if (lua_pcall(L,2,0,0)!=LUA_OK)
+ fatal(lua_tostring(L,-1));
lua_close(L);
return EXIT_SUCCESS;
}
+
+/*
+** print bytecodes
+** See Copyright Notice in lua.h
+*/
+
+#define VOID(p) ((const void*)(p))
+
+static void PrintString(const TString* ts)
+{
+ const char* s=getstr(ts);
+ size_t i,n=ts->tsv.len;
+ printf("%c",'"');
+ for (i=0; i<n; i++)
+ {
+ int c=(int)(unsigned char)s[i];
+ switch (c)
+ {
+ case '"': printf("\\\""); break;
+ case '\\': printf("\\\\"); break;
+ case '\a': printf("\\a"); break;
+ case '\b': printf("\\b"); break;
+ case '\f': printf("\\f"); break;
+ case '\n': printf("\\n"); break;
+ case '\r': printf("\\r"); break;
+ case '\t': printf("\\t"); break;
+ case '\v': printf("\\v"); break;
+ default: if (isprint(c))
+ printf("%c",c);
+ else
+ printf("\\%03d",c);
+ }
+ }
+ printf("%c",'"');
+}
+
+static void PrintConstant(const Proto* f, int i)
+{
+ const TValue* o=&f->k[i];
+ switch (ttype(o))
+ {
+ case LUA_TNIL:
+ printf("nil");
+ break;
+ case LUA_TBOOLEAN:
+ printf(bvalue(o) ? "true" : "false");
+ break;
+ case LUA_TNUMBER:
+ printf(LUA_NUMBER_FMT,nvalue(o));
+ break;
+ case LUA_TSTRING:
+ PrintString(rawtsvalue(o));
+ break;
+ default: /* cannot happen */
+ printf("? type=%d",ttype(o));
+ break;
+ }
+}
+
+#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
+#define MYK(x) (-1-(x))
+
+static void PrintCode(const Proto* f)
+{
+ const Instruction* code=f->code;
+ int pc,n=f->sizecode;
+ for (pc=0; pc<n; pc++)
+ {
+ Instruction i=code[pc];
+ OpCode o=GET_OPCODE(i);
+ int a=GETARG_A(i);
+ int b=GETARG_B(i);
+ int c=GETARG_C(i);
+ int ax=GETARG_Ax(i);
+ int bx=GETARG_Bx(i);
+ int sbx=GETARG_sBx(i);
+ int line=getfuncline(f,pc);
+ printf("\t%d\t",pc+1);
+ if (line>0) printf("[%d]\t",line); else printf("[-]\t");
+ printf("%-9s\t",luaP_opnames[o]);
+ switch (getOpMode(o))
+ {
+ case iABC:
+ printf("%d",a);
+ if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
+ if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
+ break;
+ case iABx:
+ printf("%d",a);
+ if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
+ if (getBMode(o)==OpArgU) printf(" %d",bx);
+ break;
+ case iAsBx:
+ printf("%d %d",a,sbx);
+ break;
+ case iAx:
+ printf("%d",MYK(ax));
+ break;
+ }
+ switch (o)
+ {
+ case OP_LOADK:
+ printf("\t; "); PrintConstant(f,bx);
+ break;
+ case OP_GETUPVAL:
+ case OP_SETUPVAL:
+ printf("\t; %s",UPVALNAME(b));
+ break;
+ case OP_GETTABUP:
+ printf("\t; %s",UPVALNAME(b));
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABUP:
+ printf("\t; %s",UPVALNAME(a));
+ if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_GETTABLE:
+ case OP_SELF:
+ if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABLE:
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV:
+ case OP_POW:
+ case OP_EQ:
+ case OP_LT:
+ case OP_LE:
+ if (ISK(b) || ISK(c))
+ {
+ printf("\t; ");
+ if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
+ printf(" ");
+ if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
+ }
+ break;
+ case OP_JMP:
+ case OP_FORLOOP:
+ case OP_FORPREP:
+ case OP_TFORLOOP:
+ printf("\t; to %d",sbx+pc+2);
+ break;
+ case OP_CLOSURE:
+ printf("\t; %p",VOID(f->p[bx]));
+ break;
+ case OP_SETLIST:
+ if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
+ break;
+ case OP_EXTRAARG:
+ printf("\t; "); PrintConstant(f,ax);
+ break;
+ default:
+ break;
+ }
+ printf("\n");
+ }
+}
+
+#define SS(x) ((x==1)?"":"s")
+#define S(x) (int)(x),SS(x)
+
+static void PrintHeader(const Proto* f)
+{
+ const char* s=f->source ? getstr(f->source) : "=?";
+ if (*s=='@@' || *s=='=')
+ s++;
+ else if (*s==LUA_SIGNATURE[0])
+ s="(bstring)";
+ else
+ s="(string)";
+ printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
+ (f->linedefined==0)?"main":"function",s,
+ f->linedefined,f->lastlinedefined,
+ S(f->sizecode),VOID(f));
+ printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
+ (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams),
+ S(f->maxstacksize),S(f->sizeupvalues));
+ printf("%d local%s, %d constant%s, %d function%s\n",
+ S(f->sizelocvars),S(f->sizek),S(f->sizep));
+}
+
+static void PrintDebug(const Proto* f)
+{
+ int i,n;
+ n=f->sizek;
+ printf("constants (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t",i+1);
+ PrintConstant(f,i);
+ printf("\n");
+ }
+ n=f->sizelocvars;
+ printf("locals (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t%s\t%d\t%d\n",
+ i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
+ }
+ n=f->sizeupvalues;
+ printf("upvalues (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t%s\t%d\t%d\n",
+ i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);
+ }
+}
+
+static void PrintFunction(const Proto* f, int full)
+{
+ int i,n=f->sizep;
+ PrintHeader(f);
+ PrintCode(f);
+ if (full) PrintDebug(f);
+ for (i=0; i<n; i++) PrintFunction(f->p[i],full);
+}