[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: run a lua page (cgilua) in command line
- From: Tomas <tomas@...>
- Date: Wed, 23 Nov 2005 08:55:24 -0200 (BRST)
Jorge,
I thought you were trying to run the Lua Pages preprocessor,
which is not distributed separately but is really easy to use without
CGILua. If you (or someone) want to do that just ask me.
What I really want to do is to use cgilua in an embedded http server in C++
that I wrote for a multiplayer game server. I have no problem using lua in my
C++ programs. My next step is add cgilua in my embedded http server but I
have no idea where start. Most of the page I visited show how to use cgilua
in webservers like apache.
You just have to write a launcher for your web server
(except for the environment variables, the cgi launcher would
work for a command line test).
A launcher is a simple file which defines the SAPI and
runs cgilua. For example:
define_sapi ()
require"cgilua"
cgilua.main ()
(Next version we'll change `define_sapi' to `require"sapi.launcher"'
or something like that, which makes more sense)
The function define_sapi have to define the SAPI table:
-- untested code. partially extracted from CGILua's t_cgi.lua
SAPI = {
Request = {
getpostdata = function (n) return io.stdin:read(n) end,
servervariable = function (n) return os.getenv(n) end,
},
Response = {
contenttype = function (s) io.stdout:write ("Content-type: "..s.."\n\n") end,
redirect = function (s) io.stdout:write ("Location: "..s.."\n\n")
header = function (h, v) io.stdout:write (string.format ("%s: %s\n", h, v) end,
write = function (s) io.stdout:write (s) end,
errorlog = function (s) io.stderr:write (s) end,
},
}
Hope this helps,
Tomas