lua-users home
lua-l archive

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


On 9/27/2010 3:20 AM, Duncan Cross wrote:

To be honest, it seems only fair to me, since Lua's standard script
file loader already supports ignoring the first line if it begins with
a shebang. This sets a precedent that it is appropriate for the loader
to ignore common, OS-specific pecularities at the beginning of a
script file.

-Duncan


A regrettable precedent, perhaps? Although it's an OS feature that is well documented and used on multiple platforms. In any case, I think the "correct" response to this problem is...

From http://www.lua.org/manual/5.1/manual.html#pdf-load
>
> load(func [, chunkname])
> Loads a chunk using function func to get its pieces.

function utf8_dofile(filename)
  return assert(load(
    function()
      return string.gsub(
             assert(io.open(filename)):read('*a'),
             '^\239\187\191', '')
    end,
    filename
  ))()
end

Or something like that.

--
- tom
telliamed@whoopdedo.org