[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Alert! New version of Lua is being developed (Lua 5.2)

Alert! New version of Lua is being developed (Lua 5.2)

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Wed 10 Feb 2010 07:31 PM (UTC)
Message
I note that the Lua developers are working on version 5.2 and releasing work versions.

http://www.lua.org/work/doc/

Below is a copy of the tentative changes announced so far:



Changes since Lua 5.1

Everything may change in the final version.

Here are the main changes in Lua since its last release. The reference manual lists the incompatibilities that had to be introduced.

Language


  • new lexical environments.
  • no more fenv for threads.
  • ephemeron tables.
  • yieldable pcall/metamethods.
  • tables honor the __len metamethod.
  • max constants per function raised to 2^26.
  • hex escapes in strings.
  • no more verification of opcode consistency.


Libraries


  • new library for bitwise operations.
  • new metamethods __pairs and __ipairs.
  • arguments for function called through xpcall.
  • optional argument to load (to control binary x text).
  • loadlib may load libraries with global names (RTLD_GLOBAL).
  • new function package.searchpath.
  • optional base in math.log.
  • file:write returns file.
  • closing a pipe returns exit status.
  • os.exit may close state.
  • new option 'isrunning' for collectgarbage and lua_gc.
  • frontier patterns.
  • ipairs now goes until #t.


Implementation


  • emergency garbage collector (core forces a full collection when allocation fails).
  • ephemeron tables (tables with weak keys only visit value when key is accessible)
  • handling of non-string error messages in the standalone interpreter.
  • udata with finalizers are kept in a separated list for the GC.
  • CallInfo stack now is a linked list.
  • internal (immutable) version of ctypes.
  • parser uses much less C-stack space (no more auto arrays).
  • new hash for floats.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 10 Feb 2010 07:34 PM (UTC)
Message
Frontier patterns have been around for a while:

Template:post=6034 Please see the forum thread: http://gammon.com.au/forum/?id=6034.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Wed 10 Feb 2010 08:20 PM (UTC)
Message
It is interesting and amusing to note that one of the functions I was using heavily to load up imported "game" data was setfenv, and that has been removed from Lua 5.2

However the functionality has not.

For example, if I read it correctly, instead of:


local t = {} 
local f = assert (loadstring (arg))
setfenv (f, t) 
f ()  


you would use:


local t = {} 
local f = assert (loadin (t, arg))
f ()


... where "loadin" loads a string "arg" in the environment of "t".

Or, maybe this:


local t = {} 
in t do  
  local f = assert (loadstring (arg))
  f ()
end -- in


It was also interesting to note on the Lua mailing list someone saying:

Quote:

I too was sad to see those function go as I frequently use them to isolate data (formated as lua code) loading in my games.


So it seems it is not just me that is using Lua as a method of transporting data from client to server in a game.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Wed 10 Feb 2010 09:15 PM (UTC)

Amended on Wed 10 Feb 2010 09:18 PM (UTC) by Twisol

Message
Looking over the 5.2 reference manual, it looks like this will be a very useful release. I especially like the idea of lexical environments (in <x> do <y> end), and I expect the loss of setfenv/getfenv won't be such a loss after all.

Once it's finalized, will you be including Lua 5.2 with MUSHclient? I imagine it would break plenty of existing plugins/libraries, so perhaps a choice between 5.1 and 5.2 could be offered. The current 'language' XML attribute could keep 'Lua' as meaning 5.1, but also add explicit identifiers 'Lua5.1' and 'Lua5.2', so newer plugins can choose which one to use.

EDIT: Any idea how a construct like this might work? Specifically, is the table used for 'in' reused or replaced over every iteration? I would expect it to be replaced, but I can't really test it.

for _,v in ipairs(funcs) do
  in {} do
    v()
  end
end

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 10 Feb 2010 09:34 PM (UTC)
Message
It is easy enough to download and build it:

http://www.lua.org/work/

Quote:

in exp do block end

...

Expression exp is evaluated only once in the beginning of the statement and it is stored in a hidden local variable named (environment).



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Wed 10 Feb 2010 09:44 PM (UTC)
Message
Ahh, ok.

I did just build it, actually. I tested this code in the interpreter:

foo = function()
  print(test)
end

test = 1

do
  local foo = foo
  in {test = 2} do
    foo()
  end
end


It printed 1. It makes sense in retrospect, functions keep the environment they had when they were defined.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 10 Feb 2010 09:49 PM (UTC)

Amended on Wed 10 Feb 2010 09:50 PM (UTC) by Nick Gammon

Message
I did something similar:


function f1 ()
  print "f1"
end -- f1

function f2 ()
  print "f2"
end -- f2

funcs = { f1, f2 }

for _,v in ipairs(funcs) do
  in {} do
    v()
    print "hello"
  end
end


I was a bit surprised it printed "f1" before throwing the error that "print" was not defined.

I suppose this is what they mean by a "lexical environment". The environment applies within the "in" block, but anything previously defined retains its original environment.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 10 Feb 2010 09:53 PM (UTC)
Message
And what do you suppose this will do?


in {} do
  function f1 ()
    print "f1"
  end -- f1

  function f2 ()
    print "f2"
  end -- f2
end -- in

funcs = { f1, f2 }

for _,v in ipairs(funcs) do
  local print = print
  in {} do
    print "hello"
    v()
  end
end



  • Print: hello, f1, hello, f2?

  • Print: hello, then raise an error that print does not exist?

  • Print nothing at all?

  • Give a compile error?


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #8 on Wed 10 Feb 2010 09:58 PM (UTC)
Message
It does make a lot of sense. I suppose it's not a huge loss to do something like this instead:

function make_env()
  local _G = {}
  
  do
    local _G_meta = {
      print = print,
    }
    _G_meta.__index = _G_meta
    setmetatable(_G, _G_meta)
  end
  
  in _G do
    f1 = function()
      print("f1")
    end
    
    f2 = function()
      print("f2")
    end
  end
  
  return _G
end


It's no different from a typical closure, after all. Although I had to do some odd contortions to hide everything but the local _G from the 'in' scope.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Wed 10 Feb 2010 10:00 PM (UTC)

Amended on Wed 10 Feb 2010 10:34 PM (UTC) by Twisol

Message
At first glance, I would say that it would print "hello", then complain about 'print' not being defined. When I run it though... nothing happens visibly. How interesting.

EDIT: Actually, this snippet is effectively a no-op, since you don't store the table the functions are in.

in {} do
  function f1 ()
    print "f1"
  end -- f1

  function f2 ()
    print "f2"
  end -- f2
end -- in


EDIT 2: Ahh, now it makes sense. f1 and f2 are nil in the main scope, so funcs is basically an empty table, since you basically did {nil, nil}. So the for loop does absolutely nothing.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Wed 10 Feb 2010 10:27 PM (UTC)
Message
Twisol said:

Once it's finalized, will you be including Lua 5.2 with MUSHclient? I imagine it would break plenty of existing plugins/libraries, so perhaps a choice between 5.1 and 5.2 could be offered.


Well I am reluctant to offer a choice, because then plugin developers for x years won't be able to rely on any of the new features.

However obviously we can't go cold turkey on the new version because the setfenv in particular is a technique I have been using and recommending for loading Lua variables into plugins. (Actually, now I look at it, the default suggested method does *not* use setfenv).

I note in luaconf.h, as expected, they have a compatibility option:


/*
@@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'.
** You can replace them with lexical environments, 'loadin', or the
** debug library.
*/
#define LUA_COMPAT_FENV


I think that will have to be set initially, so that plugins will just work, but you can still write using the new features from the start.

Then we can allow a couple of months for plugin-writers to adapt their plugins, maybe something like this:


local t = {}
if loadin then
  assert (loadin (t, arg)) ()
else
  setfenv (assert (loadstring (arg)), t) ()
end -- if


A plugin with that in it would work on both Lua 5.1 and Lua 5.2.

And, while the compatability option was turned on, old plugins would work with Lua 5.2 as well.

Then later on, a version is released that turns off the compatibility option, and plugin writers can then adapt their plugins to require the new version only (by the MUSHclient version number).

There is probably nothing too compelling in Lua 5.2 to rush into turning off compatibility - although having hex constants in strings will be nice.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Wed 10 Feb 2010 10:28 PM (UTC)
Message
Twisol said:

EDIT 2: Ahh, now it makes since. f1 and f2 are nil in the main scope, so funcs is basically an empty table, since you basically did {nil, nil}. So the for loop does absolutely nothing.


Yes, I guessed wrongly, same as you. :P

But it makes sense when you look at it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Wed 10 Feb 2010 10:28 PM (UTC)
Message
Just to note, using loadstring() in an 'in' block doesn't quite work the way you'd expect. Since loadstring comes from the original environment, no matter where you call it, the loaded chunk will refer to the original environment.

I'm experimenting with loadin() now...

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Wed 10 Feb 2010 10:31 PM (UTC)
Message
Nick Gammon said:
I note in luaconf.h, as expected, they have a compatibility option:


/*
@@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'.
** You can replace them with lexical environments, 'loadin', or the
** debug library.
*/
#define LUA_COMPAT_FENV


I think that will have to be set initially, so that plugins will just work, but you can still write using the new features from the start.


Excellent, I didn't think of that.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #14 on Wed 10 Feb 2010 10:46 PM (UTC)
Message
How would you suggest loading a file into a given environment? There's no loadfilein() function, and in order to use loadin() you'd have to have access to file I/O methods, which are disabled in untrusted plugins/worlds.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


45,040 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]