3

如何在 Livecode 或 Hypercard 中创建 UUID(= 通用唯一标识符,或 GUID = 全局唯一标识符,Microsoft 所说)?

UUID 的目的是在没有中央协调的情况下为信息片段提供几乎唯一的密钥。

参考

4

4 回答 4

3

如果您使用的是 Unix(如 Linux 或 MacOS),则可以使用 shell() 函数来调用 uuidgen 终端命令。它应该是这样的

put shell("uuidgen") into theUUID

这有点笨拙(创建一个 shell,在其中运行一个命令行应用程序,然后再次退出它),但可以在较旧的 LiveCode 版本上工作,并且与 shell 脚本的作用没有什么不同。

在 HyperCard 中,您必须在脚本设置为 AppleScript 的对象中使用 AppleScript,或者使用“do X as AppleScript”命令。不确定 AppleScript 是否可以本地构建 UUID,但如果不能,AppleScript 可用于运行 shell 脚本。(HyperCard 中不存在 shell() 函数,它是由 SuperCard、IIRC 发明的)。

如果这些都没有帮助,这里有一个描述如何创建标准 UUID 的规范:http ://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt它并不特定于任何编程语言。

于 2013-07-03T15:16:23.363 回答
1

在 LiveCode 6.1(今天发布)中,您可以使用 uuid 函数创建一个 uuid。类型 4 随机 uuid 是默认设置,并且还实现了类型 3 和 5 基于摘要的 uuid。

于 2013-07-02T20:50:18.603 回答
0

以下函数创建类型 4(随机)UUID:

function getUUID
   local tUUIDpattern
   local tUUID
   local tHexDigits
   put "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx" into tUUIDpattern
   put "1234567890abcdef" into tHexDigits
   repeat for each char tChar in tUUIDpattern
      if tChar = "x" then
         put any char of tHexDigits  after tUUID
      else
         put tChar after tUUID
      end if
   end repeat
   return tUUID
end getUUID
于 2013-07-02T11:14:29.380 回答
0

现在(至少在 6.6.1 版本中)可以在put uuid(random)没有 shell的情况下使用

if the type is empty or random a version 4 (random) UUID is returned. A cryptographic quality pseudo-random number generator is used to generate the randomness.
If the type is md5 a version 3 UUID is returned.
If the type is sha1 a version 5 UUID is returned.
于 2014-05-09T13:12:20.660 回答