lua-users home
lua-l archive

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


On Tue, Oct 12, 2010 at 2:54 PM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> local res,err = dofile(modpath)
> if not res then print(err) end

If you replace that with:

local f = io.open(modpath,'r')
local body = f:read '*a'
if body:find '^#!' then
  local idx = body:find '\n'
  body = body:sub(idx)
end
f:close()
local res,err = loadstring(body)
if not res then print(err) end
res()

then things work as expected, but notice the ugly/inefficient hack
needed to strip the hash-bang line that chokes loadstring...

steve d.