diff --git a/bc.lua b/bc.lua index fa03de9dd7e1..bd4804501ad4 100644 --- a/bc.lua +++ b/bc.lua @@ -1,4 +1,3 @@ -local uuid = require("uuid") local bit32 = require("bit32") local Version = {0, 1} @@ -40,6 +39,23 @@ do clock = os.clock 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 ---------------------------------------------------------------- {{{ @@ -420,7 +436,7 @@ function BaseControl:listen(noun, query, callback) if self.listeners[noun] == nil then self.listeners[noun] = {} end - local id = uuid.next() + local id = next_uuid() self.listeners[noun][id] = { query=query, callback=callback,