mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
80b211e314
This change introduces a `-W /dev/pts/1` flag to redbean. What it does is use the mincore() system call to create a dual-screen terminal display that lets you troubleshoot the virtual address space. This is useful since page faults are an important thing to consider when using a forking web server. Now we have a colorful visualization of which pages are going to fault and which ones are resident in memory. The memory monitor, if enabled, spawns as a thread that just outputs ANSI codes to the second terminal in a loop. In order to make this happen using the new clone() polyfill, stdio is now thread safe. This change also introduces some new demo pages to redbean. It also polishes the demos we already have, to look a bit nicer and more presentable for the upcoming release, with better explanations too.
49 lines
1.5 KiB
Lua
49 lines
1.5 KiB
Lua
-- Call Lua Module Demo
|
|
--
|
|
-- Your Lua modules may be stored in the /.lua/ folder.
|
|
--
|
|
-- In our /.init.lua global scope earlier, we ran the code:
|
|
--
|
|
-- mymodule = require "mymodule"
|
|
--
|
|
-- Which preloaded the /.lua/mymodule.lua module once into the server
|
|
-- global memory template from which all request handlers are forked.
|
|
-- Therefore, we can just immediately use that module from our Lua
|
|
-- server pages.
|
|
|
|
Write[[<!doctype html>
|
|
<title>redbean call lua module demo</title>
|
|
<style>
|
|
body { padding: 1em; }
|
|
h1 a { color: inherit; text-decoration: none; }
|
|
h1 img { border: none; vertical-align: middle; }
|
|
pre { margin-left: 2em; }
|
|
p { word-break: break-word; max-width: 650px; }
|
|
dt { font-weight: bold; }
|
|
dd { margin-top: 1em; margin-bottom: 1em; }
|
|
.hdr { text-indent: -1em; padding-left: 1em; }
|
|
</style>
|
|
<h1>
|
|
<a href="/"><img src="/redbean.png"></a>
|
|
<a href="call-lua-module.lua">call lua module demo</a>
|
|
</h1>
|
|
<p>Your Lua modules may be stored in the /.lua/ folder.
|
|
<p>In our <code>/.init.lua</code> global scope earlier, we ran the code:
|
|
<pre>mymodule = require "mymodule"</pre>
|
|
<p>Which preloaded the <code>/.lua/mymodule.lua</code> module once into
|
|
the server global memory template from which all request handlers are
|
|
forked. Therefore, we can just immediately use that module from our
|
|
Lua Server Pages.
|
|
<p>
|
|
Your <code>mymodule.hello()</code> output is as follows:
|
|
<blockquote>
|
|
]]
|
|
|
|
mymodule.hello()
|
|
|
|
Write[[
|
|
</blockquote>
|
|
<p>
|
|
<a href="/">go back</a>
|
|
</p>
|
|
]]
|