[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Globals (more ruminations)
- From: HyperHacker <hyperhacker@...>
- Date: Wed, 21 Jul 2010 15:20:19 -0600
On Wed, Jul 21, 2010 at 15:08, Matthew Wild <mwild1@gmail.com> wrote:
> On 21 July 2010 21:45, HyperHacker <hyperhacker@gmail.com> wrote:
>>
>> I think a lot of the suggestions made so far are basically syntactic
>> sugar for this. If you're using a lot of functions from the global
>> namespace it'd be somewhat annoying to have to do "local print, io,
>> string, table = G.print, G.io, G.string, G.table" etc all the time.
>>
>> Perhaps a solution here is a "_module" table, which works similar to
>> _G, containing all modules that have been loaded to the global
>> namespace. i.e. at startup it would contain {string, os, io} etc as
>> well as perhaps some of the built-in globals like print, package, and
>> pcall (or perhaps these should be in modules of some sort as well).
>>
>
> $ lua
> Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
>> require "socket"
>> for k,v in pairs(package.loaded) do print(k,v) end
> string table: 0x9a5d618
> debug table: 0x9a60970
> package table: 0x9a5da50
> _G table: 0x9a5c450
> io table: 0x9a5eba0
> os table: 0x9a5f3a8
> table table: 0x9a5d100
> math table: 0x9a5ff70
> socket.core table: 0x9a73110
> coroutine table: 0x9a5d718
> socket table: 0x9a73110
>
> Not sure how this helps most cases discussed so far though :)
>
> Matthew
>
Well that eliminates the need for a long list of "local x, y, z = G.x,
G.y, G.z" in Stuart's example; instead of e.g. "local math = G.math"
you can access math through package.loaded, so maybe set it as a
fallback __index for G. Notably print isn't in there though...
--
Sent from my toaster.
- References:
- Re: Globals (more ruminations), Alexander Gladysh
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Juri Munkki
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Patrick Donnelly
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Edgar Toernig
- Re: Globals (more ruminations), David Manura
- Re: Globals (more ruminations), David Manura
- Re: Globals (more ruminations), Stuart P. Bentley
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Stuart P. Bentley
- Re: Globals (more ruminations), HyperHacker
- Re: Globals (more ruminations), Matthew Wild