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 | |
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
-rw-r--r-- | c-api/compat-5.3.c | 3 | ||||
-rw-r--r-- | compat53.lua | 24 | ||||
-rw-r--r-- | lprefix.h | 17 |
3 files changed, 35 insertions, 9 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index ecb22b0..e45c728 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -36,7 +36,8 @@ COMPAT53_API void lua_len (lua_State *L, int i) { | |||
36 | switch (lua_type(L, i)) { | 36 | switch (lua_type(L, i)) { |
37 | case LUA_TSTRING: /* fall through */ | 37 | case LUA_TSTRING: /* fall through */ |
38 | case LUA_TTABLE: | 38 | case LUA_TTABLE: |
39 | lua_pushnumber(L, (int)lua_objlen(L, i)); | 39 | if (!luaL_callmeta(L, i, "__len")) |
40 | lua_pushnumber(L, (int)lua_objlen(L, i)); | ||
40 | break; | 41 | break; |
41 | case LUA_TUSERDATA: | 42 | case LUA_TUSERDATA: |
42 | if (luaL_callmeta(L, i, "__len")) | 43 | if (luaL_callmeta(L, i, "__len")) |
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 |
@@ -52,5 +52,22 @@ | |||
52 | # define luaopen_utf8 luaopen_compat53_utf8 | 52 | # define luaopen_utf8 luaopen_compat53_utf8 |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | #ifdef ltablib_c | ||
56 | # define luaopen_table luaopen_compat53_table | ||
57 | static int compat53_rawgeti (lua_State *L, int i, lua_Integer n) { | ||
58 | return lua_rawgeti(L, i, n); | ||
59 | } | ||
60 | # undef lua_rawgeti | ||
61 | # define lua_rawgeti compat53_rawgeti | ||
62 | static void compat53_rawseti (lua_State *L, int i, lua_Integer n) { | ||
63 | lua_rawseti(L, i, (int)n); | ||
64 | } | ||
65 | # undef lua_rawseti | ||
66 | # define lua_rawseti compat53_rawseti | ||
67 | # if LUA_VERSION_NUM == 501 | ||
68 | # define lua_compare(L, a, b, op) lua_lessthan(L, a, b) | ||
69 | # endif | ||
70 | #endif /* ltablib_c */ | ||
71 | |||
55 | #endif | 72 | #endif |
56 | 73 | ||