@ -1,4 +1,3 @@
local uuid = require ( " uuid " )
local bit32 = require ( " bit32 " )
local bit32 = require ( " bit32 " )
local Version = { 0 , 1 }
local Version = { 0 , 1 }
@ -40,6 +39,23 @@ do
clock = os.clock
clock = os.clock
end
end
end
end
local next_uuid -- Generate a UUID
do
local status , uuid = pcall ( require , " uuid " )
if status and uuid.next ~= nil then
next_uuid = uuid.next
else
-- Fallback to something reasonably close
next_uuid = function ( )
local uuid = " "
for _ = 1 , 16 do
uuid = uuid .. string.format ( " %02x " , math.random ( 0 , 255 ) )
end
return uuid
end
end
end
-- }}}
-- }}}
-- Network ---------------------------------------------------------------- {{{
-- Network ---------------------------------------------------------------- {{{
@ -420,7 +436,7 @@ function BaseControl:listen(noun, query, callback)
if self.listeners [ noun ] == nil then
if self.listeners [ noun ] == nil then
self.listeners [ noun ] = { }
self.listeners [ noun ] = { }
end
end
local id = uuid. next( )
local id = next_uuid ( )
self.listeners [ noun ] [ id ] = {
self.listeners [ noun ] [ id ] = {
query = query ,
query = query ,
callback = callback ,
callback = callback ,