lua server page couldn't use loadfile or dofile ,io.popen also is not avalible.

52 views
Skip to first unread message

冯力

unread,
Oct 29, 2013, 3:47:52 AM10/29/13
to mongoos...@googlegroups.com
 I want to use mongoose for my project.The example of lua like prime_numbers.lp or page.lp runs very well.
But when I  load file data or run some shell cmd,there is no anything output, except my "hhhh" here. What's wrong and how can I operate file using lua server page?
Thanks.

$ ./mongoose-lua -v
Loading config file ./mongoose.conf
Mongoose version 4.2 (c) Sergey Lyubka, built on Oct 29 2013

my test.lp is here:
----------------------------------------
function scandir(directory)
mg.write("hhhh")
local i, t, popen = 0, {}, io.popen
for filename in popen('ls "'..directory..'"'):lines() do
mg.write("bbbb")
i = i + 1
t[i] = filename
mg.write(filename)
end
return t
end
mg.write(scandir("."))
-------------------------------------
local count = 0
_G.entry = function(_) count = count + 1 end
local f, error = loadfile('entry.lua')
mg.write('error:' .. error .. '\n')
mg.write('path:' .. script_path() .. '\n')
-- getfenv(f).entry = entry
f()
mg.write("number of counts:" .. count)

entry.lua file is here:
-----------------------------
entry{
"author1",
"name1",
"1997"
}

Sergey Lyubka

unread,
Nov 23, 2013, 8:56:51 AM11/23/13
to mongoose-users
This "dirscan.lp" page works well for me on windows:


HTTP/1.0 200 OK
Content-Type: text/plain

<?
  -- Directory scanning example

  function scandir(dir)
    local t = {}
    for f in io.popen('dir ' .. dir):lines() do table.insert(t, f) end
    return t
  end

  local tab = scandir('C:\\')
  for k,v in pairs(tab) do mg.write(v, '\n') end
?>


--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages