Compare commits

...

3 Commits

5 changed files with 45 additions and 16 deletions

View File

@ -23,6 +23,7 @@
"keygrabber", "keygrabber",
"ldoc", "ldoc",
"leafo", "leafo",
"lldebugger",
"luacheck", "luacheck",
"luacheckrc", "luacheckrc",
"luadoc", "luadoc",

18
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Busted",
"type": "lua-local",
"request": "launch",
"program": {
"command": "luarocks"
},
"args": ["test"]
// "ignorePatterns": "^/usr"
}
]
}

View File

@ -1,3 +1,9 @@
-- Enable lua-local-debugger
-- https://github.com/tomblind/local-lua-debugger-vscode
if os.getenv "LOCAL_LUA_DEBUGGER_VSCODE" == "1" then
require("lldebugger").start()
end
-- Fake awesome modules -- Fake awesome modules
package.loaded["gears.table"] = { package.loaded["gears.table"] = {
hasitem = function(t, item) hasitem = function(t, item)

View File

@ -23,7 +23,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
} }
assert.is_not_nil(s) assert.is_not_nil(s)
@ -36,28 +35,39 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
} }
slot.remove(s) slot.remove(s)
assert.is_false(s.connected) -- remove should also invoke disconnect_signal
assert.is_nil(slot.get_slot(s)) assert.is_nil(slot.get_slot(s))
end) end)
it("should connect slot (from constructor parameters)", function() it("should automatically connect slot", function()
local target = new_target() local target = new_target()
local s = slot { local s = slot {
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
connect = true,
} }
assert.is_true(s.connected) assert.is_true(s.connected)
end) end)
it("should prevent slot connection with parameter", function()
local target = new_target()
local s = slot {
target = target,
signal = "signal",
slot = function() end,
connect = false,
}
assert.is_false(s.connected)
end)
it("should connect signal", function() it("should connect signal", function()
local target = new_target() local target = new_target()
@ -66,6 +76,7 @@ describe("Awesome-slot", function()
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" }, slot_params = { key = "value" },
connect = false,
} }
slot.connect(s) slot.connect(s)
@ -80,8 +91,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
connect = true,
} }
slot.disconnect(s) slot.disconnect(s)
@ -96,7 +105,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
} }
assert.is_not_nil(slot.get_slot(s)) assert.is_not_nil(slot.get_slot(s))
@ -111,7 +119,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
} }
assert.is_not_nil(slot.get_slot(id)) assert.is_not_nil(slot.get_slot(id))
@ -124,7 +131,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = "signal", signal = "signal",
slot = function() end, slot = function() end,
slot_params = { key = "value" },
} }
assert.is_not_nil(s.id) assert.is_not_nil(s.id)
@ -145,7 +151,6 @@ describe("Awesome-slot", function()
signal = signal_name, signal = signal_name,
slot = callback, slot = callback,
slot_params = params, slot_params = params,
connect = true,
} }
target:emit_signal(signal_name) target:emit_signal(signal_name)
@ -167,7 +172,6 @@ describe("Awesome-slot", function()
target = target, target = target,
signal = signal_name, signal = signal_name,
slot = callback, slot = callback,
connect = true,
} }
target:emit_signal(signal_name, 1, 2, 3) target:emit_signal(signal_name, 1, 2, 3)

View File

@ -107,10 +107,10 @@ end
-- @tparam any params.target The slot target object. -- @tparam any params.target The slot target object.
-- @tparam string params.signal The signal the slot connects to. -- @tparam string params.signal The signal the slot connects to.
-- @tparam function params.slot The callback function to connect to the signal. -- @tparam function params.slot The callback function to connect to the signal.
-- @tparam table params.slot_params The parameters to pass to the callback -- @tparam[opt] table params.slot_params The parameters to pass to the callback
-- function. (The signal will invoke the callback function with this table as -- function. (The signal will invoke the callback function with this table as
-- parameter) -- parameter)
-- @tparam[opt=false] boolean params.connect Connect the slot now. -- @tparam[opt=true] boolean params.connect Connect the slot now.
-- @treturn Slot The created Slot instance. -- @treturn Slot The created Slot instance.
-- @constructorfct awesome_slot -- @constructorfct awesome_slot
function awesome_slot.create(params) function awesome_slot.create(params)
@ -127,7 +127,7 @@ function awesome_slot.create(params)
-- Insert the new slot into the slots list -- Insert the new slot into the slots list
awesome_slot._private.registered_slots[slot.id] = slot awesome_slot._private.registered_slots[slot.id] = slot
if params.connect then if params.connect == nil or params.connect then
awesome_slot.connect(slot) awesome_slot.connect(slot)
end end
@ -142,7 +142,7 @@ function awesome_slot.remove(slot)
local s = awesome_slot.get_slot(slot) local s = awesome_slot.get_slot(slot)
if s.connected then if s.connected then
awesome_slot.disconnect_slot(s) awesome_slot.disconnect(s)
end end
awesome_slot._private.registered_slots[s.id] = nil awesome_slot._private.registered_slots[s.id] = nil