summaryrefslogtreecommitdiff
path: root/src/algo.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/algo.h')
-rw-r--r--src/algo.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/algo.h b/src/algo.h
index 2255070..5d25330 100644
--- a/src/algo.h
+++ b/src/algo.h
@@ -119,8 +119,13 @@ static void check_subject (lua_State *L, int pos, TArgExec *argE)
int stype;
argE->text = lua_tolstring (L, pos, &argE->textlen);
stype = lua_type (L, pos);
+#if LUA_VERSION_NUM == 501
+ if (stype != LUA_TSTRING && stype != LUA_TUSERDATA) {
+ luaL_typerror (L, pos, "string or userdata");
+#else
if (stype != LUA_TSTRING && stype != LUA_TTABLE && stype != LUA_TUSERDATA) {
luaL_typerror (L, pos, "string, table or userdata");
+#endif
} else if (argE->text == NULL) {
int type;
lua_getfield (L, pos, "topointer");
@@ -135,7 +140,10 @@ 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
- lua_objlen (L, pos);
+ if (!luaL_getmetafield (L, pos, "__len") || lua_type (L, -1) != LUA_TFUNCTION)
+ luaL_argerror (L, pos, "the userdata has no valid __len metafield");
+ lua_pushvalue (L, pos);
+ lua_call (L, 1, 1);
#else
lua_len (L, pos);
#endif