This example accompanies the mako.createloader(io) documentation. It shows how to configure Lua module loading for files stored in an application's own IO tree.
www/.preload- Sets up the module loader for the application.www/index.lsp- Demonstrates loading the example modules.www/helloworld1.lua- Example Lua module at the application root.www/.lua/helloworld2.lua- Example Lua module in the.luadirectory.www/.lua/subdir/helloworld3.lua- Example Lua module in a nested subdirectory.
Start the example with the Mako Server:
cd require-test
mako -l::wwwFor more detail on starting the Mako Server, see the command line video tutorial and the command line options documentation.
After the server starts, open the HTTP URL printed in the Mako console. The page prints the output from each dofile(...) and require(...) variant.
The startup script creates a loader bound to the application's IO. That makes it possible to use Lua's normal require(...) mechanism for modules stored inside the application package instead of relying only on the default global search path.
- If
require(...)fails, confirm that.preloadran and that the module path inside the app matches the name passed torequire. - Hidden directories such as
.luaare normal for BAS applications and are still available server-side.