diff --git a/osx.c b/osx.c index 23879c1..7945ad1 100644 --- a/osx.c +++ b/osx.c @@ -276,6 +276,26 @@ static int os_dir_open(lua_State *L) return 1; } +static int os_dir_tostring(lua_State *L) +{ + df_os_dir *dir = luaL_checkudata(L, 1, DF_LUA_DIRHANDLE); + + if (dir->closeflag) { + lua_pushliteral(L, "directory (closed)"); + } else { + df_os_dirhn hn = dir->hn; + void *p; + +#ifdef _WIN32 + p = (void *) hn->dirh; +#else + p = hn; +#endif + lua_pushfstring(L, "directory (%p)", p); + } + return 1; +} + static int os_dir_close(lua_State *L) { df_os_dir *dir = todir(L); @@ -624,6 +644,7 @@ static void createmeta(lua_State *L) { static const luaL_Reg metameth[] = { { "__index", NULL }, // placeholder + { "__tostring", os_dir_tostring }, { "__gc", os_dir_gc }, #if LUA_VERSION_NUM >= 504 { "__close", os_dir_gc},