Specific Functions of ModuleLoader|Specifying Version of a Library

Loading Libraries in a Library

Consider the case that a library depends on other libraries. The basics are same to the case of a top-level script. Reuquired libraries can be specified with the same syntax as top level script. Only difference is that the "script "ModuleLoader"'s setup(me)" is not required.

Usually "use" statements of AppleScript Libraries should be used as the following.

use SimpleTextLib : script "SampleLibs/SimpleTextLib"

Also you can use the syntax of ModuleLoader. "@module" is replaced with loaded library when the library is loaded by ModuleLoader.

property SimpleTextLib : "@module"

The following sample library expected that "SimpleTextLib" is loaded into "property SimpleTextLib" when this library is loaded.

property SimpleTextLib : "@module"

on replace_text_in_list(a_list, target, replacement)
set new_list to {}
repeat with a_text in a_list
tell SimpleTextLib
set end of new_list to replace_text(a_text, target, replacement)
end tell
end repeat
return new_list
end replace_text_in_list

The following sample is a top-level script to load above library "SimpleListLib". The statement `property SimpleListLib : "@module" ' indicate a requet to load the library "SimpleListLib". When the "script "ModuleLoader"'s setup(me)" statement is evaluated, both of "SimpleListLib" and "SimpleTextLib" will be loaded into the properties.

property SimpleListLib : "@module"
property _ : script "ModuleLoader"'s setup(me)

SimpleListLib's replace_text_in_list({"cain", "cine"}, "c", "p")
-- result : {"pain", "pine"}

Test of Libraries

Until the `script "ModuleLoader"'s setup(me) ' statement is executed, a library is not loaded into "property SimpleTextLib". To test the library "SimpleListLib", it is recommended to use the run handler which have the `script "ModuleLoader"'s setup(me) ' statement and test code as the following.

property SimpleTextLib : "@module"

on replace_text_in_list(a_list, target, replacement)
set new_list to {}
repeat with a_text in a_list
tell SimpleTextLib
set end of new_list to replace_text(a_text, target, replacement)
end tell
end repeat
return new_list
end replace_text_in_list

on run -- test code
script "ModuleLoader"'s setup(me)
replace_text_in_list({"cain", "cine"}, "c", "p")
end run
Specific Functions of ModuleLoader|Specifying Version of a Library