Commit Graph

31 Commits

Author SHA1 Message Date
Uli Schlachter 3f93bf4cd5 Use signal_array_getbyname() where appropriate
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-01-24 09:13:35 +01:00
Uli Schlachter 6f1df7a3ad Fix disconnecting not connected signals (#950)
When a function is disconnected from a signal ("disconnect_signal") that is not
actually connected to the function, two things happened:

1. The attempt to remove the function from the signal array didn't do anything
2. Unreferencing the function noticed that the function wasn't referenced

The second step printed a big, fat scary warning.

Actually, this has the possibility of causing errors. For example, in the
following code, awesome would wrongly unreference the function at the
disconnect_signal() call and might later still try to call it when the
"refresh" signal is emitted:

do
    local function f() end
    awesome.connect_signal("refresh", f)
    awesome.disconnect_signal("debug::error", f)
end

Fix this by making signal_disconnect() return a boolean value indicating if it
actually did something. All callers are fixed to use this value and only update
the reference counts if something was actually disconnected.

Fixes: https://github.com/awesomeWM/awesome/issues/814
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-09 00:03:08 +02:00
Uli Schlachter a964396771 Deprecate signal_add() on C-API objects
This commit makes the code automatically add signals when they are first used.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:51:45 +02:00
Uli Schlachter f02b75f826 Fix arguments to luaL_checkstack()
The argument to luaL_checkstack() is the amount of new stack to make available,
not the new size of the stack. Thus, remove the addition of lua_gettop(L) here.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-17 19:07:06 +01:00
Uli Schlachter d09ece6b5a Require "integer" instead of "number" in more places
E.g. trying to press mouse button 1.5 via root.fake_input() doesn't make sense.
Previously the code silently truncated the number to an integer. Now it
complains about this instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-06 13:59:14 +01:00
Uli Schlachter 5e6a893207 Replace various calls to warn() with luaA_warn()
luaA_warn() prints a Lua backtrace and thus generates more useful output. warn()
should only be used in awesome-internal places (e.g. receiving an error from the
X11 server).

Closes https://github.com/awesomeWM/awesome/pull/608.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-31 15:35:13 +01:00
Julian Wollrath 26f15a13f3 Document C API directly in the C source code
v2: Add available signals to the docs.

Signed-off-by: Julian Wollrath <jwollrath@web.de>
2015-06-19 23:13:31 +02:00
Daniel Hahler f562b4a64b luaA_object_emit_signal: check for valid object
By the time a signal gets emitted the object might be invalid already,
e.g. when it is very short-lived and unmanaged by the time the delayed
call to emit_signal is being invoked.

Ref: https://github.com/awesomeWM/awesome/pull/87#issuecomment-70901168
2015-02-10 14:52:47 +01:00
Uli Schlachter 8eed5e7bcf client: Include c.name in the result of tostring(c)
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-12-06 18:16:05 +01:00
Gregor Best a2cd466103 Remove compiler warnings
Signed-off-by: Gregor Best <gbe@ring0.de>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-24 18:15:34 +01:00
Uli Schlachter a8fa910586 luaA_object_emit_signal: Fix a crash on non-objects
This was first fixed in 79b1f5aba1, but 3fbb5f15 reintroduced the crash. The
only "real" change in here is that there is now a "return;" after the
warn("Trying...");. The rest is just re-indentation.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-01-04 17:09:52 +01:00
Gregor Best c2ea920ca0 remove encoding=utf-8 from modelines
This option is no longer valid in modelines, so it has been removed from
all modelines using the following shellscript:

    #!/bin/ksh

    git ls-tree -r HEAD | cut -f2 | while read f; do
        egrep -e '^(//|--) vim: .*encoding=' $f >/dev/null || continue
        sed -E -e '/^(\/\/|--) vim:/s/:encoding=utf-8//' $f > /tmp/foo
        mv /tmp/foo $f
    done

Signed-off-by: Gregor Best <gbe@ring0.de>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-11 17:34:09 +02:00
Uli Schlachter 79b1f5aba1 Don't use luaL_error in luaA_object_emit_signal (FS#713)
This function can be called from unprotected contexts. Calling luaL_error() in
this case results in a call to luaA_panic() and awesome dies.

The only real change here is that this now calls warn() instead of luaL_error().
The rest is reindentation because warn() returns while luaL_error() didn't.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-12-11 13:48:31 +01:00
Uli Schlachter 22a5137299 Print a warning if an invalid reference is dropped (FS#820)
Previously, if you called luaA_object_decref() it would silently *create* a new
reference with reference count -1. Obviously, this is not good.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-12-11 13:25:44 +01:00
Uli Schlachter 2732475403 signal: Make non-existing signals non-fatal
This function is also called from unprotected C contexts and there shouldn't be
any reason why this really has to be fatal.

A warning makes you lose less sessions. ;)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-26 16:29:36 +02:00
Uli Schlachter ab4c151ed8 Add signals before using them
This commit makes it an error if an unknown signal is connected, disconnected or
emitted. All signals have to be added before they can be used.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-25 23:00:36 +02:00
Uli Schlachter 948f960b7e Also rename the signal_* C function
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-25 20:48:42 +02:00
Julien Danjou 6d332f07a0 lua{class,object}: rename signals functions
I knew this was wrong at the beginning, f*ck.

Signed-off-by: Julien Danjou <julien@danjou.info>
2010-08-25 20:28:20 +02:00
Julien Danjou f523b37e1d lua{class,object}: {add,remove}_signal() take lua_CFunction as arg
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-08-25 20:14:55 +02:00
Julien Danjou 3fbb5f1535 luaobject: emit signals on class too
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-08-18 10:41:52 +02:00
Julien Danjou f7746a198c luaclass: take care of inheritance garbage collection
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-05-28 13:27:49 +02:00
Julien Danjou fccc451f89 luaclass: add inheritance support
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-05-28 13:27:04 +02:00
Brian Gianforcaro 3145e3145e Grammar/spelling corrections in comments and docs.
Signed-off-by: Brian Gianforcaro <b.gianfo@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-08-31 10:39:36 +02:00
Julien Danjou 8da6a20f27 luaobject: check that object is userdata
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-08-22 13:20:55 +02:00
Julien Danjou c180904d77 luaobject: change function push method in signal emit
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-08-21 15:30:48 +02:00
Julien Danjou 2a252cd4da luaobject: add signal_object_emit
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-08-21 15:30:48 +02:00
Julien Danjou dc61d258f0 luaclass: optimize type handling
We use lua_class_t pointer as key in the registry to store metatable we
will compare.
lauxlib uses a string, which sucks, because it forces to do a
pushliteral() each time you want to get a metatable from the registry,
which is slower.

Signed-off-by: Julien Danjou <julien@danjou.info>
2009-08-21 15:30:47 +02:00
Julien Danjou 7ecce446ad luaobject: generate Lua API function for add, remove and emit signal
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-07-29 15:48:18 +02:00
Julien Danjou eed9864ab0 luaobject: add signals
Signed-off-by: Julien Danjou <julien@danjou.info>
2009-07-29 15:48:18 +02:00
Julien Danjou a1b113901c luaobject: change global refering method
We now store elements in registry:
registry.pointer = userdata

And count references.

Signed-off-by: Julien Danjou <julien@danjou.info>
2009-07-28 10:40:51 +02:00
Julien Danjou 339fb53d56 luaobject: add and use item system
Now, each object can store items.

Signed-off-by: Julien Danjou <julien@danjou.info>
2009-07-28 10:29:30 +02:00