diff --git a/src/lapi_systemfs.cc b/src/lapi_systemfs.cc index f299c89..66df405 100644 --- a/src/lapi_systemfs.cc +++ b/src/lapi_systemfs.cc @@ -15,10 +15,16 @@ namespace blt { int exists(lua_state* state) { + // Check arguments + if(lua_gettop(state) != 2) + luaL_error(state, "SystemFS:exists(path) takes a single argument, not %d arguments including SystemFS", lua_gettop(state)); + if(!lua_isstring(state, -1)) + luaL_error(state, "SystemFS:exists(path) -> argument 'path' must be a string!"); + // assuming PWD is base folder - const char* path = lua_tolstring(state, 1, NULL); + const char* path = lua_tolstring(state, -1, NULL); struct stat _stat; - lua_pushboolean(state, stat(path, &_stat)); + lua_pushboolean(state, stat(path, &_stat) == 0); return 1; } }