summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShmuel Zeigerman <solomuz0@gmail.com>2014-08-05 22:35:13 +0300
committerShmuel Zeigerman <solomuz0@gmail.com>2014-08-05 22:35:13 +0300
commit0087f459bac1ce6290ed6bf8f77d7150bb87899a (patch)
treeceaf85c2731b7a8835ebe5c785632dcd1c19daaf /src
parent1c83c2328a18fc40334aa0472fed17c3d2dca239 (diff)
downloadlrexlib-0087f459bac1ce6290ed6bf8f77d7150bb87899a.tar.gz
Minor refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/algo.h22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/algo.h b/src/algo.h
index 7c9d443..14a25ea 100644
--- a/src/algo.h
+++ b/src/algo.h
@@ -135,20 +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 (stype == LUA_TSTRING)
- argE->textlen = lua_objlen (L, pos);
- else {
- if (!luaL_getmetafield (L, pos, "__len") || lua_type (L, -1) != LUA_TFUNCTION)
- luaL_argerror (L, pos, "the subject has no valid __len metamethod");
- lua_pushvalue (L, pos);
- lua_call (L, 1, 1);
- type = lua_type (L, -1);
- if (type != LUA_TNUMBER)
- luaL_error (L, "subject's length is %s (expected number)",
- lua_typename (L, type));
- argE->textlen = lua_tointeger (L, -1);
- lua_pop (L, 1);
- }
+ if (!luaL_callmeta (L, pos, "__len"))
+ luaL_argerror (L, pos, "the subject has no valid __len metamethod");
+ type = lua_type (L, -1);
+ if (type != LUA_TNUMBER)
+ luaL_error (L, "subject's length is %s (expected number)",
+ lua_typename (L, type));
+ argE->textlen = lua_tointeger (L, -1);
+ lua_pop (L, 1);
#else
argE->textlen = luaL_len (L, pos);
#endif