local function fallback(a, b) return a + b end -- web.require for loading modules from URLs -- first argument of web.require is the name of the module, second is the (possibly relative) URL -- we pcall it in case web.require doesn't work (e.g. if page is opened directly from filesystem) local status, gcd = pcall(function() return web.require("gcd", "./gcd.lua") end) gcd = status and gcd or { gcd = fallback } -- lcd.lua contains `require("gcd")`. it works since the the previous web.require named that module "gcd" local status, lcd = pcall(function() return web.require("lcd", "./lcd.lua") end) lcd = status and lcd or { lcd = fallback } -- blah blah. some example code: local function td(content) return "<td>" .. content .. "</td>" end local function row(a, b) return "<tr>" .. td(a) .. td(b) .. td(gcd.gcd(a, b)) .. td(lcd.lcd(a, b)) .. "</tr>" end local html = { [[<ul> <li><a href="https://www.lua.org/"><img src="./lua-logo.gif" alt="Lua"></a></li> <li><a href="https://github.com/Glorp/webby-lua">in the browser</a></li> </ul>]], "<table><thead>", "<table><thead>", "<tr><th>a</th><th>b</th><th>gcd(a, b)</th><th>lcd(a, b)</th></tr>", "</thead><tbody>" } local i = 0 while i < 10 do i = i + 1 table.insert(html, row(math.random(2, 20), math.random(2, 20))) end table.insert(html, "</tbody></table>") web.html(table.concat(html))
autorun:
run ▶
No JavaScript? Maybe see
the repo on GitHub
.