lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> At this point, I have wsapi running, happily running hello.lua, but
> I'm having the following issue after I copied hello.lua into
> sqlite.lua to try to work with an SQLite database: The data is output
> on the console, but not on the browser (save for the stuff from
> hello.lua):
> 
> ...
> 		cursor = assert(conn:execute("select * from tbl1"))
> 		row = {}
> 		while cursor:fetch(row) do
> 			print(table.concat(row, '|') .. '<br>')
> 		end

The problem is that the print() function does not output the agruments
to browser, but like usual - to the standard output (console). You need
to use the same function as in the example - coroutine.yield(), like in:

> 		
>     coroutine.yield("<html><body>")
>     coroutine.yield("<p>Hello Wsapi!</p>")
>     coroutine.yield("<p>PATH_INFO: " .. wsapi_env.PATH_INFO .. "</p>")
>     coroutine.yield("<p>SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME ..
> "</p>")
>     coroutine.yield("</body></html>")

Although outputing can be done with coroutine.yield(), IMO it is much
better to use a framework built on top of WSAPI, like the Orbit
framework ( http://keplerproject.github.com/orbit/ ), which simplifies a
lot of stuff. It even enables you to write pages in 'PHP' style (Orbit
pages - http://keplerproject.github.com/orbit/pages.html ).