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.
The handler is called after required libraries are loaded.
It is a good place to initialize the library by itself.
The returned value of "module_loaded_by" handler is treated as a loaded library.
"module_loaded_by" must return "me" or a kind of script object.
It is useful to make a library inheriting another library.
Additional libraries can be loaded in the "module_loaded_by" handler.
You should use load handler of the loader script passed as a parameter.
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.
propertyMoreLib : missing value
property_value : missing value
onmodule_loaded_by(loader)
log "module_loaded_by"
-- initialization of myself
setmy_valuetocurrent date
-- load an additional library
tellloader
try
setMoreLibtoload("ExtendedTextLib")
onerror
setMoreLibtoload("SimpleTextLib")
endtry
endtell
returnme
endmodule_loaded_by
ontime_from_loaded()
return ((current date) - (my_value)) astext
endtime_from_loaded
The following sample is the top level script which loads above library script.
propertyModuleLoadedEvent : "@module"
script "ModuleLoader"'s setup(me)
delay 1
tellModuleLoadedEvent
logtime_from_loaded() -- result : 1
tellitsMoreLib
logreplace_text("How now brown cow", space, "-")
-- result : How-now-brown-cow
endtell
endtell
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.