Created
May 16, 2012 09:07
-
-
Save starwing/2708924 to your computer and use it in GitHub Desktop.
Patch to makes slnunico compatible with Lua 5.2
This file contains hidden or 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
diff --git a/slnunico.c b/slnunico.c | |
index bc1124b..22efb00 100644 | |
--- a/slnunico.c | |
+++ b/slnunico.c | |
@@ -94,6 +94,9 @@ http://www.unicode.org/Public/UNIDATA/PropList.txt | |
# define SLN_UNICODENAME "unicode" | |
#endif | |
+#if LUA_VERSION_NUM < 502 | |
+# define luaL_setfuncs(L,l,nup) luaI_openlib(L,NULL,l,nup) | |
+#endif | |
#include "slnudata.c" | |
#define charinfo(c) (~0xFFFF&(c) ? 0 : GetUniCharInfo(c)) /* BMP only */ | |
@@ -429,6 +432,49 @@ static int str_dump (lua_State *L) { | |
*/ | |
+/* | |
+** maximum number of captures that a pattern can do during | |
+** pattern-matching. This limit is arbitrary. | |
+*/ | |
+#if !defined(LUA_MAXCAPTURES) | |
+#define LUA_MAXCAPTURES 32 | |
+#endif | |
+ | |
+/* | |
+** LUA_INTFRMLEN is the length modifier for integer conversions in | |
+** 'string.format'; LUA_INTFRM_T is the integer type corresponding to | |
+** the previous length | |
+*/ | |
+#if !defined(LUA_INTFRMLEN) /* { */ | |
+#if defined(LUA_USE_LONGLONG) | |
+ | |
+#define LUA_INTFRMLEN "ll" | |
+#define LUA_INTFRM_T long long | |
+ | |
+#else | |
+ | |
+#define LUA_INTFRMLEN "l" | |
+#define LUA_INTFRM_T long | |
+ | |
+#endif | |
+#endif /* } */ | |
+ | |
+#define MAX_UINTFRM ((lua_Number)(~(unsigned LUA_INTFRM_T)0)) | |
+#define MAX_INTFRM ((lua_Number)((~(unsigned LUA_INTFRM_T)0)/2)) | |
+#define MIN_INTFRM (-(lua_Number)((~(unsigned LUA_INTFRM_T)0)/2) - 1) | |
+ | |
+/* | |
+** LUA_FLTFRMLEN is the length modifier for float conversions in | |
+** 'string.format'; LUA_FLTFRM_T is the float type corresponding to | |
+** the previous length | |
+*/ | |
+#if !defined(LUA_FLTFRMLEN) | |
+ | |
+#define LUA_FLTFRMLEN "" | |
+#define LUA_FLTFRM_T double | |
+ | |
+#endif | |
+ | |
#define CAP_UNFINISHED (-1) | |
#define CAP_POSITION (-2) | |
@@ -1282,7 +1328,7 @@ int ext_uni_match ( void *state, const char *s, size_t n, | |
} | |
#endif | |
-static const luaL_reg uniclib[] = { | |
+static const luaL_Reg uniclib[] = { | |
{"byte", unic_byte}, /* no cluster ! */ | |
{"char", unic_char}, | |
{"dump", str_dump}, | |
@@ -1318,12 +1364,13 @@ static void createmetatable (lua_State *L) { | |
** Open string library | |
*/ | |
LUALIB_API int luaopen_unicode (lua_State *L) { | |
- /* register unicode itself so require("unicode") works */ | |
- luaL_register(L, SLN_UNICODENAME, | |
- uniclib + (sizeof uniclib/sizeof uniclib[0] - 1)); /* empty func list */ | |
- lua_pop(L, 1); | |
- lua_pushinteger(L, MODE_ASCII); | |
- luaI_openlib(L, SLN_UNICODENAME ".ascii", uniclib, 1); | |
+ lua_newtable(L); | |
+#define PUSHLIB(mode, name) \ | |
+ ( lua_pushinteger(L, MODE_##mode), \ | |
+ luaL_setfuncs(L, uniclib, 1), \ | |
+ lua_pushvalue(L, 1), \ | |
+ lua_setfield(L, -2, #name) ) | |
+ PUSHLIB(ASCII, string); | |
#ifdef SLNUNICODE_AS_STRING | |
#if defined(LUA_COMPAT_GFIND) | |
lua_getfield(L, -1, "gmatch"); | |
@@ -1332,14 +1379,12 @@ LUALIB_API int luaopen_unicode (lua_State *L) { | |
#ifdef STRING_WITH_METAT | |
createmetatable(L); | |
#endif | |
- lua_setfield(L, LUA_GLOBALSINDEX, "string"); | |
+ lua_setglobal(L, "string"); | |
#endif | |
- lua_pushinteger(L, MODE_LATIN); | |
- luaI_openlib(L, SLN_UNICODENAME ".latin1", uniclib, 1); | |
- lua_pushinteger(L, MODE_GRAPH); | |
- luaI_openlib(L, SLN_UNICODENAME ".grapheme", uniclib, 1); | |
- lua_pushinteger(L, MODE_UTF8); | |
- luaI_openlib(L, SLN_UNICODENAME ".utf8", uniclib, 1); | |
+ PUSHLIB(LATIN, latin1); | |
+ PUSHLIB(GRAPH, grapheme); | |
+ PUSHLIB(UTF8, utf8); | |
+#undef PUSHLIB | |
#ifdef WANT_EXT_MATCH | |
{ | |
unsigned i; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment