diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2015-01-22 03:46:44 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2015-01-22 03:46:44 +0100 |
commit | 665c3b6ef1e8ff795637a4362201eb87450ffb86 (patch) | |
tree | 3ff85ebcd95a019fb1c38d992db5e9d15b05cfea /lprefix.h | |
parent | eec3f9e44bee334542348bdd1d428417e22ed5e5 (diff) | |
download | lua-compat-5.3-665c3b6ef1e8ff795637a4362201eb87450ffb86.tar.gz lua-compat-5.3-665c3b6ef1e8ff795637a4362201eb87450ffb86.tar.bz2 lua-compat-5.3-665c3b6ef1e8ff795637a4362201eb87450ffb86.zip |
hack around %U format in lutf8lib.c
Diffstat (limited to 'lprefix.h')
-rw-r--r-- | lprefix.h | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -48,8 +48,37 @@ | |||
48 | #undef LUAMOD_API | 48 | #undef LUAMOD_API |
49 | #define LUAMOD_API extern | 49 | #define LUAMOD_API extern |
50 | 50 | ||
51 | #ifndef luaopen_utf8 | 51 | #ifdef lutf8lib_c |
52 | # define luaopen_utf8 luaopen_compat53_utf8 | 52 | # define luaopen_utf8 luaopen_compat53_utf8 |
53 | # include <stdarg.h> | ||
54 | /* we don't support the %U format string of lua_pushfstring! | ||
55 | * code below adapted from the Lua 5.3 sources: | ||
56 | */ | ||
57 | static const char *compat53_utf8_escape (lua_State* L, ...) { | ||
58 | long x = 0; | ||
59 | va_list argp; | ||
60 | va_start(argp, L); | ||
61 | x = (long)va_arg(argp, long); | ||
62 | va_end(argp); | ||
63 | if (x < 0x80) { /* ASCII */ | ||
64 | char c = (char)x; | ||
65 | lua_pushlstring(L, &c, 1); | ||
66 | } else { | ||
67 | char buff[8] = { 0 }; | ||
68 | unsigned int mfb = 0x3f; | ||
69 | int n = 1; | ||
70 | do { | ||
71 | buff[8 - (n++)] = (char)(0x80|(x & 0x3f)); | ||
72 | x >>= 6; | ||
73 | mfb >>= 1; | ||
74 | } while (x > mfb); | ||
75 | buff[8-n] = (char)((~mfb << 1) | x); | ||
76 | lua_pushlstring(L, buff+8-n, n); | ||
77 | } | ||
78 | return lua_tostring(L, -1); | ||
79 | } | ||
80 | # define lua_pushfstring(L, fmt, l) \ | ||
81 | compat53_utf8_escape(L, l) | ||
53 | #endif | 82 | #endif |
54 | 83 | ||
55 | #ifdef ltablib_c | 84 | #ifdef ltablib_c |