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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Changes to the Lua initialization in MUSHclient v4.60

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Changes to the Lua initialization in MUSHclient v4.60

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sun 05 Sep 2010 02:44 AM (UTC)  quote  ]

Amended on Sun 05 Sep 2010 02:45 AM (UTC) by Nick Gammon

Message
As part of code cleanups for version 4.60 of MUSHclient, I noticed that the implementation of the main script spaces metatables was wrong (it is confusing reading the C code to set it up).

To demonstrate, in any version below 4.60 you can try this:


print (_G)        --> table: 00D0B6B8
print (world)     --> table: 00CE6A38
print (rawget (_G, "__index"))  --> nil
print (rawget (world, "__index")) --> table: 00CE6A38
print (getmetatable (_G))         --> table: 00CE6A38
print (getmetatable (world))      --> nil
world.__index = nil
Note "hello"  --> Error: attempt to call global 'Note' (a nil value)


You can see that the above is wrong in a number of ways. It is as if this was coded in Lua:


setmetatable (_G, world)
world.__index = world


It should in fact look more like this:


setmetatable (_G, { __index = world } )


Also, setting world.__index to nil should not stop access to the world functions from the global environment.

In version 4.60 the results are like this:


print (_G)      --> table: 020547A0
print (world)   --> table: 0205ED30
print (rawget (_G, "__index"))    --> nil
print (rawget (world, "__index")) --> nil
print (getmetatable (_G))     --> table: 0205EC90
print (getmetatable (world))  --> nil
world.__index = nil 
Note "hello"   --> hello


Now there is no "__index" field in the world table, and the global environment has a metatable which is different from the world table. This metatable simply indexes back to the world table. If you set world.__index it has no effect (it was nil anyway).

Now these changes *shouldn't* affect existing scripts, but I mention them in case anyone has done some obscure mucking around with metatables and are relying on the current behaviour.

- Nick Gammon

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

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #1 on Sun 05 Sep 2010 03:02 AM (UTC)  quote  ]
Message
Fun side effect of the pre-4.60 behavior: you can access the world table as __index, too.

__index.Note("lolwat")

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 05 Sep 2010 03:16 AM (UTC)  quote  ]
Message
Yeah, exactly why it was wrong. ;)

Well spotted.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


784 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]