lua-users home
lua-l archive

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


Am 15.04.2013 20:12 schröbte Hisham:
On 15 April 2013 06:48, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 11.04.2013 21:58 schröbte Petite Abeille:


On Apr 11, 2013, at 9:39 PM, Philipp Janda <siffiejoe@gmx.net> wrote:

which sets _ENV directly


Out of curiosity, what issue would that entail from your perspective?

It limits you to Lua 5.2.

Does it?

[...]

]/Programs/Lua/5.2.0/bin/lua -lPA_module main.lua
I'm Blo!
Uff

]/Programs/Lua/5.1.5/bin/lua main.lua
I'm Blo!
Uff

Ah, I should have thought of that, I use a similar trick for 5.1/5.2 compatibility for domain specific stuff:

function define( f )
  local env = make_env()
  if _VERSION == "Lua 5.1" then
    setfenv( f, env )
  end
  f( env )
end

define( function( _ENV )
  -- domain specific stuff ...
end )

Ok, I take everything back and claim the opposite: both module compatibility functions are equivalent feature-wise with the exception that one is deprecated or non-existent on Lua 5.2 but requires no changes to Lua 5.1 code, while the other works with both versions, but requires an extra dependency and small code modifications to existing 5.1 modules, and behaves slightly different for Lua 5.1/5.2 under rare circumstances.

The code for putting multiple modules into one file works for modules using either of the module-functions as well as for plain Lua modules.


-- Hisham
http://hisham.hm/


Philipp