lua-users home
lua-l archive

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


Hi, I need to be able to use functions as keys in a table but also need to associate different indexed values for each function. I could go with keying first by function then via the index in sub-tables, but for my particular use it would be better to have all of the references in a single table. Would it be good then to key by a string with the index appended? Something analagous to this:

local function f() end
local index = 3
local value = "foo"
local t = {}
t[tostring(f) .. "_" .. index] = value


Using tostring() on a function gives strings like "function: 0x80652c0", so I could strip out the "function: 0x" part to save space, or for that matter turn the rest into a number and tack my index on the end.

I just want to be reasonably sure that a function's tostring() is usable in such a manner without any hidden gotcha's, since I haven't seen anything like this mentioned on lua-l before. Other suggestions are welcome. Thanks,

-Lucas