如何在Livecode或Hypercard中创建UUID(=通用唯一识别码,或GUID =全局唯一标识符,Microsoft语言)?
UUID的目的是为信息片段提供几乎唯一的密钥,而无需中央协调。
参考资料
如何在Livecode或Hypercard中创建UUID(=通用唯一识别码,或GUID =全局唯一标识符,Microsoft语言)?
UUID的目的是为信息片段提供几乎唯一的密钥,而无需中央协调。
参考资料
如果你使用类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()函数,我IRC发明了SuperCard)。
如果所有这些都无法帮助您,这里有一份规范,描述如何创建标准UUID:http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt,它不特定于任何编程语言。
目前(至少在版本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.
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