diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2015-01-19 19:12:24 +0100 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2015-01-19 19:12:24 +0100 |
| commit | f7f85b0826f7006b8dcc040111cd0ef8d42c2352 (patch) | |
| tree | 504dc073a89e2b5483aabb0778db6c438d15ed6d /compat53.lua | |
| parent | 6a55913a7f53d16e65f23a7c4e5ac7c2edfbf47a (diff) | |
| download | lua-compat-5.3-f7f85b0826f7006b8dcc040111cd0ef8d42c2352.tar.gz lua-compat-5.3-f7f85b0826f7006b8dcc040111cd0ef8d42c2352.tar.bz2 lua-compat-5.3-f7f85b0826f7006b8dcc040111cd0ef8d42c2352.zip | |
prepare to use ltablib.c from 5.3 for table library
Diffstat (limited to 'compat53.lua')
| -rw-r--r-- | compat53.lua | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/compat53.lua b/compat53.lua index 03158f0..58e0a24 100644 --- a/compat53.lua +++ b/compat53.lua | |||
| @@ -27,8 +27,8 @@ if lua_version < "5.3" then | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | -- load utf8 library | 29 | -- load utf8 library |
| 30 | local ok, utf8lib = pcall(require, "compat53.utf8") | 30 | local utf8_ok, utf8lib = pcall(require, "compat53.utf8") |
| 31 | if ok then | 31 | if utf8_ok then |
| 32 | utf8 = utf8lib | 32 | utf8 = utf8lib |
| 33 | package.loaded["utf8"] = utf8lib | 33 | package.loaded["utf8"] = utf8lib |
| 34 | if lua_version == "5.1" then | 34 | if lua_version == "5.1" then |
| @@ -37,12 +37,20 @@ if lua_version < "5.3" then | |||
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | -- load table library | ||
| 41 | local table_ok, tablib = pcall(require, "compat53.table") | ||
| 42 | if table_ok then | ||
| 43 | table = tablib | ||
| 44 | package.loaded["table"] = tablib | ||
| 45 | end | ||
| 46 | |||
| 47 | |||
| 40 | -- use Roberto's struct module for string packing/unpacking for now | 48 | -- use Roberto's struct module for string packing/unpacking for now |
| 41 | -- maybe we'll later extract the functions from the 5.3 string | 49 | -- maybe we'll later extract the functions from the 5.3 string |
| 42 | -- library for greater compatiblity, but it uses the 5.3 buffer API | 50 | -- library for greater compatiblity, but it uses the 5.3 buffer API |
| 43 | -- which cannot easily be backported to Lua 5.1. | 51 | -- which cannot easily be backported to Lua 5.1. |
| 44 | local ok, struct = pcall(require, "struct") | 52 | local struct_ok, struct = pcall(require, "struct") |
| 45 | if ok then | 53 | if struct_ok then |
| 46 | string.pack = struct.pack | 54 | string.pack = struct.pack |
| 47 | string.packsize = struct.size | 55 | string.packsize = struct.size |
| 48 | string.unpack = struct.unpack | 56 | string.unpack = struct.unpack |
| @@ -132,8 +140,8 @@ if lua_version < "5.3" then | |||
| 132 | end | 140 | end |
| 133 | 141 | ||
| 134 | 142 | ||
| 135 | -- update table library | 143 | -- update table library (if C module not available) |
| 136 | do | 144 | if not table_ok then |
| 137 | local table_concat = table.concat | 145 | local table_concat = table.concat |
| 138 | function table.concat(list, sep, i, j) | 146 | function table.concat(list, sep, i, j) |
| 139 | local mt = gmt(list) | 147 | local mt = gmt(list) |
| @@ -298,7 +306,7 @@ if lua_version < "5.3" then | |||
| 298 | return table_unpack(list, i, j) | 306 | return table_unpack(list, i, j) |
| 299 | end | 307 | end |
| 300 | end | 308 | end |
| 301 | end | 309 | end -- update table library |
| 302 | 310 | ||
| 303 | 311 | ||
| 304 | 312 | ||
| @@ -576,7 +584,7 @@ if lua_version < "5.3" then | |||
| 576 | end | 584 | end |
| 577 | 585 | ||
| 578 | 586 | ||
| 579 | if not is_luajit52 then | 587 | if not table_ok and not is_luajit52 then |
| 580 | table.pack = function(...) | 588 | table.pack = function(...) |
| 581 | return { n = select('#', ...), ... } | 589 | return { n = select('#', ...), ... } |
| 582 | end | 590 | end |
