1
/* $Id: luanode.c 1013 2008-02-14 00:09:02Z oneiros $ */
3
Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
5
This file is part of LuaTeX.
7
LuaTeX is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 2 of the License, or (at your
10
option) any later version.
12
LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU General Public License along
18
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
3
20
#include "luatex-api.h"
4
21
#include <ptexlib.h>
7
#undef link /* defined by cpascal.h */
24
static const char _svn_version[] =
25
"$Id: luanode.c 1226 2008-05-02 16:11:02Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/tags/beta-0.28.0/src/texk/web2c/luatexdir/lua/luanode.c $";
27
#undef link /* defined by cpascal.h */
8
28
#define info(a) fixmem[(a)].hhlh
9
29
#define link(a) fixmem[(a)].hhrh
12
32
static char *group_code_names[] = {
37
char *pack_type_name[] = { "exactly", "additional"};
41
lua_node_filter_s (int filterid, char *extrainfo, halfword head_node, halfword *tail_node) {
44
lua_State *L = Luas[0];
45
int callback_id = callback_defined(filterid);
46
if (head_node==null || vlink(head_node)==null || callback_id==0)
48
lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
49
lua_rawgeti(L,-1, callback_id);
50
if (!lua_isfunction(L,-1)) {
54
nodelist_to_lua(L,vlink(head_node)); /* arg 1 */
55
lua_pushstring(L,extrainfo); /* arg 2 */
56
if (lua_pcall(L,2,1,0) != 0) { /* no arg, 1 result */
57
fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
62
if (lua_isboolean(L,-1)) {
63
if (lua_toboolean(L,-1)!=1) {
64
flush_node_list(vlink(head_node));
65
vlink(head_node) = null;
68
a = nodelist_from_lua(L);
71
lua_pop(L,2); /* result and callback container table */
73
fix_node_list(head_node);
74
ret = vlink(head_node);
76
while (vlink(ret)!=null)
86
lua_node_filter (int filterid, int extrainfo, halfword head_node, halfword *tail_node) {
87
lua_node_filter_s(filterid, group_code_names[extrainfo], head_node, tail_node);
94
lua_hpack_filter (halfword head_node, scaled size, int pack_type, int extrainfo) {
96
lua_State *L = Luas[0];
97
int callback_id = callback_defined(hpack_filter_callback);
98
if (head_node==null || callback_id == 0)
100
lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
101
lua_rawgeti(L,-1, callback_id);
102
if (!lua_isfunction(L,-1)) {
107
nodelist_to_lua(L,head_node);
108
lua_pushstring(L,group_code_names[extrainfo]);
109
lua_pushnumber(L,size);
110
lua_pushstring(L,pack_type_name[pack_type]);
111
if (lua_pcall(L,4,1,0) != 0) { /* no arg, 1 result */
112
fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
118
if (lua_isboolean(L,-1)) {
119
if (lua_toboolean(L,-1)!=1) {
120
flush_node_list(head_node);
124
ret = nodelist_from_lua(L);
126
lua_pop(L,2); /* result and callback container table */
127
/* lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE);*/
134
lua_vpack_filter (halfword head_node, scaled size, int pack_type, scaled maxd, int extrainfo) {
136
integer callback_id ;
137
lua_State *L = Luas[0];
140
if (strcmp("output",group_code_names[extrainfo])==0) {
141
callback_id = callback_defined(pre_output_filter_callback);
143
callback_id = callback_defined(vpack_filter_callback);
145
if (callback_id==0) {
148
lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
149
lua_rawgeti(L,-1, callback_id);
150
if (!lua_isfunction(L,-1)) {
154
nodelist_to_lua(L,head_node);
155
lua_pushstring(L,group_code_names[extrainfo]);
156
lua_pushnumber(L,size);
157
lua_pushstring(L,pack_type_name[pack_type]);
158
lua_pushnumber(L,maxd);
159
if (lua_pcall(L,5,1,0) != 0) { /* no arg, 1 result */
160
fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
166
if (lua_isboolean(L,-1)) {
167
if (lua_toboolean(L,-1)!=1) {
168
flush_node_list(head_node);
172
ret = nodelist_from_lua(L);
174
lua_pop(L,2); /* result and callback container table */
175
/* lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE);*/
58
char *pack_type_name[] = { "exactly", "additional" };
62
lua_node_filter_s(int filterid, char *extrainfo, halfword head_node,
67
lua_State *L = Luas[0];
68
int callback_id = callback_defined(filterid);
69
if (head_node == null || vlink(head_node) == null || callback_id == 0)
71
lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
72
lua_rawgeti(L, -1, callback_id);
73
if (!lua_isfunction(L, -1)) {
77
nodelist_to_lua(L, vlink(head_node)); /* arg 1 */
78
lua_pushstring(L, extrainfo); /* arg 2 */
79
if (lua_pcall(L, 2, 1, 0) != 0) { /* no arg, 1 result */
80
fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
85
if (lua_isboolean(L, -1)) {
86
if (lua_toboolean(L, -1) != 1) {
87
flush_node_list(vlink(head_node));
88
vlink(head_node) = null;
91
a = nodelist_from_lua(L);
94
lua_pop(L, 2); /* result and callback container table */
96
fix_node_list(head_node);
97
ret = vlink(head_node);
99
while (vlink(ret) != null)
103
*tail_node = head_node;
109
lua_node_filter(int filterid, int extrainfo, halfword head_node,
110
halfword * tail_node)
112
lua_node_filter_s(filterid, group_code_names[extrainfo], head_node,
120
lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo)
123
lua_State *L = Luas[0];
124
int callback_id = callback_defined(hpack_filter_callback);
125
if (head_node == null || callback_id == 0)
127
lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
128
lua_rawgeti(L, -1, callback_id);
129
if (!lua_isfunction(L, -1)) {
134
nodelist_to_lua(L, head_node);
135
lua_pushstring(L, group_code_names[extrainfo]);
136
lua_pushnumber(L, size);
137
lua_pushstring(L, pack_type_name[pack_type]);
138
if (lua_pcall(L, 4, 1, 0) != 0) { /* no arg, 1 result */
139
fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
145
if (lua_isboolean(L, -1)) {
146
if (lua_toboolean(L, -1) != 1) {
147
flush_node_list(head_node);
151
ret = nodelist_from_lua(L);
153
lua_pop(L, 2); /* result and callback container table */
154
/* lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); */
161
lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd,
166
lua_State *L = Luas[0];
167
if (head_node == null)
169
if (strcmp("output", group_code_names[extrainfo]) == 0) {
170
callback_id = callback_defined(pre_output_filter_callback);
172
callback_id = callback_defined(vpack_filter_callback);
174
if (callback_id == 0) {
177
lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
178
lua_rawgeti(L, -1, callback_id);
179
if (!lua_isfunction(L, -1)) {
183
nodelist_to_lua(L, head_node);
184
lua_pushstring(L, group_code_names[extrainfo]);
185
lua_pushnumber(L, size);
186
lua_pushstring(L, pack_type_name[pack_type]);
187
lua_pushnumber(L, maxd);
188
if (lua_pcall(L, 5, 1, 0) != 0) { /* no arg, 1 result */
189
fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
195
if (lua_isboolean(L, -1)) {
196
if (lua_toboolean(L, -1) != 1) {
197
flush_node_list(head_node);
201
ret = nodelist_from_lua(L);
203
lua_pop(L, 2); /* result and callback container table */
204
/* lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); */