mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
otable: Lua implementation
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
0f8c71e17f
commit
58679a328b
1 changed files with 38 additions and 0 deletions
38
lib/otable.lua.in
Normal file
38
lib/otable.lua.in
Normal file
|
@ -0,0 +1,38 @@
|
|||
----------------------------------------------------------------------------
|
||||
-- @author Julien Danjou <julien@danjou.info>
|
||||
-- @copyright 2009 Julien Danjou
|
||||
-- @release @AWESOME_VERSION@
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local pairs = pairs
|
||||
local rawset = rawset
|
||||
|
||||
--- Special object table
|
||||
module("otable")
|
||||
|
||||
local function newindex(t, k, v)
|
||||
for tk, tv in pairs(t) do
|
||||
if tk == k then
|
||||
rawset(t, tk, v)
|
||||
return
|
||||
end
|
||||
end
|
||||
rawset(t, k, v)
|
||||
end
|
||||
|
||||
local function index(t, k)
|
||||
for tk, tv in pairs(t) do
|
||||
if tk == k then
|
||||
return tv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function new()
|
||||
return setmetatable({}, { __newindex = newindex, __index = index })
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = new })
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
Loading…
Reference in a new issue