Show how to call a function in a shared library (without dynamically linking to it at compile-time). In particular, show how to call the shared library function if the library is available, otherwise use an internal equivalent function.

This is a special case of calling a foreign language function where the focus is close to the ABI level and not at the normal API level.



Related task

 OpenGL -- OpenGL is usually maintained as a shared library.


-- calculate CRC-32 checksum
str = "The quick brown fox jumps over the lazy dog"
 
-- is shared library (in Director called "Xtra", a DLL in windows, a sharedLib in
-- OS X) available?
if ilk(xtra("Crypto"))=#xtra then
 
  -- use shared library
  cx = xtra("Crypto").new()
  crc = cx.cx_crc32_string(str)
 
else
 
  -- otherwise use (slower) pure lingo solution
  crcObj = script("CRC").new()
  crc = crcObj.crc32(str)
 
end if