lua-users home
lua-l archive

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

hi all.

In C, to get prev/next element of a array is easy: we just use pointer arithmetic to get the index of the element. and increase/decrease the index to get prev/next value in array.

but in Lua, the table is a mixing of array and hash-table. so we can not get the corresponding key for the value. so, how can I made a FAST function just like table.getkey() ?

local t = {'a', 'b', 'c', 'd', 'e'}
print(table.getkey(t, 'b')) --> 2

I did it by associate index with value, but I must maintain the table of index if I insert/remove something from the table. there are some good way to do this?