diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2015-01-14 03:52:56 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2015-01-14 03:52:56 +0100 |
commit | cdd787b876efe2e662ba7d6e8b9e38bf9f44bc04 (patch) | |
tree | be89d436fec1054bf1b5cdcb14ffd13579f99d34 /compat53.lua | |
parent | 8ec87cc5b2afb05fd94fe11f35e997f26804cfef (diff) | |
download | lua-compat-5.3-cdd787b876efe2e662ba7d6e8b9e38bf9f44bc04.tar.gz lua-compat-5.3-cdd787b876efe2e662ba7d6e8b9e38bf9f44bc04.tar.bz2 lua-compat-5.3-cdd787b876efe2e662ba7d6e8b9e38bf9f44bc04.zip |
add utf8 library from Lua 5.3; use struct for string packing
Diffstat (limited to 'compat53.lua')
-rw-r--r-- | compat53.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compat53.lua b/compat53.lua new file mode 100644 index 0000000..98e1a3d --- /dev/null +++ b/compat53.lua | |||
@@ -0,0 +1,24 @@ | |||
1 | local lua_version = _VERSION:sub(-3) | ||
2 | |||
3 | if lua_version ~= "5.3" then | ||
4 | |||
5 | -- load utf8 library | ||
6 | utf8 = require("compat53.utf8") | ||
7 | package.loaded["utf8"] = utf8 | ||
8 | if lua_version == "5.1" then | ||
9 | utf8.charpattern = "[%z\1-\127\194-\244][\128-\191]*" | ||
10 | end | ||
11 | |||
12 | -- use Roberto's struct module for string packing/unpacking for now | ||
13 | -- maybe we'll later extract the functions from the 5.3 string | ||
14 | -- library for greater compatiblity, but it uses the 5.3 buffer API | ||
15 | -- which cannot easily be backported to Lua 5.1. | ||
16 | local ok, struct = pcall(require, "struct") | ||
17 | if ok then | ||
18 | string.pack = struct.pack | ||
19 | string.packsize = struct.size | ||
20 | string.unpack = struct.unpack | ||
21 | end | ||
22 | |||
23 | end | ||
24 | |||