Specifying Version of a Library|Making a Location of Libraries for a Project

module_loaded_by handler

The "module_loaded_by" handler of the loaded library is called just after the library is loaded by "script "ModuleLoader"'s setup(me)". If a library implements "module_loaded_by" handler, some tasks can be performed at loaded time.

Initializing a Library when Loaded

The following sample is initializing itself in "module_loaded_by" handler. Also additional library is loaded. The additional library can be changed at loaded time.

property MoreLib : missing value
property _value : missing value

on module_loaded_by(loader)
log "module_loaded_by"
-- initialization of myself
set my _value to current date

-- load an additional library
tell loader
try
set MoreLib to load("ExtendedTextLib")
on error
set MoreLib to load("SimpleTextLib")
end try
end tell
return me
end module_loaded_by

on time_from_loaded()
return ((current date) - (my _value)) as text
end time_from_loaded

The following sample is the top level script which loads above library script.

property ModuleLoadedEvent : "@module"

script "ModuleLoader"'s setup(me)
delay 1
tell ModuleLoadedEvent
log time_from_loaded() -- result : 1
tell its MoreLib
log replace_text("How now brown cow", space, "-")
-- result : How-now-brown-cow
end tell
end tell

Making a Library Inherit other Library

Another use of "module_loaded_by" event is to build the library which inherit other library.

Usually a parent of a script object is determined at comipile-time. To specify the parent of the script object at run-time, the script object must be defined in a handler.

In the following sample, the script object "ExtendedTextLib" which inherits "SimpleTextLib" is defined and generated in the "module_loaded_by" handler. The script object "ExtendedTextLib" as a returned value of the "module_loaded_by" handler will be treated as a loaded library.

property name : "ExtendedTextLib"
--property SimpleTextLib : "@module"
use SimpleTextLib : script "SampleLibs/SimpleTextLib"

on module_loaded_by(loader)
log "module_loaded_by"
script ExtendedTextLib
property parent : SimpleTextLib
on remove_spaces(a_text)
return my replace_text(a_text, space, "")
end remove_spaces
end script

return ExtendedTextLib
end module_loaded_by

The following sample is the top level script which loads above library script.

property ExtendedTextLib : "@module"

script "ModuleLoader"'s setup(me)

tell ExtendedTextLib
remove_spaces("How now brown cow")
-- result :"Hownowbrowncow"
end tell
Specifying Version of a Library|Making a Location of Libraries for a Project