Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
5ce1fc3c
Commit
5ce1fc3c
authored
Feb 27, 2013
by
Mikhail Nikalyukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lua page example with the form submitting
parent
a58bb71c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
UserManual.md
UserManual.md
+8
-2
prime_numbers.lp
examples/lua/prime_numbers.lp
+42
-0
No files found.
UserManual.md
View file @
5ce1fc3c
...
@@ -307,8 +307,9 @@ like request method, all headers, etcetera. Please refer to
...
@@ -307,8 +307,9 @@ like request method, all headers, etcetera. Please refer to
`struct mg_request_info`
definition in
`struct mg_request_info`
definition in
[
mongoose.h
](
https://github.com/valenok/mongoose/blob/master/mongoose.h
)
[
mongoose.h
](
https://github.com/valenok/mongoose/blob/master/mongoose.h
)
to see what kind of information is present in
`request_info`
object. Also,
to see what kind of information is present in
`request_info`
object. Also,
[
page.lp
](
https://github.com/valenok/mongoose/blob/master/test/page.lp
)
[
page.lp
](
https://github.com/valenok/mongoose/blob/master/test/page.lp
)
and
contains some example code that uses
`request_info`
.
[
prime_numbers.lp
](
)https://github.com/valenok/mongoose/blob/master/examples/lua/prime_numbers.lp
contains some example code that uses
`request_info`
and other functions(form submitting for example).
One substantial difference of mongoose's Lua Pages and PHP is that Mongoose
One substantial difference of mongoose's Lua Pages and PHP is that Mongoose
...
@@ -323,6 +324,11 @@ It is easy to do things like redirects, for example:
...
@@ -323,6 +324,11 @@ It is easy to do things like redirects, for example:
<? print('HTTP/1.0 302 Found\r\nLocation: http://google.com\r\n\r\n') ?>
<? print('HTTP/1.0 302 Found\r\nLocation: http://google.com\r\n\r\n') ?>
To serve 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 the block that follows.
# Common Problems
# Common Problems
-
PHP doesn't work - getting empty page, or 'File not found' error. The
-
PHP doesn't work - getting empty page, or 'File not found' error. The
reason for that is wrong paths to the interpreter. Remember that with PHP,
reason for that is wrong paths to the interpreter. Remember that with PHP,
...
...
examples/lua/prime_numbers.lp
0 → 100644
View file @
5ce1fc3c
<?
-- Lua server pages have full control over the output, including HTTP
-- headers they send to the client. Send HTTP headers:
print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n')
?>
<html>
<p>
Prime numbers from 0 to 100, calculated by Lua:
</p>
<?
function is_prime(n)
if n <= 0 then return false end
if n <= 2 then return true end
if (n % 2 == 0) then return false end
for i = 3, n / 2, 2 do
if (n % i == 0) then return false end
end
return true
end
for i = 1, 100 do
if is_prime(i) then print('<span>' .. i .. '</span> ') end
end
?>
<p>
Reading POST data from Lua (click submit):
</p>
<form
method=
"POST"
><input
type=
"text"
name=
"t1"
/><input
type=
"submit"
></form>
<pre>
POST data: [
<? print(read())?>
]
request method: [
<? print(request_info.request_method) ?>
]
IP/port: [
<? print(request_info.remote_ip, ':', request_info.remote_port) ?>
]
URI: [
<? print(request_info.uri) ?>
]
HTTP version [
<? print(request_info.http_version) ?>
]
HEADERS:
<?
for name, value in pairs(request_info.http_headers) do
print(name, ':', value, '\n')
end
?>
</pre>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment