Lua Scriptlet Example
|
<%lua
--
-- Defer this page
--
if conversation:getQuery():get('defer') == 'true' then
if conversation:defer() then
conversation:stop()
end
end
--
-- Cache this page
--
caching:setDuration(5000)
--
-- Calling Java
--
system = luajava.bindClass('java.lang.System')
print(string.format(' This page was dynamically generated at %s ', system:currentTimeMillis())) -- -- An example of a function -- function print_adapter (adapter) %>
Adapter: <%= adapter:getAttributes():get('name') %> version <%= adapter:getAttributes():get('version') %> Language used:<% print_adapter(executable:getContext():getAdapter()) %>Available languages:<% adapters = executable:getManager():getAdapters():toArray() for i = 1, #adapters do print_adapter(adapters[i]) end %> |
The "id" attribute in the URL query is:<%= conversation:getQuery():get('id') or '' %> A few tests:
<%
--
-- Including a document
--
-- This is identical to:
--
-- document:include('/triple/lua/')
--
%>
<%& '/triple/lua/' %>
<%
for i = 0, 9 do
%>
A multiple of three:
<%
print_triple(i)
%>
|