[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: variable names from variables?
- From: Vaughan McAlley <vaughan@...>
- Date: Thu, 3 Feb 2011 00:53:30 +1100
On 3 February 2011 00:48, Robert Raschke <rtrlists@googlemail.com> wrote:
>
> On Wed, Feb 2, 2011 at 1:36 PM, Patrick Mc(avery
> <spell_gooder_now@spellingbeewinnars.org> wrote:
>>
>> This code:
>>
>> for i = 10, 1 do
>> local value .. i = {}
>> end
>>
>>
>> does not work, I am assuming it's because variables do not have types only
>> values do?
>>
>> Is there someway to automatically generate variable names?
>>
>
> It's not entirely clear what you want to do. You can create new global
> variables via _G. But why would you want to create local ones that way, why
> not simply use a table? I'd be interested to hear the use case.
>
> Also, I think you meant to write "for i = 10, 1, -1 do".
>
> Robby
>
>
Yes, the VM doesn’t use names for local variables, just register
numbers. Globals are a different matter:
for i = 1, 10 do
G["value" .. i] = {} -- G["value1"] is the same as the global value1
end
print(value6)
=> table: 0x62e820
Vaughan