Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
878acca2
Commit
878acca2
authored
10 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Removed Lua docs
parent
ace92859
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/LuaSqlite.md
+0
-51
0 additions, 51 deletions
docs/LuaSqlite.md
with
0 additions
and
51 deletions
docs/LuaSqlite.md
deleted
100644 → 0
+
0
−
51
View file @
ace92859
# Mongoose Lua Server Pages
Pre-built Windows and Mac mongoose binaries support Lua Server Pages
functionality.
That means it is possible to write PHP-like scripts with mongoose
using Lua programming language instead of PHP. Lua is known
for it's speed and small size. Mongoose uses Lua version 5.2.3, the
documentation for it can be found at
[
Lua 5.2 reference manual
](
http://www.lua.org/manual/5.2/
)
.
To create a Lua Page, make a file that is called
`ANY_NAME.lp`
. For example,
`my_page.lp`
. It is important to have a file
name that ends up with
`.lp`
, cause this is the way mongoose recognises
Lua Page file. The contents of the file, just like
with PHP, is HTML with embedded Lua code. Lua code must be enclosed within
`<? ?>`
blocks, and can appear anywhere on the page.
Mongoose does not send HTTP headers for Lua pages. Therefore,
every Lua Page must begin with HTTP status line and headers, like this:
<? mg.write('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
<html><body>
<span>Today is:</span> <? mg.write(os.date("%A")) ?>
</body></html>
Note that this example uses function
`mg.write()`
, which prints data to the
web page. Using function
`mg.write()`
is the way to generate web content from
inside Lua code. In addition to
`mg.write()`
, all standard library functions
are accessible from the Lua code (please check reference manual for details).
Information about the request is available via the
`mg.request_info`
object.
I contains request method, all headers, etcetera. Please refer to
`struct mg_request_info`
definition in
[
mongoose.h
](
https://github.com/cesanta/mongoose/blob/master/mongoose.h
)
to see what is available via the
`mg.request_info`
object.
Check out
[
prime_numbers.lp
](
https://github.com/cesanta/mongoose/blob/master/examples/lua/prime_numbers.lp
)
for some example.
Mongoose exports the following to the Lua Server Page:
mg.write(str) -- writes string to the client
mg.onerror(msg) -- error handler, can be overridden
mg.request_info -- a table with request information
Using Lua scripting it is easy to emulate SSI functionality. For example,
to include the content of another file, one can write:
<? mg.write(io.open('MY_FILE.TXT'):read('*all')) ?>
To serve a Lua Page, mongoose creates Lua context. That context is used for
all Lua blocks within the page. That means, all Lua blocks on the same page
share the same context. If one block defines a variable, for example, that
variable is visible in all following blocks.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment