This makes it possible to add something similar to a __index / __newindex
metamethod to all our C objects. Based on this, Lua can then easily implement
arbitrary properties on our capi objects.
Run the following code:
do
local d
local f = function() d.visible = true end
if _VERSION >= "Lua 5.2" then
setmetatable({}, { __gc = f })
else
getmetatable(newproxy(true)).__gc = f
end
d = drawin({})
end
collectgarbage("collect")
Awesome will segfault.
The reason for this is that after the above code ran, all variables in it are
unreferenced and will be garbage-collected at the next sweep phase. Lua runs
garbage collectors in the inverse order that their corresponding objects were
"marked" which means for the above code that the drawin's garbage collector will
run before function f runs. So the code will access the drawin after its
destructor already ran. Obviously, awesome's C code does not expect nor
correctly deal with this situation and was dereferencing a NULL pointer.
To fix this, this commit "unsets" the metatable of a userdata object when it is
being garbage collected. Since the type of a userdata is inferred via its
metatable, the object will no longer be accepted by luaA_toudata().
For the above code this will result in an unhelpful error message saying that
something tried to index a userdata, but userdata cannot be indexed. At least we
no longer crash and the traceback of the error will hopefully point at some __gc
metamethod which should be enough of a hint to figure out the problem.
Thanks-to: http://blog.reverberate.org/2014/06/beware-of-lua-finalizers-in-c-modules.html
Signed-off-by: Uli Schlachter <psychon@znc.in>
This property is especially useful for client objects which are unusable after
unmanage. "Unusuable" here means that pretty much everything you do with the
client object results in a lua error.
Syntax is c.valid.
Signed-off-by: Uli Schlachter <psychon@znc.in>
Every .c file has to include the corresponding .h file first to make sure the
headers are self-contained. Additionally, this moves some unneeded includes
around.
Signed-off-by: Uli Schlachter <psychon@znc.in>
The original struct name is luaL_Reg, but Lua v5.1 had a
`typedef luaL_reg luaL_Reg`, which in v5.2 was removed
and as a result breaking the build in Awesome which uses luaL_reg
version exclusively.
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
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>
With this patch, we track the number of objects that are alive for any class.
This information can be accessed via class.instances()
For example:
print("wiboxes", wibox.instances())
print("widgets", widget.instances())
Signed-off-by: Uli Schlachter <psychon@znc.in>
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>
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>