-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- lua-hyperscan, Lua bindings to hyperscan | ||
-- Copyright (C) 2015 Boris Nagaev | ||
-- See the LICENSE file for terms of use. | ||
|
||
package = "hyperscan" | ||
version = "dev-1" | ||
source = { | ||
url = "git://github.com/starius/lua-hyperscan.git", | ||
} | ||
description = { | ||
summary = "Lua bindings to hyperscan", | ||
homepage = "https://github.com/starius/lua-hyperscan", | ||
license = "BSD 3-clause", | ||
detailed = [[ | ||
Lua bindings to hyperscan. | ||
Hyperscan is high-performanceregular expression matching library. | ||
]], | ||
} | ||
dependencies = { | ||
"lua >= 5.1", | ||
} | ||
external_dependencies = { | ||
HS = { | ||
header = "hs/hs.h" | ||
}, | ||
} | ||
build = { | ||
type = "builtin", | ||
modules = { | ||
['hyperscan'] = { | ||
sources = { | ||
"src/hyperscan/constants.c", | ||
--"src/hyperscan/functions.c", | ||
"src/hyperscan/hyperscan.c", | ||
}, | ||
incdirs = {"$(HS_INCDIR)"}, | ||
libdirs = {"$(HS_LIBDIR)"}, | ||
libraries = {"hs"}, | ||
}, | ||
}, | ||
platforms = { | ||
unix = { | ||
modules = { | ||
['hyperscan'] = { | ||
libraries = {"stdc++", "m"}, | ||
}, | ||
}, | ||
}, | ||
mingw32 = { | ||
modules = { | ||
['hyperscan'] = { | ||
libraries = {"stdc++", "m"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// lua-hyperscan, Lua bindings to hyperscan | ||
// Copyright (C) 2015 Boris Nagaev | ||
// See the LICENSE file for terms of use. | ||
|
||
#include "hyperscan.h" | ||
|
||
typedef struct Constant { | ||
int value; | ||
const char* name; | ||
} Constant; | ||
|
||
typedef struct Namespace { | ||
const Constant* constants; | ||
const char* name; | ||
} Namespace; | ||
|
||
#define ITEM(c) {c, #c} | ||
|
||
static const Constant errors[] = { | ||
ITEM(HS_SUCCESS), | ||
ITEM(HS_INVALID), | ||
ITEM(HS_NOMEM), | ||
ITEM(HS_SCAN_TERMINATED), | ||
ITEM(HS_COMPILER_ERROR), | ||
ITEM(HS_DB_VERSION_ERROR), | ||
ITEM(HS_DB_PLATFORM_ERROR), | ||
ITEM(HS_DB_MODE_ERROR), | ||
ITEM(HS_BAD_ALIGN), | ||
ITEM(HS_BAD_ALLOC), | ||
{}, | ||
}; | ||
|
||
static const Constant extended_parameters[] = { | ||
ITEM(HS_EXT_FLAG_MIN_OFFSET), | ||
ITEM(HS_EXT_FLAG_MAX_OFFSET), | ||
ITEM(HS_EXT_FLAG_MIN_LENGTH), | ||
{}, | ||
}; | ||
|
||
static const Constant pattern_flags[] = { | ||
ITEM(HS_FLAG_CASELESS), | ||
ITEM(HS_FLAG_DOTALL), | ||
ITEM(HS_FLAG_MULTILINE), | ||
ITEM(HS_FLAG_SINGLEMATCH), | ||
ITEM(HS_FLAG_ALLOWEMPTY), | ||
ITEM(HS_FLAG_UTF8), | ||
ITEM(HS_FLAG_UCP), | ||
ITEM(HS_FLAG_PREFILTER), | ||
ITEM(HS_FLAG_SOM_LEFTMOST), | ||
{}, | ||
}; | ||
|
||
static const Constant cpu_features[] = { | ||
ITEM(HS_CPU_FEATURES_AVX2), | ||
{}, | ||
}; | ||
|
||
static const Constant cpu_tuning[] = { | ||
ITEM(HS_TUNE_FAMILY_GENERIC), | ||
ITEM(HS_TUNE_FAMILY_SNB), | ||
ITEM(HS_TUNE_FAMILY_IVB), | ||
ITEM(HS_TUNE_FAMILY_HSW), | ||
ITEM(HS_TUNE_FAMILY_SLM), | ||
ITEM(HS_TUNE_FAMILY_BDW), | ||
{}, | ||
}; | ||
|
||
static const Constant compile_mode[] = { | ||
ITEM(HS_MODE_BLOCK), | ||
ITEM(HS_MODE_NOSTREAM), | ||
ITEM(HS_MODE_STREAM), | ||
ITEM(HS_MODE_VECTORED), | ||
ITEM(HS_MODE_SOM_HORIZON_LARGE), | ||
ITEM(HS_MODE_SOM_HORIZON_MEDIUM), | ||
ITEM(HS_MODE_SOM_HORIZON_SMALL), | ||
{}, | ||
}; | ||
|
||
static const Namespace namespaces[] = { | ||
ITEM(errors), | ||
ITEM(extended_parameters), | ||
ITEM(pattern_flags), | ||
ITEM(cpu_features), | ||
ITEM(cpu_tuning), | ||
ITEM(compile_mode), | ||
{}, | ||
}; | ||
|
||
#undef ITEM | ||
|
||
static void pushConstants(lua_State* L, const Constant* constants) { | ||
int length = 0; | ||
const Constant* it; | ||
// determine length | ||
for (it = constants; it->name != NULL; it++) { | ||
length += 1; | ||
} | ||
lua_createtable(L, 0, length); | ||
// fill table | ||
for (it = constants; it->name != NULL; it++) { | ||
lua_pushinteger(L, it->value); | ||
lua_setfield(L, -2, it->name); | ||
} | ||
} | ||
|
||
void createConstantsTable(lua_State* L) { | ||
int length = 0; | ||
const Namespace* it; | ||
// determine length | ||
for (it = namespaces; it->name != NULL; it++) { | ||
length += 1; | ||
} | ||
lua_createtable(L, 0, length); | ||
// fill table | ||
for (it = namespaces; it->name != NULL; it++) { | ||
pushConstants(L, it->constants); | ||
lua_setfield(L, -2, it->name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// lua-hyperscan, Lua bindings to hyperscan | ||
// Copyright (C) 2015 Boris Nagaev | ||
// See the LICENSE file for terms of use. | ||
|
||
#include "hyperscan.h" | ||
|
||
int luaopen_hyperscan(lua_State* L) { | ||
lua_newtable(L); // module "hyperscan" | ||
createConstantsTable(L); | ||
lua_setfield(L, -2, "constants"); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// lua-hyperscan, Lua bindings to hyperscan | ||
// Copyright (C) 2015 Boris Nagaev | ||
// See the LICENSE file for terms of use. | ||
|
||
#ifndef LUA_HS_H_ | ||
#define LUA_HS_H_ | ||
|
||
#include <hs/hs.h> | ||
#include <lua.h> | ||
|
||
void createConstantsTable(lua_State* L); | ||
|
||
#endif |