lua-users home
lua-l archive

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


It was thus said that the Great Morita, Bill once stated:
> 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.

  I'm not sure what you are asking.  

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a = {}
> x = "abc"
> a[x] = "the one and only X"
> =a[x]
the one and only X
> x = nil
> x = string.lower("ABC")
> =a[x]
the one and only X
> 

  Seems to work to me.

  -spc