lua-users home
lua-l archive

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

Daniel Silverstone schrieb:
> So this would be blah = loadin(pathtoscript, envtab) rather than blah =
> loadfile(pathtoscript) setfenv(blah, envtab) ?  That seems emminently
> reasonable and pleasant to use.

It would be
  file = assert ( (path))
  source = file:read ("*all")
  file:close ()
  func = loadin (env, source, "@"..path)

But in order to address the "reuse"-issue again, with loadin() it would
only be easy to reuse the source and compile the function each time again. a hack I might use string.dump (func), buffer that and reload
it later using loadin () probably would create more overhead than
just using setfenv () on the function but it would still be more
efficient than compiling the source again.

- David