diff options
author | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-08-06 08:44:51 +0300 |
---|---|---|
committer | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-08-06 08:44:51 +0300 |
commit | 0ef80eeb34fd4d1ce6ee46b881b6074be39ebb92 (patch) | |
tree | b58a6d1935855e56d48a4102d2d7793137807711 /src | |
parent | 896b84505311c5bf08d8f743403de65e47c46437 (diff) | |
download | lrexlib-0ef80eeb34fd4d1ce6ee46b881b6074be39ebb92.tar.gz |
Accept non-string subjects with no __len metamethod in Lua 5.1.
Diffstat (limited to 'src')
-rw-r--r-- | src/algo.h | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -135,12 +135,14 @@ static void check_subject (lua_State *L, int pos, TArgExec *argE) argE->text = lua_touserdata (L, -1); lua_pop (L, 1); #if LUA_VERSION_NUM == 501 - if (!luaL_callmeta (L, pos, "__len")) - luaL_argerror (L, pos, "subject has no valid __len metamethod"); - if (lua_type (L, -1) != LUA_TNUMBER) - luaL_argerror (L, pos, "subject's length is not a number"); - argE->textlen = lua_tointeger (L, -1); - lua_pop (L, 1); + if (luaL_callmeta (L, pos, "__len")) { + if (lua_type (L, -1) != LUA_TNUMBER) + luaL_argerror (L, pos, "subject's length is not a number"); + argE->textlen = lua_tointeger (L, -1); + lua_pop (L, 1); + } + else + argE->textlen = lua_objlen (L, pos); #else argE->textlen = luaL_len (L, pos); #endif |