1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* LSPIPAT - LUA SPIPAT WRAPPER
* Copyright (C) 2010, Robin Haberkorn
* License: LGPL
*/
#ifndef _LSPIPAT_H
#define _LSPIPAT_H
#ifdef HAVE_LUA5_1_LUA_H
#include <lua5.1/lua.h>
#include <lua5.1/lauxlib.h>
#include <lua5.1/lualib.h>
#else
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#endif
#include <stdint.h>
#include <stdbool.h>
#include <spipat.h>
#if defined(HAVE_SPIPAT_IMPL_H) && defined(HAVE_SPIPAT_IMAGE_H)
#define USE_SPIPAT_IMAGE_CUSTOM
#include <spipat_impl.h>
#include <spipat_image.h>
#endif
#define VSTRING_INITIALIZER {NULL, 0, NULL, NULL}
/* Lua error raising */
#define L_ALLOC "Allocation error"
#define L_MISC "Miscellaneous error"
#define L_TYPE "Invalid type"
#define L_NUMBER "Invalid number of parameters"
#define L_VALUE "Invalid value for this parameter"
#define L_FREED "Pattern already freed"
#define L_RETURN "Invalid return value"
#define L_ERROR(MSG, ...) do { \
luaL_error(L, MSG "\n", ##__VA_ARGS__); \
} while (0) /* return omitted, so it works for all functions */
/* metatables */
#define PATTERN_MT "SPIPAT.PATTERN_MT"
/* structures */
typedef struct {
const char *lua;
int c;
} LUA_CONSTANT;
struct cbRefs { /* wraps references necessary for callbacks */
lua_State *L;
int function;
int cookie; /* local cookie */
};
typedef struct {
struct pat *pattern;
enum { /* Lua reference classes of patterns */
PATTERN_OTHER = 0,
PATTERN_ONESUBPAT,
PATTERN_TWOSUBPAT,
PATTERN_CALL,
PATTERN_RETFNC,
PATTERN_SIMPLEFNC
} type;
union { /* references to control garbage collection */
struct onesubpatRefs {
int pattern;
} onesubpat;
struct twosubpatRefs {
int pattern1;
int pattern2;
} twosubpat;
struct callRefs {
int pattern;
struct cbRefs cb;
} call;
struct retfncRefs {
struct cbRefs cb;
int ret;
} retfnc;
struct simplefncRefs {
struct cbRefs cb;
} simplefnc;
} u;
} PATTERN_WRAPPER;
/* Lua functions */
#define LUA_SIG(FNC) \
int FNC(lua_State *L)
LUA_SIG(l_smatch);
LUA_SIG(l_topattern);
LUA_SIG(l_dump);
LUA_SIG(l_tostring);
LUA_SIG(l_op_and);
LUA_SIG(l_op_or);
LUA_SIG(l_op_call_immed);
LUA_SIG(l_op_call_onmatch);
LUA_SIG(l_setcur);
LUA_SIG(l_pred);
LUA_SIG(l_primitive_any);
LUA_SIG(l_primitive_break);
LUA_SIG(l_primitive_breakx);
LUA_SIG(l_primitive_notany);
LUA_SIG(l_primitive_nspan);
LUA_SIG(l_primitive_span);
LUA_SIG(l_primitive_len);
LUA_SIG(l_primitive_pos);
LUA_SIG(l_primitive_rpos);
LUA_SIG(l_primitive_rtab);
LUA_SIG(l_primitive_tab);
LUA_SIG(l_primitive_abort);
LUA_SIG(l_primitive_arb);
LUA_SIG(l_primitive_bal);
LUA_SIG(l_primitive_fail);
LUA_SIG(l_primitive_rem);
LUA_SIG(l_primitive_succeed);
LUA_SIG(l_primitive_arbno);
LUA_SIG(l_primitive_fence);
void retfncUnrefRet(void *);
#endif
|