summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShmuel Zeigerman <solomuz0@gmail.com>2012-04-06 11:32:12 +0300
committerShmuel Zeigerman <solomuz0@gmail.com>2012-04-06 11:32:12 +0300
commit9441e6762ced48005b0dd64cfafbd96ad02ef5ba (patch)
treef3b30807b6edcb047cfed09022d08d0a118a6a1b
parent20d043ccd51ae389cb189ac0c569cf9d714fbd31 (diff)
downloadlrexlib-9441e6762ced48005b0dd64cfafbd96ad02ef5ba.tar.gz
1. Define REX_CREATEGLOBALVAR only for Lua 5.1 build.
2. TRE: add macro REX_ADDWIDECHARFUNCS (undefined by default).
-rw-r--r--src/tre/ltre.c7
-rw-r--r--src/tre/ltre_w.c26
-rw-r--r--test/runtest.lua17
-rw-r--r--windows/mingw/_mingw.mak3
-rw-r--r--windows/mingw/rex_tre.mak8
5 files changed, 40 insertions, 21 deletions
diff --git a/src/tre/ltre.c b/src/tre/ltre.c
index ff5cae3..0a5275c 100644
--- a/src/tre/ltre.c
+++ b/src/tre/ltre.c
@@ -341,8 +341,9 @@ static const luaL_Reg r_functions[] = {
REX_API int REX_OPENLIB (lua_State *L)
{
alg_register(L, r_methods, r_functions, "TRE regexes");
- /* TODO: */
- /* add_wide_lib (L, 1); */
- /* add_wide_lib (L, 0); */
+#ifdef REX_ADDWIDECHARFUNCS
+ add_wide_lib (L, 1);
+ add_wide_lib (L, 0);
+#endif
return 1;
}
diff --git a/src/tre/ltre_w.c b/src/tre/ltre_w.c
index 3afe30b..ade0ab8 100644
--- a/src/tre/ltre_w.c
+++ b/src/tre/ltre_w.c
@@ -111,7 +111,7 @@ static int compile_regex (lua_State *L, const TArgComp *argC, TPosix **pud) {
if (argC->cflags & REG_NOSUB)
ud->r.re_nsub = 0;
ud->match = (regmatch_t *) Lmalloc (L, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t));
- lua_pushvalue (L, LUA_ENVIRONINDEX);
+ lua_pushvalue (L, ALG_ENVIRONINDEX);
lua_setmetatable (L, -2);
if (pud) *pud = ud;
@@ -195,7 +195,7 @@ static int split_exec (TPosix *ud, TArgExec *argE, int offset) {
ALG_NSUB(ud) + 1, ud->match, argE->eflags);
}
-static const luaL_Reg posixmeta[] = {
+static const luaL_Reg r_methods[] = {
{ "wexec", algm_exec },
{ "wfind", algm_find },
{ "wmatch", algm_match },
@@ -205,7 +205,7 @@ static const luaL_Reg posixmeta[] = {
{ NULL, NULL}
};
-static const luaL_Reg rexlib[] = {
+static const luaL_Reg r_functions[] = {
{ "wnew", algf_new },
{ "wfind", algf_find },
{ "wgmatch", algf_gmatch },
@@ -218,7 +218,25 @@ static const luaL_Reg rexlib[] = {
/* Add the library */
void add_wide_lib (lua_State *L, int methods)
{
- luaL_register(L, NULL, methods ? posixmeta : rexlib);
+ (void)alg_register;
+#if LUA_VERSION_NUM == 501
+ if (methods) {
+ lua_pushvalue(L, -2);
+ luaL_register(L, NULL, r_methods);
+ lua_pop(L, 1);
+ }
+ else
+ luaL_register(L, NULL, r_functions);
+#else
+ lua_pushvalue(L, -2);
+ if (methods) {
+ lua_pushvalue(L, -1);
+ luaL_setfuncs(L, r_methods, 1);
+ lua_pop(L, 1);
+ }
+ else
+ luaL_setfuncs(L, r_functions, 1);
+#endif
}
/* 1. When called repeatedly on the same TBuffer, its existing data
diff --git a/test/runtest.lua b/test/runtest.lua
index 54058c2..9fa38e7 100644
--- a/test/runtest.lua
+++ b/test/runtest.lua
@@ -37,18 +37,11 @@ local function test_library (libname, setfile, verbose)
end
local avail_tests = {
- gnu = { lib = "rex_gnu", "common_sets", "emacs_sets", "gnu_sets" },
- posix = { lib = "rex_posix", "common_sets", "posix_sets", },
- spencer = { lib = "rex_spencer", "common_sets", "posix_sets", "spencer_sets" },
- posix1 = { lib = "rex_posix1", "common_sets", "posix_sets", "spencer_sets" },
- tre = { lib = "rex_tre", "common_sets", "posix_sets", "spencer_sets", --[["tre_sets"]] },
- lord = { lib = "rex_lord", "common_sets", "posix_sets" },
- maddock = { lib = "rex_maddock", "common_sets", "posix_sets", },
- pcreposix = { lib = "rex_pcreposix","common_sets", "posix_sets", },
- pcre = { lib = "rex_pcre", "common_sets", "pcre_sets", "pcre_sets2", },
- pcre_nr = { lib = "rex_pcre_nr", "common_sets", "pcre_sets", "pcre_sets2", },
- pcre45 = { lib = "rex_pcre45", "common_sets", "pcre_sets", "pcre_sets2", },
- onig = { lib = "rex_onig", "common_sets", "onig_sets", }
+ gnu = { lib = "rex_gnu", "common_sets", "emacs_sets", "gnu_sets" },
+ onig = { lib = "rex_onig", "common_sets", "onig_sets", }
+ pcre = { lib = "rex_pcre", "common_sets", "pcre_sets", "pcre_sets2", },
+ spencer = { lib = "rex_spencer", "common_sets", "posix_sets", "spencer_sets" },
+ tre = { lib = "rex_tre", "common_sets", "posix_sets", "spencer_sets", --[["tre_sets"]] },
}
do
diff --git a/windows/mingw/_mingw.mak b/windows/mingw/_mingw.mak
index b1524d1..07174c1 100644
--- a/windows/mingw/_mingw.mak
+++ b/windows/mingw/_mingw.mak
@@ -15,6 +15,7 @@ ifeq ($(LUAVERSION),51)
LUADLL = lua5.1
LUAEXE = lua.exe
LUAINC = s:\progr\work\system\include\lua51
+ MYCFLAGS += -DREX_CREATEGLOBALVAR
else
INSTALLPATH = s:\exe\lib32\lua52
LUADLL = lua52
@@ -28,7 +29,7 @@ BIN = $(PROJECT).dll
BININSTALL = $(INSTALLPATH)\$(BIN)
CC = gcc
CFLAGS = -W -Wall -O2 $(INCS) -DREX_OPENLIB=luaopen_$(PROJECT) \
- -DREX_LIBNAME=\"$(PROJECT)\" -DREX_CREATEGLOBALVAR $(MYCFLAGS)
+ -DREX_LIBNAME=\"$(PROJECT)\" $(MYCFLAGS)
DEFFILE = $(PROJECT).def
EXPORTED = luaopen_$(PROJECT)
INCS = -I$(LUAINC) $(MYINCS)
diff --git a/windows/mingw/rex_tre.mak b/windows/mingw/rex_tre.mak
index 28d73ba..de7c5a3 100644
--- a/windows/mingw/rex_tre.mak
+++ b/windows/mingw/rex_tre.mak
@@ -8,11 +8,17 @@ REGEXINC = s:\progr\work\system\include
PROJECT = rex_tre
MYINCS = -I$(REGEXINC)
MYLIBS = -ltre
-# OBJ = ltre.o ltre_w.o common.o
OBJ = ltre.o common.o
PROJDIR = tre
TESTNAME = tre
+# Uncomment the following line to add wide-character functions (in alpha state).
+# ADDWIDECHARFUNCS = 1
+ifdef ADDWIDECHARFUNCS
+ OBJ += ltre_w.o
+ MYCFLAGS += -DREX_ADDWIDECHARFUNCS
+endif
+
include _mingw.mak
ltre.o : common.h algo.h