mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
2046c0d2ae
- Expand redbean UNIX module - Expand redbean documentation - Ensure Lua copyright is embedded in binary - Increase the PATH_MAX limit especially on NT - Use column major sorting for linenoise completions - Fix some suboptimalities in redbean's new UNIX API - Figured out right flags for Multics newline in raw mode
40 lines
1.1 KiB
Lua
40 lines
1.1 KiB
Lua
mymodule = require "mymodule"
|
|
sqlite3 = require "lsqlite3"
|
|
|
|
-- /.init.lua is loaded at startup in redbean's main process
|
|
HidePath('/usr/share/zoneinfo/')
|
|
HidePath('/usr/share/ssl/')
|
|
|
|
-- open a browser tab using explorer/open/xdg-open
|
|
-- LaunchBrowser('/tool/net/demo/index.html')
|
|
|
|
-- sql database (see sql.lua)
|
|
db = sqlite3.open_memory()
|
|
db:exec[[
|
|
CREATE TABLE test (
|
|
id INTEGER PRIMARY KEY,
|
|
content TEXT
|
|
);
|
|
INSERT INTO test (content) VALUES ('Hello World');
|
|
INSERT INTO test (content) VALUES ('Hello Lua');
|
|
INSERT INTO test (content) VALUES ('Hello Sqlite3');
|
|
]]
|
|
|
|
-- this intercepts all requests if it's defined
|
|
function OnHttpRequest()
|
|
if HasParam('magic') then
|
|
Write('<p>\r\n')
|
|
Write('OnHttpRequest() has intercepted your request<br>\r\n')
|
|
Write('because you specified the magic parameter\r\n')
|
|
Write('<pre>\r\n')
|
|
Write(EscapeHtml(LoadAsset('/.init.lua')))
|
|
Write('</pre>\r\n')
|
|
else
|
|
Route() -- this asks redbean to do the default thing
|
|
end
|
|
SetHeader('Server', 'redbean!')
|
|
end
|
|
|
|
function Adder(x, y)
|
|
return x + y
|
|
end
|