-- auto-generated library loading code
property _Loader : run application "LoaderServer"
----------------------------------------------------------------------
-- DEPENDENCIES
property _Number : missing value
on __load__(loader)
set _Number to loader's loadLib("Number")
end __load__
----------------------------------------------------------------------
-- main code
__load__(_Loader's makeLoader()) -- load libraries
_Number's numToText(34342343233, ".")
--> "34342343233"
If you’ve not used AppleMods’ libraries before, you’ll need to download and install AppleMods’ Loader system first. Run the Loader installer, then download and add the Number library to the ASLibraries folder. You can use the LoaderWizard applet to generate the library loading code to paste at the top of your script.
Strictly speaking neither does my example, since you can cut-n-paste the Number library’s numToText handler into your own code if you really want to. It’s just that cut-n-paste programming isn’t very good practice: it adds complexity and bloat to your own code which makes it harder to maintain and increases the risk of bugs sneaking in. The point of using libraries is to get all that gunk out of your way, which it does.
As for the bulky Loader boilerplate, blame AppleScript for not providing a built-in ‘import’ statement like any decent language would. You can auto-generate this code though so it’s generally a no-brainer, and the Loader applet itself isn’t required to run scripts, only to compile them. So while it’s not ideal it’s not too bad a trade-off either, when in return you get several hundred free, time-tested, ‘plug-n-play’ commands to play with.
BTW, if you want to load the libraries when the script is compiled, instead of when it’s run, change:
__load__(_Loader's makeLoader())
into:
property _ : __load__(_Loader's makeLoader())
Of course, this means you’ll need to recompile the script if you update the libraries later, but it can be useful for creating a compiled script that runs on other machines without having to install the libraries there as well.