diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2008-04-18 12:27:06 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2008-04-18 12:27:06 +0000 |
commit | a94278f9e2c781a67d137e0df26c35592f60cb0b (patch) | |
tree | c867f5400348fc8b5a559ee5d744e33bd9622d70 /Build/source/texk/web2c/luatexdir/lua/lpdflib.c | |
parent | 5e63f0508a830d7b182b384935a1377f9031e619 (diff) |
luatex 0.25.3
git-svn-id: svn://tug.org/texlive/trunk@7494 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/lpdflib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/lpdflib.c | 121 |
1 files changed, 68 insertions, 53 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index 9cf847c84c8..393409b0729 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -1,23 +1,23 @@ -/* $Id: lpdflib.c 1013 2008-02-14 00:09:02Z oneiros $ */ +/* $Id: lpdflib.c 1154 2008-04-13 22:36:03Z oneiros $ */ #include "luatex-api.h" #include <ptexlib.h> -static int -findcurv (lua_State *L) { - int j; - j = get_cur_v(); - lua_pushnumber(L, j); - return 1; +static int findcurv(lua_State * L) +{ + int j; + j = get_cur_v(); + lua_pushnumber(L, j); + return 1; } -static int -findcurh (lua_State *L) { - int j; - j = get_cur_h(); - lua_pushnumber(L, j); - return 1; +static int findcurh(lua_State * L) +{ + int j; + j = get_cur_h(); + lua_pushnumber(L, j); + return 1; } @@ -26,7 +26,8 @@ typedef enum { set_origin, direct_page, direct_always } pdf_lit_mode; int luapdfprint(lua_State * L) { int n; - unsigned i, len; + unsigned i; + size_t len; const char *outputstr, *st; pdf_lit_mode literal_mode; n = lua_gettop(L); @@ -46,13 +47,12 @@ int luapdfprint(lua_State * L) else if (strcmp(outputstr, "page") == 0) literal_mode = direct_page; else { - lua_pushstring(L, - "invalid argument for print literal mode"); + lua_pushstring(L, "invalid argument for print literal mode"); lua_error(L); } } } else { - if (n != 1) { + if (n != 1) { lua_pushstring(L, "invalid number of arguments"); lua_error(L); } @@ -71,57 +71,72 @@ int luapdfprint(lua_State * L) default: assert(0); } - st = lua_tolstring(L, n,&len); + st = lua_tolstring(L, n, &len); for (i = 0; i < len; i++) { - if (i%16 == 0) - pdfroom(16); - pdf_buf[pdf_ptr++] = st[i]; + if (i % 16 == 0) + pdfroom(16); + pdf_buf[pdf_ptr++] = st[i]; } return 0; } -static int -getpdf (lua_State *L) { - char *st; - if (lua_isstring(L,2)) { - st = (char *)lua_tostring(L,2); - if (st && *st) { - if (*st == 'h') - return findcurh(L); - else if (*st == 'v') - return findcurv(L); +#define obj_type_others 0 + +static int l_immediateobj(lua_State * L) +{ + if (!lua_isstring(L, -1)) + luaL_error(L, "pdf.immediateobj needs string value"); + pdf_create_obj(obj_type_others, 0); + pdf_begin_obj(obj_ptr, 1); + pdf_printf("%s\n", lua_tostring(L, -1)); + pdf_end_obj(); + lua_pop(L, 1); + lua_pushinteger(L, obj_ptr); + return 1; +} + +static int getpdf(lua_State * L) +{ + char *st; + if (lua_isstring(L, 2)) { + st = (char *) lua_tostring(L, 2); + if (st && *st) { + if (*st == 'h') + return findcurh(L); + else if (*st == 'v') + return findcurv(L); + } } - } - lua_pushnil(L); - return 1; + lua_pushnil(L); + return 1; } -static int -setpdf (lua_State *L) { - return (L==NULL ? 0 : 0); /* for -Wall */ +static int setpdf(lua_State * L) +{ + return (L == NULL ? 0 : 0); /* for -Wall */ } static const struct luaL_reg pdflib[] = { {"print", luapdfprint}, + {"immediateobj", l_immediateobj}, {NULL, NULL} /* sentinel */ }; -int -luaopen_pdf (lua_State *L) { - luaL_register(L, "pdf", pdflib); - /* build meta table */ - luaL_newmetatable(L,"pdf_meta"); - lua_pushstring(L, "__index"); - lua_pushcfunction(L, getpdf); - /* do these later, NYI */ - if (0) { +int luaopen_pdf(lua_State * L) +{ + luaL_register(L, "pdf", pdflib); + /* build meta table */ + luaL_newmetatable(L, "pdf_meta"); + lua_pushstring(L, "__index"); + lua_pushcfunction(L, getpdf); + /* do these later, NYI */ + if (0) { + lua_settable(L, -3); + lua_pushstring(L, "__newindex"); + lua_pushcfunction(L, setpdf); + } lua_settable(L, -3); - lua_pushstring(L, "__newindex"); - lua_pushcfunction(L, setpdf); - } - lua_settable(L, -3); - lua_setmetatable(L,-2); /* meta to itself */ - return 1; + lua_setmetatable(L, -2); /* meta to itself */ + return 1; } - |