[osx.c] Add directory __tostring() metamethod.

This commit is contained in:
Lorenzo Cogotti 2022-12-12 12:35:48 +01:00
parent 672f94e73d
commit 0f893a4682
1 changed files with 21 additions and 0 deletions

21
osx.c
View File

@ -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},