Я пытаюсь запустить следующий код:
#!/usr/bin/env wsapi.cgi
require("lib/request") -- wsapi lib
require("lib/response")
require("io")
module("loadHtml", package.seeall)
---This function generates a response for the WSAPI calls that need to GET a file
function run(wsapi_env)
--check the request
local req = wsapi.request.new(wsapi_env or {})
--generate response
res = wsapi.response.new()
---a couple of utility functions that will be used to write something to response
function print(str) res:write(str) end
function println(str) res:write(str) res:write('<br/>') end
println("running...")
ff=dofile("index.html.lua")
println("done!")
return res:finish()
end
return _M
И "index.html.lua" выглядит примерно так:
print([[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
Hello world!
</html>]])
он работает без ошибок, но все, что я получаю на стороне клиента, это точно так:
running...<br/>done!<br/>
Другими словами, println () в функции run () работает, но не работает внутри "index.html.lua". Я попытался loadfile () вместо dofile (), и это то же самое. Самое смешное, что я написал тестовый код, и он работает:
--tryDoFileRun.lua:
function e()
function p(str)
print(str)
end
dofile("tryDoFile.lua")
end
e()
, который запускает это:
--tryDoFile.lua
print("in tryDoFile.lua")
p("calling p")
и вывод:
in tryDoFile.lua
calling p
Так и должно быть. однако эта же идея не работает в первом коде выше.
Как я могу получить этот код, чтобы index.html.lua использовал мою функцию print ()?
Спецификация системы: WSAPI, сервер Lighttpd, LUA 5.1, ARM9, Linux 2.6