~rootmos/lua-hack

61b65a276eb3edc634dcc48036d234869dc32968 — Gustav Behm 1 year, 2 months ago 5854f6c
Close notification
2 files changed, 23 insertions(+), 8 deletions(-)

M notify/go.lua
M notify/notify.c
M notify/go.lua => notify/go.lua +1 -5
@@ 1,10 1,6 @@
local N = require("notify")
N.app_name = "foo"

local n = N:new{ summary = "hello", body = "foobar", timeout = 10000 }:show()
local n <close> = N:new{ summary = "hello", body = "foobar", timeout = 10000 }:show()

os.execute("sleep 1")

n.body = "baz"
n.timeout = 500
n:show()

M notify/notify.c => notify/notify.c +22 -3
@@ 81,6 81,24 @@ static int notification_show(lua_State* L)
    luaR_return(L, 1);
}

static int notification_close(lua_State* L)
{
    luaR_stack(L);
    struct notification* notification = luaL_checkudata(L, 1, TYPE_NOTIFICATION);

    GError* e = NULL;
    if(!notify_notification_close(notification->n, &e)) {
        luaL_where(L, 1);
        lua_pushfstring(L, "unable to close notification: %s", e->message);
        g_error_free(e);
        lua_concat(L, 2);
        return lua_error(L);
    }

    lua_pushvalue(L, 1);
    luaR_return(L, 1);
}

static int notification_index(lua_State* L)
{
    luaR_stack(L);


@@ 313,7 331,6 @@ static int notification_new(lua_State* L)
                if(body == NULL) {
                    failwith("lua_tostring failed unexpectedly");
                }
                debug("app name: %s", app_name);
            } else if(f != LUA_TNIL) {
                return luaL_argerror(L, arg, "app_name field not a string");
            }


@@ 326,7 343,6 @@ static int notification_new(lua_State* L)
                if(!isnum) {
                    return luaL_argerror(L, arg, "timeout field not an integer");
                }
                debug("timeout: %d", timeout);
            } else if(f != LUA_TNIL) {
                return luaL_argerror(L, arg, "timeout field not a number");
            }


@@ 339,7 355,6 @@ static int notification_new(lua_State* L)
                if(!isnum) {
                    return luaL_argerror(L, arg, "id field not an integer");
                }
                debug("id: %d", id);
            } else if(f != LUA_TNIL) {
                return luaL_argerror(L, arg, "id field not a number");
            }


@@ 367,6 382,7 @@ static int notification_new(lua_State* L)
    if(luaL_newmetatable(L, TYPE_NOTIFICATION)) {
        luaL_Reg l[] = {
            { "show", notification_show },
            { "close", notification_close },
            { NULL, NULL },
        };
        luaL_newlib(L, l);


@@ 378,6 394,9 @@ static int notification_new(lua_State* L)

        lua_pushcfunction(L, notification_gc);
        lua_setfield(L, -2, "__gc");

        lua_pushcfunction(L, notification_close);
        lua_setfield(L, -2, "__close");
    }
    lua_setmetatable(L, -2);