lua-users home
lua-l archive

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


On 19/10/2009, at 4:46 PM, Morita, Bill wrote:

I have an issue I do not seem to find a reasonable solution to in Lua 5.1 I wish to dynamically generate text keys and then put them in a table to be retrieved by a generated text key.

The nature of Lua is such that, while text keys are supported, they can only be set in the source code. Because everything is an object in lua, two separate instances of x=”abc” will generated different objects and Thus a[x] = 1 cannot be retrieved by a later by a[x] where x was re- assigned (even to the same string).

There does not seem a function to “de-objectify” a value, nor does there seem to be a way to dynamically execute a generated statement.

Perhaps there is something I fail to understand.

Thanks

Hi Bill,

I'm not quite sure I understand what you mean, but if it helps, all of the following work:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a = "abc"
> x = {}
> x[a] = 13
> =x[a]
13
> =x.abc
13
> =x["abc"]
13
> b = "abc"
> =x[b]
13

Cheers,
Geoff